X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=template.php;h=45857afcecde5532be9c7651ac7a7bbb552bf29a;hb=0c70f6a8cdf46b61c8d30f918833b8f2d8522009;hp=1667cdead3e1c59287a0f422311b3c5b748e406e;hpb=dfd0f158f89020b3142e41127d21e48c8512aa1e;p=wfpl.git diff --git a/template.php b/template.php index 1667cde..45857af 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 != ' # # row content... -#