Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
44 changes: 22 additions & 22 deletions src/Parsing/ParserState.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ParserState
/**
* @var int
*/
private $iLength;
private $length;

/**
* @var int
Expand Down Expand Up @@ -78,7 +78,7 @@ public function setCharset($charset): void
$this->charset = $charset;
$this->characters = $this->strsplit($this->text);
if (\is_array($this->characters)) {
$this->iLength = \count($this->characters);
$this->length = \count($this->characters);
}
}

Expand Down Expand Up @@ -233,7 +233,7 @@ public function consumeWhiteSpace(): array
try {
$oComment = $this->consumeComment();
} catch (UnexpectedEOFException $e) {
$this->currentPosition = $this->iLength;
$this->currentPosition = $this->length;
return $comments;
}
} else {
Expand All @@ -259,16 +259,16 @@ public function comes($sString, $bCaseInsensitive = false): bool
}

/**
* @param int $iLength
* @param int $length
* @param int $iOffset
*/
public function peek($iLength = 1, $iOffset = 0): string
public function peek($length = 1, $iOffset = 0): string
{
$iOffset += $this->currentPosition;
if ($iOffset >= $this->iLength) {
if ($iOffset >= $this->length) {
return '';
}
return $this->substr($iOffset, $iLength);
return $this->substr($iOffset, $length);
}

/**
Expand All @@ -281,11 +281,11 @@ public function consume($mValue = 1): string
{
if (\is_string($mValue)) {
$iLineCount = \substr_count($mValue, "\n");
$iLength = $this->strlen($mValue);
if (!$this->streql($this->substr($this->currentPosition, $iLength), $mValue)) {
$length = $this->strlen($mValue);
if (!$this->streql($this->substr($this->currentPosition, $length), $mValue)) {
throw new UnexpectedTokenException(
$mValue,
$this->peek(\max($iLength, 5)),
$this->peek(\max($length, 5)),
'literal',
$this->lineNumber
);
Expand All @@ -294,7 +294,7 @@ public function consume($mValue = 1): string
$this->currentPosition += $this->strlen($mValue);
return $mValue;
} else {
if ($this->currentPosition + $mValue > $this->iLength) {
if ($this->currentPosition + $mValue > $this->length) {
throw new UnexpectedEOFException((string) $mValue, $this->peek(5), 'count', $this->lineNumber);
}
$result = $this->substr($this->currentPosition, $mValue);
Expand Down Expand Up @@ -351,7 +351,7 @@ public function consumeComment()

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

/**
Expand Down Expand Up @@ -439,21 +439,21 @@ public function strlen($sString): int

/**
* @param int $iStart
* @param int $iLength
* @param int $length
*/
private function substr($iStart, $iLength): string
private function substr($iStart, $length): string
{
if ($iLength < 0) {
$iLength = $this->iLength - $iStart + $iLength;
if ($length < 0) {
$length = $this->length - $iStart + $length;
}
if ($iStart + $iLength > $this->iLength) {
$iLength = $this->iLength - $iStart;
if ($iStart + $length > $this->length) {
$length = $this->length - $iStart;
}
$result = '';
while ($iLength > 0) {
while ($length > 0) {
$result .= $this->characters[$iStart];
$iStart++;
$iLength--;
$length--;
}
return $result;
}
Expand Down Expand Up @@ -481,9 +481,9 @@ private function strsplit($sString)
if ($this->streql($this->charset, 'utf-8')) {
return \preg_split('//u', $sString, -1, PREG_SPLIT_NO_EMPTY);
} else {
$iLength = \mb_strlen($sString, $this->charset);
$length = \mb_strlen($sString, $this->charset);
$result = [];
for ($i = 0; $i < $iLength; ++$i) {
for ($i = 0; $i < $length; ++$i) {
$result[] = \mb_substr($sString, $i, 1, $this->charset);
}
return $result;
Expand Down
6 changes: 3 additions & 3 deletions src/Value/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ public static function parse(ParserState $parserState, $bIsColorComponent = fals

$sUnit = null;
$aSizeUnits = self::getSizeUnits();
foreach ($aSizeUnits as $iLength => &$aValues) {
$sKey = \strtolower($parserState->peek($iLength));
foreach ($aSizeUnits as $length => &$aValues) {
$sKey = \strtolower($parserState->peek($length));
if (\array_key_exists($sKey, $aValues)) {
if (($sUnit = $aValues[$sKey]) !== null) {
$parserState->consume($iLength);
$parserState->consume($length);
break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Value/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,18 @@ public static function parseValue(ParserState $parserState, array $aListDelimite
$aNewStack[] = $aStack[$iStartPosition];
continue;
}
$iLength = 2; //Number of elements to be joined
for ($i = $iStartPosition + 3; $i < $iStackLength; $i += 2, ++$iLength) {
$length = 2; //Number of elements to be joined
for ($i = $iStartPosition + 3; $i < $iStackLength; $i += 2, ++$length) {
if ($sDelimiter !== $aStack[$i]) {
break;
}
}
$list = new RuleValueList($sDelimiter, $parserState->currentLine());
for ($i = $iStartPosition; $i - $iStartPosition < $iLength * 2; $i += 2) {
for ($i = $iStartPosition; $i - $iStartPosition < $length * 2; $i += 2) {
$list->addListComponent($aStack[$i]);
}
$aNewStack[] = $list;
$iStartPosition += $iLength * 2 - 2;
$iStartPosition += $length * 2 - 2;
}
$aStack = $aNewStack;
}
Expand Down