Skip to content

Commit 88187c7

Browse files
committed
Strings::toAscii transliterates я/ю as ya/yu [Closes #203]
1 parent e4ffbcb commit 88187c7

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/Utils/Strings.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,18 @@ public static function toAscii(string $s): string
145145
$s = self::pcre('preg_replace', ['#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{2FF}\x{370}-\x{10FFFF}]#u', '', $s]);
146146
$s = strtr($s, '`\'"^~?', "\x01\x02\x03\x04\x05\x06");
147147
$s = str_replace(
148-
["\u{201E}", "\u{201C}", "\u{201D}", "\u{201A}", "\u{2018}", "\u{2019}", "\u{B0}"],
149-
["\x03", "\x03", "\x03", "\x02", "\x02", "\x02", "\x04"], $s
148+
["\u{201E}", "\u{201C}", "\u{201D}", "\u{201A}", "\u{2018}", "\u{2019}", "\u{B0}", "\u{42F}", "\u{44F}", "\u{42E}", "\u{44E}"], // „ “ ” ‚ ‘ ’ ° Я я Ю ю
149+
["\x03", "\x03", "\x03", "\x02", "\x02", "\x02", "\x04", 'Ya', 'ya', 'Yu', 'yu'],
150+
$s
150151
);
151152
if ($transliterator !== null) {
152153
$s = $transliterator->transliterate($s);
153154
}
154155
if (ICONV_IMPL === 'glibc') {
155156
$s = str_replace(
156-
["\u{BB}", "\u{AB}", "\u{2026}", "\u{2122}", "\u{A9}", "\u{AE}"],
157-
['>>', '<<', '...', 'TM', '(c)', '(R)'], $s
157+
["\u{BB}", "\u{AB}", "\u{2026}", "\u{2122}", "\u{A9}", "\u{AE}"], // » « … ™ © ®
158+
['>>', '<<', '...', 'TM', '(c)', '(R)'],
159+
$s
158160
);
159161
$s = iconv('UTF-8', 'WINDOWS-1250//TRANSLIT//IGNORE', $s);
160162
$s = strtr($s, "\xa5\xa3\xbc\x8c\xa7\x8a\xaa\x8d\x8f\x8e\xaf\xb9\xb3\xbe\x9c\x9a\xba\x9d\x9f\x9e"

tests/Utils/Strings.toAscii().phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ Assert::exception(function () {
2828
if (class_exists('Transliterator') && \Transliterator::create('Any-Latin; Latin-ASCII')) {
2929
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}")); // Αθήνα→Москва
3030
}
31+
32+
33+
Assert::same('Ya ya Yu yu', Strings::toAscii("\u{42F} \u{44F} \u{42E} \u{44E}")); // Я я Ю ю

0 commit comments

Comments
 (0)