diff options
author | LarsDW223 <lars_paulsen@web.de> | 2014-10-14 16:12:08 +0200 |
---|---|---|
committer | LarsDW223 <lars_paulsen@web.de> | 2014-10-14 16:12:08 +0200 |
commit | 70daee86e69783928d3da887a3a3e26b8ab74734 (patch) | |
tree | 6b3d3ad404b530a246d38c2b2cef77bceddf1b59 /lib/exe | |
parent | b2e6a1f4afcd548dbd5bc6af110940b08b9f1a88 (diff) | |
download | rpg-70daee86e69783928d3da887a3a3e26b8ab74734.tar.gz rpg-70daee86e69783928d3da887a3a3e26b8ab74734.tar.bz2 |
Corrected compression for ++ and -- operator. Partially fixes #897.
Diffstat (limited to 'lib/exe')
-rw-r--r-- | lib/exe/js.php | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/lib/exe/js.php b/lib/exe/js.php index bec12ef7a..2ab78dfc3 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -289,6 +289,10 @@ function js_compress($s){ // items that don't need spaces next to them $chars = "^&|!+\-*\/%=\?:;,{}()<>% \t\n\r'\"[]"; + // items which need a space if the sign before and after whitespace is equal. + // E.g. '+ ++' may not be compressed to '+++' --> syntax error. + $ops = "+-"; + $regex_starters = array("(", "=", "[", "," , ":", "!"); $whitespaces_chars = array(" ", "\t", "\n", "\r", "\0", "\x0B"); @@ -389,19 +393,27 @@ function js_compress($s){ // whitespaces if( $ch == ' ' || $ch == "\r" || $ch == "\n" || $ch == "\t" ){ - // leading spaces - if($i+1 < $slen && (strpos($chars,$s[$i+1]) !== false)){ - $i = $i + 1; - continue; - } - // trailing spaces - // if this ch is space AND the last char processed - // is special, then skip the space $lch = substr($result,-1); - if($lch && (strpos($chars,$lch) !== false)){ - $i = $i + 1; - continue; + + // Only consider deleting whitespace if the signs before and after + // are not equal and are not an operator which may not follow itself. + if ((!$lch || $s[$i+1] == ' ') + || $lch != $s[$i+1] + || strpos($ops,$s[$i+1]) === false) { + // leading spaces + if($i+1 < $slen && (strpos($chars,$s[$i+1]) !== false)){ + $i = $i + 1; + continue; + } + // trailing spaces + // if this ch is space AND the last char processed + // is special, then skip the space + if($lch && (strpos($chars,$lch) !== false)){ + $i = $i + 1; + continue; + } } + // else after all of this convert the "whitespace" to // a single space. It will get appended below $ch = ' '; |