Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Commit

Permalink
fix theiconic#36 make InitialMapper multibyte proof
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanlaak committed Nov 26, 2019
1 parent 9a54a71 commit 5a32bd3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
}
],
"require": {
"php": ">=7.1"
"php": ">=7.1",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "^7.0",
Expand Down
9 changes: 5 additions & 4 deletions src/Mapper/InitialMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ public function map(array $parts): array

if (strtoupper($part) === $part) {
$stripped = str_replace('.', '', $part);
$length = strlen($stripped);
$length = mb_strlen($stripped);

if (1 < $length && $length <= $this->combinedMax) {
array_splice($parts, $k, 1, str_split($stripped));
$charactersAsArray = preg_split('//u', $stripped, null, PREG_SPLIT_NO_EMPTY);
array_splice($parts, $k, 1, $charactersAsArray);
$last = count($parts) - 1;
$part = $parts[$k];
}
Expand All @@ -66,12 +67,12 @@ public function map(array $parts): array
*/
protected function isInitial(string $part): bool
{
$length = strlen($part);
$length = mb_strlen($part);

if (1 === $length) {
return true;
}

return ($length === 2 && substr($part, -1) === '.');
return ($length === 2 && mb_substr($part, -1) === '.');
}
}

0 comments on commit 5a32bd3

Please sign in to comment.