Skip to content

Commit e9ddfa6

Browse files
committed
wip
1 parent f7a0086 commit e9ddfa6

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/Utils/Strings.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,17 @@ public static function toAscii(string $s): string
159159
if ($transliterator) {
160160
$s = $transliterator->transliterate($s);
161161
// The transliterator leaves some characters out of ASCII, eg → ʾ
162-
$s = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $s);
162+
if (ICONV_IMPL === 'glibc') {
163+
// temporarily hide these characters to distinguish them from the garbage that iconv creates
164+
$s = strtr($s, '?', "\x01");
165+
$s = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $s);
166+
// remove garbage that iconv creates during transliteration
167+
$s = str_replace(['`', "'", '"', '^', '~', '?'], '', $s);
168+
// restore temporarily hidden characters
169+
$s = strtr($s, "\x01", '?');
170+
} else {
171+
$s = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $s);
172+
}
163173
} else {
164174
// temporarily hide these characters to distinguish them from the garbage that iconv creates
165175
$s = strtr($s, '`\'"^~?', "\x01\x02\x03\x04\x05\x06");

0 commit comments

Comments
 (0)