Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions src/Parsing/ParserState.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ParserState
/**
* @var array<int, string>
*/
private $characters;
private $characters = [];

/**
* @var int
Expand All @@ -44,11 +44,6 @@ class ParserState
*/
private $charset;

/**
* @var int
*/
private $length;

/**
* @var int
*/
Expand All @@ -75,7 +70,6 @@ public function setCharset(string $charset): void
{
$this->charset = $charset;
$this->characters = $this->strsplit($this->text);
$this->length = \count($this->characters);
}

/**
Expand Down Expand Up @@ -225,7 +219,7 @@ public function consumeWhiteSpace(): array
try {
$oComment = $this->consumeComment();
} catch (UnexpectedEOFException $e) {
$this->currentPosition = $this->length;
$this->currentPosition = \count($this->characters);
return $comments;
}
} else {
Expand Down Expand Up @@ -257,7 +251,7 @@ public function comes($sString, $bCaseInsensitive = false): bool
public function peek($length = 1, $offset = 0): string
{
$offset += $this->currentPosition;
if ($offset >= $this->length) {
if ($offset >= \count($this->characters)) {
return '';
}
return $this->substr($offset, $length);
Expand Down Expand Up @@ -286,7 +280,7 @@ public function consume($mValue = 1): string
$this->currentPosition += $this->strlen($mValue);
return $mValue;
} else {
if ($this->currentPosition + $mValue > $this->length) {
if ($this->currentPosition + $mValue > \count($this->characters)) {
throw new UnexpectedEOFException((string) $mValue, $this->peek(5), 'count', $this->lineNumber);
}
$result = $this->substr($this->currentPosition, $mValue);
Expand Down Expand Up @@ -343,7 +337,7 @@ public function consumeComment()

public function isEnd(): bool
{
return $this->currentPosition >= $this->length;
return $this->currentPosition >= \count($this->characters);
}

/**
Expand Down Expand Up @@ -436,10 +430,10 @@ public function strlen($sString): int
private function substr($iStart, $length): string
{
if ($length < 0) {
$length = $this->length - $iStart + $length;
$length = \count($this->characters) - $iStart + $length;
}
if ($iStart + $length > $this->length) {
$length = $this->length - $iStart;
if ($iStart + $length > \count($this->characters)) {
$length = \count($this->characters) - $iStart;
}
$result = '';
while ($length > 0) {
Expand Down