From 4bf14ccb74174e319fb370e656018a6b8bad0e0e Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Tue, 21 Feb 2012 01:08:38 +0100 Subject: Fixed some error message bugs. * Very often the error offsets of parsing errors were too high. * The offset to line translation now works cleaner and should no longer throw PHP errors. --- stupid_template_engine.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'stupid_template_engine.php') diff --git a/stupid_template_engine.php b/stupid_template_engine.php index 48164c1..d6fe98c 100644 --- a/stupid_template_engine.php +++ b/stupid_template_engine.php @@ -82,7 +82,7 @@ class ParseCompileError extends \Exception public function rewrite($code) { - $line = substr_count(str_replace("\r\n", "\n", $code), "\n", 0, $this->off + 1) + 1; + $line = substr_count(str_replace("\r\n", "\n", substr($code, 0, $this->off)), "\n") + 1; $this->message = "{$this->msg} (Template {$this->tpl}, Line $line)"; $this->is_rewritten = True; } @@ -270,7 +270,7 @@ function mk_ast($code, $tpl, $err_off) $off = 0; $last_tag_start = 0; - $tagstack = array(array($tag->name, $tag->offset)); + $tagstack = array(array($tag->name, $tag->offset - $err_off)); while(preg_match("/\\<((?:\\s*)|(?:\\s*\\/\\s*))ste:([a-zA-Z0-9_]*)(?:\\s+(?:[a-zA-Z0-9_]+)=(?:(?:\"(?:.*?)(?/s", $code, $matches, PREG_OFFSET_CAPTURE, $off) > 0) /* RegEx from hell! Matches all Tags. Opening, closing and self-closing ones. */ { if(trim($matches[3][0]) != "/") @@ -1317,4 +1317,4 @@ class STEStandardLibrary } } -?> +?> \ No newline at end of file -- cgit v1.2.3-70-g09d2