From 64b5cd0964d04c881a6680814ac5cdda6c148b3c Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Wed, 8 Dec 2010 08:34:27 -0500 Subject: [PATCH] Cleanup. Make RegEx variable capitalization consistent. Add docblocks for prepareFooRegEx functions. --- Mustache.php | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/Mustache.php b/Mustache.php index d4bff90..3b43a4f 100644 --- a/Mustache.php +++ b/Mustache.php @@ -264,6 +264,14 @@ class Mustache { return $template; } + /** + * Prepare a section RegEx string for the given opening/closing tags. + * + * @access protected + * @param string $otag + * @param string $ctag + * @return string + */ protected function _prepareSectionRegEx($otag, $ctag) { return sprintf( '/(?:(?<=\\n)[ \\t]*)?%s(?[%s])(?.+?)%s\\n?/s', @@ -283,7 +291,7 @@ class Mustache { * @return array $section, $offset, $type, $tag_name and $content */ protected function _findSection($template) { - $regex = $this->_prepareSectionRegEx($this->_otag, $this->_ctag); + $regEx = $this->_prepareSectionRegEx($this->_otag, $this->_ctag); $section_start = null; $section_type = null; @@ -293,7 +301,7 @@ class Mustache { $section_stack = array(); $matches = array(); - while (preg_match($regex, $template, $matches, PREG_OFFSET_CAPTURE, $search_offset)) { + while (preg_match($regEx, $template, $matches, PREG_OFFSET_CAPTURE, $search_offset)) { $match = $matches[0][0]; $offset = $matches[0][1]; @@ -336,6 +344,14 @@ class Mustache { } } + /** + * Prepare a pragma RegEx for the given opening/closing tags. + * + * @access protected + * @param string $otag + * @param string $ctag + * @return string + */ protected function _preparePragmaRegEx($otag, $ctag) { return sprintf( '/%s%%\\s*(?[\\w_-]+)(?(?: [\\w]+=[\\w]+)*)\\s*%s\\n?/s', @@ -359,8 +375,8 @@ class Mustache { return $template; } - $regex = $this->_preparePragmaRegEx($this->_otag, $this->_ctag); - return preg_replace_callback($regex, array($this, '_renderPragma'), $template); + $regEx = $this->_preparePragmaRegEx($this->_otag, $this->_ctag); + return preg_replace_callback($regEx, array($this, '_renderPragma'), $template); } /** @@ -441,7 +457,15 @@ class Mustache { return (isset($this->_throwsExceptions[$exception]) && $this->_throwsExceptions[$exception]); } - protected function _prepareTagRegex($otag, $ctag) { + /** + * Prepare a tag RegEx for the given opening/closing tags. + * + * @access protected + * @param string $otag + * @param string $ctag + * @return string + */ + protected function _prepareTagRegEx($otag, $ctag) { return sprintf( '/(?(?<=\\n)[ \\t]*)?%s(?[%s]?)(?.+?)(?:\\2|})?%s(?:\\s*(?=\\n))?/s', preg_quote($otag, '/'), @@ -629,7 +653,6 @@ class Mustache { $this->_context = $new; } - /** * Remove the latest context from the stack. *