From d6cd63d77dd9a85c3a2fae707e1255e44c2bc182 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 3 Jan 2020 19:04:43 +0100 Subject: [PATCH] =?UTF-8?q?Strings::toAscii=20transliterates=20=D1=8F/?= =?UTF-8?q?=D1=8E=20as=20ya/yu=20[Closes=20#203]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Utils/Strings.php | 4 ++-- tests/Utils/Strings.toAscii().phpt | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Utils/Strings.php b/src/Utils/Strings.php index 05e420ad6..c1ca9993b 100644 --- a/src/Utils/Strings.php +++ b/src/Utils/Strings.php @@ -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 diff --git a/tests/Utils/Strings.toAscii().phpt b/tests/Utils/Strings.toAscii().phpt index 1ea1a51d6..0f16fc6df 100644 --- a/tests/Utils/Strings.toAscii().phpt +++ b/tests/Utils/Strings.toAscii().phpt @@ -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}")); // Я я Ю ю