Permalink
Browse files

Better consecutive echo handling

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1020 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent e2e5123 commit dbf95669b5f8b2b5577cf947728400e6ee238cee jakubvrana committed Aug 26, 2009
Showing with 10 additions and 10 deletions.
  1. +10 −10 compile.php
View
@@ -103,20 +103,19 @@ function php_shrink($input) {
if (!is_array($token)) {
$token = array(0, $token);
}
+ if ($tokens[$i+2][0] === T_CLOSE_TAG && $tokens[$i+3][0] === T_INLINE_HTML && $tokens[$i+4][0] === T_OPEN_TAG
+ && strlen(addcslashes($tokens[$i+3][1], "'\\")) < strlen($tokens[$i+3][1]) + 3
+ ) {
+ $tokens[$i+2] = array(T_ECHO, 'echo');
+ $tokens[$i+3] = array(T_CONSTANT_ENCAPSED_STRING, "'" . addcslashes($tokens[$i+3][1], "'\\") . "'");
+ $tokens[$i+4] = array(0, ';');
+ }
if ($token[0] == T_COMMENT || $token[0] == T_WHITESPACE || ($token[0] == T_DOC_COMMENT && $doc_comment)) {
$space = "\n";
} else {
if ($token[0] == T_DOC_COMMENT) {
$doc_comment = true;
}
- if ($token[0] == T_CLOSE_TAG && $tokens[$i+1][0] == T_INLINE_HTML && $tokens[$i+2][0] == T_OPEN_TAG
- && strlen(addcslashes($tokens[$i+1][1], "'\\")) < strlen($tokens[$i+1][1]) + 4
- ) {
- $tokens[$i] = array(T_ECHO, 'echo');
- $tokens[$i+1] = array(T_CONSTANT_ENCAPSED_STRING, "'" . addcslashes($tokens[$i+1][1], "'\\") . "'");
- $tokens[$i+2] = array(0, ';');
- $token = $tokens[$i];
- }
if ($token[0] == T_VAR) {
$shortening = false;
} elseif (!$shortening) {
@@ -126,15 +125,16 @@ function php_shrink($input) {
} elseif ($token[0] == T_ECHO) {
$in_echo = true;
} elseif ($token[1] == ';' && $in_echo) {
- $in_echo = false;
- if ($tokens[$i+1][0] === T_WHITESPACE && $tokens[$i+2][0] === T_ECHO) {
+ if (in_array($tokens[$i+1][0], array(T_WHITESPACE, T_COMMENT)) && $tokens[$i+2][0] === T_ECHO) {
next($tokens);
$i++;
}
if ($tokens[$i+1][0] === T_ECHO) {
// join two consecutive echos
next($tokens);
$token[1] = '.'; //! join ''.'' and "".""
+ } else {
+ $in_echo = false;
}
} elseif ($token[0] === T_VARIABLE && !isset($special_variables[$token[1]])) {
$token[1] = '$' . $short_variables[$token[1]];

0 comments on commit dbf9566

Please sign in to comment.