Skip to content

Commit

Permalink
[String] add missing encoding when calling mb_ord()
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jan 14, 2020
1 parent 4a1bd8a commit 978261d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion AbstractUnicodeString.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,17 @@ public function codePointsAt(int $offset): array
{
$str = $this->slice($offset, 1);

return '' === $str->string ? [] : array_map('mb_ord', preg_split('//u', $str->string, -1, PREG_SPLIT_NO_EMPTY));
if ('' === $str->string) {
return [];
}

$codePoints = [];

foreach (preg_split('//u', $str->string, -1, PREG_SPLIT_NO_EMPTY) as $c) {
$codePoints[] = mb_ord($c, 'UTF-8');
}

return $codePoints;
}

public function folded(bool $compat = true): parent
Expand Down
2 changes: 1 addition & 1 deletion CodePointString.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function codePointsAt(int $offset): array
{
$str = $offset ? $this->slice($offset, 1) : $this;

return '' === $str->string ? [] : [mb_ord($str->string)];
return '' === $str->string ? [] : [mb_ord($str->string, 'UTF-8')];
}

public function endsWith($suffix): bool
Expand Down

0 comments on commit 978261d

Please sign in to comment.