JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
parse_template deleted "<!--" and "0" sections
authorJason Woofenden <jason@jasonwoof.com>
Sun, 8 Nov 2009 19:29:37 +0000 (14:29 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Sun, 8 Nov 2009 19:40:23 +0000 (14:40 -0500)
parse_template used to delete "<!--" or "0" when they occured in a place where
they were the entirity of a static string piece. Examples:

~a~0~b~

Template to output a template:

~a~<!--~~b~~-->~c~

template.php

index 85132c3..45857af 100644 (file)
@@ -64,8 +64,7 @@ function parse_template_file($filename) {
 function parse_template($string) {
        $tem =& tem_push();
        $tem['pieces'] = array();
-       # note: for some reason this captures '<!--' but not '-->'.
-       $matches = preg_split("/(<!--)?(~[^~]*~)(?(1)-->)/", $string, -1, PREG_SPLIT_DELIM_CAPTURE);
+       $matches = preg_split('/(<!--)?(~[^~]*~)(?(1)-->)/', preg_replace('/<!--(~[^~]*~)-->/', '$1', $string), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
        foreach($matches as $match) {
                if($match == '~~') $match = '~';
                if(substr($match,0,1) == '~' and strlen($match) > 2) {
@@ -91,7 +90,7 @@ function parse_template($string) {
                        } else {  # value slot
                                $tem['pieces'][] = array('name' => $name, 'args' => $args);
                        }
-               } elseif($match and $match != '<!--') {  # static string
+               } else {  # static string
                        $tem['pieces'][] = $match;
                }
        }