Skip to content
Merged
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
21 changes: 13 additions & 8 deletions packages/intl/src/MessageFormat/Parser/MessageFormatParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@

final class MessageFormatParser
{
private string $input;
/** @var list<string> */
private array $chars;

private int $pos = 0;

Expand All @@ -54,8 +55,8 @@ final class MessageFormatParser

public function __construct(string $input)
{
$this->input = str_replace("\r\n", "\n", $input);
$this->len = mb_strlen($this->input, 'UTF-8');
$this->chars = mb_str_split(str_replace("\r\n", "\n", $input), 1, 'UTF-8');
$this->len = count($this->chars);
}

/**
Expand Down Expand Up @@ -610,10 +611,7 @@ private function readChar(): string
return '';
}

$char = mb_substr($this->input, $this->pos, 1, 'UTF-8');
$this->pos++;

return $char;
return $this->chars[$this->pos++];
}

private function peek(int $length = 1): string
Expand All @@ -622,7 +620,14 @@ private function peek(int $length = 1): string
return '';
}

return mb_substr($this->input, $this->pos, $length, 'UTF-8');
$peek = '';
$end = min($this->pos + $length, $this->len);

for ($offset = $this->pos; $offset < $end; $offset++) {
$peek .= $this->chars[$offset];
}

return $peek;
}

private function isEof(): bool
Expand Down
Loading