Changeset 5701


Ignore:
Timestamp:
07/16/2010 02:10:05 PM (5 years ago)
Author:
wwalc
Message:

#5188 - added fixing BOM characters (reintroduced changes reverted with [5548])

Location:
CKEditor/trunk/_dev/fixlineends
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • CKEditor/trunk/_dev/fixlineends/fixlineends.bat

    r5548 r5701  
    55::
    66
    7 php fixlineends.php --excluderegex=/(?:_dev[\\\/]_thirdparty)/ --eolstripwhite --eofnewline --eofstripwhite --nohidden --nosystem ../../
     7php fixlineends.php --excluderegex=/(?:_dev[\\\/]_thirdparty)/ --eolstripwhite --eofnewline --eofstripwhite --nohidden --nosystem --fixbom ../../
  • CKEditor/trunk/_dev/fixlineends/fixlineends.php

    r5548 r5701  
    6464$list["xml"] = CRLF;
    6565
     66$bom = array();
     67$bom['asp'] = true;
     68$bom['js'] = true;
     69
    6670/**
    6771 * Do not modify anything below
     
    107111 */
    108112$nodotfiles = false;
     113/**
     114 * If set to true, BOM characters are fixed
     115 * @var boolean $fixbom
     116 */
     117$fixbom = false;
    109118/**
    110119 * How deep to recurse into subdirectories
     
    317326        }
    318327        $new_content .= $line;
     328    }
     329
     330    if ($GLOBALS['fixbom']) {
     331        $before_fixing = $new_content;
     332        $ext = strtolower(substr($path, strrpos($path, ".") + 1));
     333        $new_content = stripUtf8Bom( $new_content );
     334        if (!empty($GLOBALS['bom'][$ext])) {
     335            $new_content = "\xEF\xBB\xBF" . $new_content; // BOM
     336        }
     337        if ($new_content != $before_fixing)
     338            $modified = true;
    319339    }
    320340
     
    353373
    354374/**
     375 * Strip BOM from a string
     376 * @param string $data
     377 */
     378function stripUtf8Bom( $data )
     379{
     380    if ( substr( $data, 0, 3 ) == "\xEF\xBB\xBF" )
     381        return stripUtf8Bom(substr_replace( $data, '', 0, 3 )) ;
     382
     383    return $data ;
     384}
     385
     386/**
    355387 * Fix ending lines in all files at given path
    356388 *
     
    453485            use regex to exclude files, preg_match() format expected
    454486
     487       --fixbom
     488            fix BOM characters
     489
    455490       --help
    456491            display this help and exit
    457492
    458493       --noarchive
    459             if set to true, archive files are skipped (Windows only)
     494            skip archive files (Windows only)
    460495
    461496       --nodotfiles
    462             if set to true, dot files are skipped
     497            skip dot files
    463498
    464499       --nohidden
    465             if set to true, hidden files are skipped (Windows only)
     500            skip hidden files (Windows only)
    466501
    467502       --nosystem
    468             if set to true, system files are skipped (Windows only)
     503            skip system files (Windows only)
    469504
    470505       --maxdepth
     
    525560            case '--nodotfiles':
    526561                $GLOBALS['nodotfiles'] = true;
     562                break;
     563
     564            case '--fixbom':
     565                $GLOBALS['fixbom'] = true;
    527566                break;
    528567
     
    572611
    573612if ($_SERVER['argc']>1) {
    574         include "../_thirdparty/console_getopt/Getopt.php";
     613    include "../_thirdparty/console_getopt/Getopt.php";
    575614
    576615    if ($windows) {
    577         $longoptions = array("eofstripwhite", "eofnewline", "eolstripwhite", "help", "noarchive", "nohidden", "nosystem", "nodotfiles", "maxdepth=", "excluderegex=");
     616        $longoptions = array("eofstripwhite", "eofnewline", "eolstripwhite", "help", "noarchive", "nohidden", "nosystem", "nodotfiles", "maxdepth=", "excluderegex=", "fixbom");
    578617    }
    579618    else {
    580         $longoptions = array("eofstripwhite", "eofnewline", "eolstripwhite", "help", "nodotfiles", "maxdepth=", "excluderegex=");
     619        $longoptions = array("eofstripwhite", "eofnewline", "eolstripwhite", "help", "nodotfiles", "maxdepth=", "excluderegex=", "fixbom");
    581620    }
    582621
Note: See TracChangeset for help on using the changeset viewer.
© 2003 – 2012 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy