Permalink
Browse files

support benchmark files that contain closing tags

  • Loading branch information...
1 parent 447a195 commit 82ddfc21b468b8c4c6144da65b929113f1f94d7c David Sklar committed May 4, 2010
Showing with 18 additions and 1 deletion.
  1. +4 −0 b/closing-tag.php
  2. +14 −1 ub.php
View
@@ -0,0 +1,4 @@
+<?php
+// time
+$a = 2 + 2;
+?>
View
15 ub.php
@@ -98,7 +98,20 @@ function ub_parse_code($code) {
}
$states_rx = join("|", array_keys($blocks));
- foreach (token_get_all($code) as $tok) {
+ $tokens = token_get_all($code);
+
+ /* Trim off whitespace-after-closing-tag if that's at the end of the token list */
+ $last_token = end($tokens);
+ if (($last_token[0] == T_INLINE_HTML) && preg_match('/^\s+$/u', $last_token[1])) {
+ array_pop($tokens);
+ }
+ /* Trim off a closing tag if that's at the end of the token list */
+ $last_token = end($tokens);
+ if ($last_token[0] == T_CLOSE_TAG) {
+ array_pop($tokens);
+ }
+
+ foreach ($tokens as $tok) {
/* Standardize token representation as an array */
if (! is_array($tok)) { $tok = array(T_STRING, $tok); }

0 comments on commit 82ddfc2

Please sign in to comment.