Pre-escape tag type constants (saves us from doing it each time the regex strings are prepared)

This commit is contained in:
Justin Hileman
2010-11-26 14:07:10 -05:00
parent 2b8e2f6e84
commit fe91be1fb1
+4 -4
View File
@@ -258,13 +258,13 @@ class Mustache {
return $template; return $template;
} }
const SECTION_TYPES = '^#/'; const SECTION_TYPES = '\^#\/';
protected function _prepareSectionRegEx($otag, $ctag) { protected function _prepareSectionRegEx($otag, $ctag) {
return sprintf( return sprintf(
'/(?:(?<=\\n)[ \\t]*)?%s(?<type>[%s])(?<tag_name>.+?)%s\\n?/s', '/(?:(?<=\\n)[ \\t]*)?%s(?<type>[%s])(?<tag_name>.+?)%s\\n?/s',
preg_quote($otag, '/'), preg_quote($otag, '/'),
preg_quote(self::SECTION_TYPES, '/'), self::SECTION_TYPES,
preg_quote($ctag, '/') preg_quote($ctag, '/')
); );
} }
@@ -437,13 +437,13 @@ class Mustache {
return (isset($this->_throwsExceptions[$exception]) && $this->_throwsExceptions[$exception]); return (isset($this->_throwsExceptions[$exception]) && $this->_throwsExceptions[$exception]);
} }
const TAG_TYPES = '#^/=!<>\\{&'; const TAG_TYPES = '#\^\/=!<>\\{&';
protected function _prepareTagRegex($otag, $ctag) { protected function _prepareTagRegex($otag, $ctag) {
return sprintf( return sprintf(
'/(?<whitespace>(?<=\\n)[ \\t]*)?%s(?<type>[%s]?)(?<tag_name>.+?)(?:\\2|})?%s(?:\\s*(?=\\n))?/s', '/(?<whitespace>(?<=\\n)[ \\t]*)?%s(?<type>[%s]?)(?<tag_name>.+?)(?:\\2|})?%s(?:\\s*(?=\\n))?/s',
preg_quote($otag, '/'), preg_quote($otag, '/'),
preg_quote(self::TAG_TYPES, '/'), self::TAG_TYPES,
preg_quote($ctag, '/') preg_quote($ctag, '/')
); );
} }