From: Tim Starling Date: Fri, 18 Feb 2011 06:54:46 +0000 (+0000) Subject: Made the regexes slightly more readable by undoubling the backslashes where possible... X-Git-Tag: 1.31.0-rc.0~31934 X-Git-Url: http://git.cyclocoop.org/data/Fool?a=commitdiff_plain;h=27981283a7771b01abddf1de582676c85e100b6b;p=lhc%2Fweb%2Fwiklou.git Made the regexes slightly more readable by undoubling the backslashes where possible. Tested by ensuring that the minifier output is the same before and after, with jquery.js as input. --- diff --git a/includes/libs/JavaScriptDistiller.php b/includes/libs/JavaScriptDistiller.php index 15650cdb07..b377ac59d5 100644 --- a/includes/libs/JavaScriptDistiller.php +++ b/includes/libs/JavaScriptDistiller.php @@ -28,33 +28,33 @@ class JavaScriptDistiller { return $script; } - private static function stripHorizontalSpace( $script ) { + public static function stripHorizontalSpace( $script ) { $parser = self::createParser(); // Collapse horizontal whitespaces between variable names into a single space - $parser->add( '/(\\b|\\$)[ \\t]+(\\b|\\$)/', '$2 $3' ); + $parser->add( '/(\b|\$)[ \t]+(\b|\$)/', '$2 $3' ); // Collapse horizontal whitespaces between unary operators into a single space - $parser->add( '/([+\\-])[ \\t]+([+\\-])/', '$2 $3' ); + $parser->add( '/([+\-])[ \t]+([+\-])/', '$2 $3' ); // Remove all remaining un-protected horizontal whitespace - $parser->add( '/[ \\t]+/'); + $parser->add( '/[ \t]+/'); // Collapse multiple vertical whitespaces with some horizontal spaces between them - $parser->add( '/[\\r\\n]+[ \\t]*[\\r\\n]+/', "\n" ); + $parser->add( '/[\r\n]+[ \t]*[\r\n]+/', "\n" ); // Execute and return return $parser->exec($script); } - private static function stripVerticalSpace( $script ) { + public static function stripVerticalSpace( $script ) { $parser = self::createParser(); // Collapse whitespaces between and after a ){ pair (function definitions) - $parser->add( '/\\)\\s+\\{\\s+/', '){' ); + $parser->add( '/\)\s+\{\s+/', '){' ); // Collapse whitespaces between and after a ({ pair (JSON argument) - $parser->add( '/\\(\\s+\\{\\s+/', '({' ); + $parser->add( '/\(\s+\{\s+/', '({' ); // Collapse whitespaces between a parenthesis and a period (call chaining) - $parser->add( '/\\)\\s+\\./', ').'); + $parser->add( '/\)\s+\./', ').'); // Collapse vertical whitespaces which come directly after a semicolon or a comma - $parser->add( '/([;,])\\s+/', '$2' ); + $parser->add( '/([;,])\s+/', '$2' ); // Collapse whitespaces between multiple parenthesis/brackets of similar direction - $parser->add( '/([\\)\\}])\\s+([\\)\\}])/', '$2$3' ); - $parser->add( '/([\\(\\{])\\s+([\\(\\{])/', '$2$3' ); + $parser->add( '/([\)\}])\s+([\)\}])/', '$2$3' ); + $parser->add( '/([\(\{])\\s+([\(\{])/', '$2$3' ); return $parser->exec( $script ); } @@ -80,12 +80,12 @@ class JavaScriptDistiller { $parser->add( '/\'([^\'\\\\]*(\\\\(.|[\r\n])[^\'\\\\]*)*)\'/', '$1' ); $parser->add( '/"([^"\\\\]*(\\\\(.|[\r\n])[^"\\\\]*)*)"/', '$1' ); // Protect regular expressions - $parser->add( '/[ \\t]+((\\/[^\\r\\n\\*][^\\/\\r\\n\\\\]*(\\\\.[^\\/\\r\\n\\\\]*)*\\/(i|g)*))/', '$1' ); - $parser->add( '/([^\\w\\$\\/\'"*)\\?:](\\/[^\\r\\n\\*][^\\/\\r\\n\\\\]*(\\\\.[^\\/\\r\\n\\\\]*)*\\/(i|g)*))/', '$1' ); + $parser->add( '/[ \t]+((\/[^\r\n\*][^\/\r\n\\\\]*(\\\\.[^\/\r\n\\\\]*)*\/(i|g)*))/', '$1' ); + $parser->add( '/([^\w\$\/\'"*)\?:](\/[^\r\n\*][^\/\r\n\\\\]*(\\\\.[^\/\r\n\\\\]*)*\/(i|g)*))/', '$1' ); // Remove comments - $parser->add( '/\\/\\*(.|[\\r\\n])*?\\*\\//' ); + $parser->add( '/\/\*(.|[\r\n])*?\*\//' ); // Preserve the newline after a C++-style comment -- bug 27046 - $parser->add( '/\\/\\/[^\\r\\n]*([\\r\\n])/', '$2' ); + $parser->add( '/\/\/[^\r\n]*([\r\n])/', '$2' ); return $parser; } } @@ -112,13 +112,13 @@ class ParseMaster { const LENGTH = 2; // used to determine nesting levels - private $GROUPS = '/\\(/';//g - private $SUB_REPLACE = '/\\$\\d/'; - private $INDEXED = '/^\\$\\d+$/'; - private $TRIM = '/([\'"])\\1\\.(.*)\\.\\1\\1$/'; + private $GROUPS = '/\(/';//g + private $SUB_REPLACE = '/\$\d/'; + private $INDEXED = '/^\$\d+$/'; + private $TRIM = '/([\'"])\1\.(.*)\.\1\1$/'; private $ESCAPE = '/\\\./';//g private $QUOTE = '/\'/'; - private $DELETED = '/\\x01[^\\x01]*\\x01/';//g + private $DELETED = '/\x01[^\x01]*\x01/';//g public function add($expression, $replacement = '') { // count the number of sub-expressions