From 2dbb4203c9be0b6f666757485625a8e9c4f26371 Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Sun, 13 Nov 2011 14:14:43 +0100 Subject: [PATCH] moved hard-coded regexes --- lib/Twig/Lexer.php | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index 196d099..004f562 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -40,7 +40,7 @@ class Twig_Lexer implements Twig_LexerInterface const REGEX_NAME = '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A'; const REGEX_NUMBER = '/[0-9]+(?:\.[0-9]+)?/A'; const REGEX_STRING = '/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As'; - const REGEX_DQ_STRING_START = '/"/A'; + const REGEX_DQ_STRING_DELIM = '/"/A'; const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As'; const PUNCTUATION = '()[]{}?:.,|'; @@ -266,7 +266,7 @@ class Twig_Lexer implements Twig_LexerInterface $this->moveCursor($match[0]); } // opening double quoted string - elseif (preg_match(self::REGEX_DQ_STRING_START, $this->code, $match, null, $this->cursor)) { + elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) { $this->brackets[] = array('"', $this->lineno); $this->pushState(self::STATE_STRING); $this->moveCursor($match[0]); @@ -308,7 +308,7 @@ class Twig_Lexer implements Twig_LexerInterface $this->pushToken(Twig_Token::STRING_TYPE, stripcslashes($match[0])); $this->moveCursor($match[0]); - } else if (preg_match('/"/A', $this->code, $match, null, $this->cursor)) { + } else if (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) { list($expect, $lineno) = array_pop($this->brackets); if ($this->code[$this->cursor] != '"') { @@ -324,7 +324,7 @@ class Twig_Lexer implements Twig_LexerInterface protected function lexInterpolation() { $bracket = end($this->brackets); - if ($this->options['interpolation'][0] === $bracket[0] && preg_match('/\s*}/A', $this->code, $match, null, $this->cursor)) { + if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->options['interpolation_end_regex'], $this->code, $match, null, $this->cursor)) { array_pop($this->brackets); $this->pushToken(Twig_Token::INTERPOLATION_END_TYPE); $this->moveCursor($match[0]); -- 1.7.2.5