From ec389d3441953bbd7cb27f59df61531ba856fb33 Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Fri, 1 May 2020 17:52:50 +0200 Subject: Fix parsing `]` as last input char Previously ] was duplicated in the ouput --- src/ste/Parser.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ste/Parser.php b/src/ste/Parser.php index 0280f6d..6e7bf62 100644 --- a/src/ste/Parser.php +++ b/src/ste/Parser.php @@ -43,12 +43,21 @@ class Parser * @param int $n * @return string */ - private function next($n = 1) + private function peek($n = 1) { if ($n <= 0) { throw new \InvalidArgumentException("\$n must be > 0"); } - $c = mb_substr($this->text, $this->off, $n); + return mb_substr($this->text, $this->off, $n); + } + + /** + * @param int $n + * @return string + */ + private function next($n = 1) + { + $c = $this->peek($n); $this->off = min($this->off + $n, $this->len); return $c; } @@ -455,7 +464,9 @@ class Parser $arrayfields = array(); - while ($this->next() == "[") { + while ($this->peek() == "[") { + $this->next(); + $openedat = $this->off - 1; $res = $this->parse_text( self::ESCAPES_DEFAULT, /* Escapes */ @@ -471,7 +482,6 @@ class Parser $arrayfields[] = $res[0]; } - $this->back(); return $arrayfields; } -- cgit v1.2.3-54-g00ecf