X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=template.php;h=3845c7c9bf9ec61b1b28829bfc30f4053f2d7035;hb=e99321a886b30fc6d601c7065384bfe2a6d34bc4;hp=44db726bf9eb75949d05fb385c41e19f62d5e1b2;hpb=f22aa9e82ee43e5d390bcb5ab076b24a93e8fda2;p=wfpl.git diff --git a/template.php b/template.php index 44db726..3845c7c 100644 --- a/template.php +++ b/template.php @@ -57,15 +57,14 @@ function parse_template_file($filename) { return parse_template(file_get_contents($filename)); } -# We parse the template string into a tree of strings and sub-templates. +# We parse the template string into a tree of strings and sub-templates. # A template is a hash with a name string, a pieces array, and possibly # an args array. function parse_template($string) { $tem =& tem_push(); $tem['pieces'] = array(); - # note: for some reason this captures ''. - $matches = preg_split("/()/", $string, -1, PREG_SPLIT_DELIM_CAPTURE); + $matches = preg_split('/()/', 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) { @@ -85,13 +84,13 @@ function parse_template($string) { array_pop($args); # drop '}' $cur = $tem['name']; if($name && $name != $cur) { - die("Invalid template: tried to close '$name', but '$cur' is current."); + die("Invalid template: tried to close '$name', but '$cur' is current."); } $tem =& $tem['parent']; } else { # value slot $tem['pieces'][] = array('name' => $name, 'args' => $args); } - } elseif($match and $match != '