Skip to content

Commit

Permalink
Strings::toAscii transliterates я/ю as ya/yu [Closes #203]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 3, 2020
1 parent 62b1416 commit d6cd63d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Utils/Strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public static function toAscii(string $s): string
$s = self::pcre('preg_replace', ['#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{2FF}\x{370}-\x{10FFFF}]#u', '', $s]);
// transliteration (by Transliterator and iconv) is not optimal, replace some characters directly
$s = str_replace(
["\u{201E}", "\u{201C}", "\u{201D}", "\u{201A}", "\u{2018}", "\u{2019}", "\u{B0}"], // „ “ ” ‚ ‘ ’ °
['"', '"', '"', "'", "'", "'", '^'],
["\u{201E}", "\u{201C}", "\u{201D}", "\u{201A}", "\u{2018}", "\u{2019}", "\u{B0}", "\u{42F}", "\u{44F}", "\u{42E}", "\u{44E}"], // „ “ ” ‚ ‘ ’ ° Я я Ю ю
['"', '"', '"', "'", "'", "'", '^', 'Ya', 'ya', 'Yu', 'yu'],
$s
);
// temporarily hide these characters to distinguish them from the garbage that iconv creates
Expand Down
3 changes: 3 additions & 0 deletions tests/Utils/Strings.toAscii().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ Assert::exception(function () {
if (class_exists('Transliterator') && \Transliterator::create('Any-Latin; Latin-ASCII')) {
Assert::same('Athena->Moskva', Strings::toAscii("\u{391}\u{3B8}\u{3AE}\u{3BD}\u{3B1}\u{2192}\u{41C}\u{43E}\u{441}\u{43A}\u{432}\u{430}")); // Αθήνα→Москва
}


Assert::same('Ya ya Yu yu', Strings::toAscii("\u{42F} \u{44F} \u{42E} \u{44E}")); // Я я Ю ю

0 comments on commit d6cd63d

Please sign in to comment.