From 1a24065c727870a3c4b05e3359ded8ad46fa7c41 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Wed, 26 Feb 2025 09:52:23 +0300 Subject: [PATCH] Fixing minor bugs in parser error line reporter --- jzon.inc.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/jzon.inc.php b/jzon.inc.php index 76e0a37..03699f8 100644 --- a/jzon.inc.php +++ b/jzon.inc.php @@ -11,16 +11,17 @@ function jzon_show_position(int $p, string $in, int $context_lines = 5) : string $out = array(); $lines = explode("\n", $in); //let's find out the maximum leading zeros for line numbers - $fmt_num = (int)round(log10(count($lines))); + $fmt_num = (int)round(log10(count($lines)))+1; foreach($lines as $line_idx => $line) { - //adding line numbers and handling tabs - $out[] = sprintf('%0'.$fmt_num.'d', $line_idx) . ' ' . str_replace("\t", " ", $line); + //adding line numbers and normalizing tabs by converting them to spaces + $out[] = sprintf('%0'.$fmt_num.'d', ($line_idx+1)) . ' ' . str_replace("\t", " ", $line); $left = $p - (strlen($line) + 1/*taking into account \n*/); //var_dump($left, $p, $line, $fmt_num); - if($left < 0) + if($left <= 0) { $arrow = str_repeat('-', $fmt_num) . '-'; //line numbers + //let's normalize tabs for($i=0;$i<$p;++$i) $arrow .= ($line[$i] === "\t" ? '----' : '-'); $arrow .= '^';