Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Component/Transliteration/PhpTransliteration.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
105 * {@inheritdoc} | 105 * {@inheritdoc} |
106 */ | 106 */ |
107 public function transliterate($string, $langcode = 'en', $unknown_character = '?', $max_length = NULL) { | 107 public function transliterate($string, $langcode = 'en', $unknown_character = '?', $max_length = NULL) { |
108 $result = ''; | 108 $result = ''; |
109 $length = 0; | 109 $length = 0; |
110 $hash = FALSE; | |
111 | |
112 // Replace question marks with a unique hash if necessary. This because | |
113 // mb_convert_encoding() replaces all invalid characters with a question | |
114 // mark. | |
115 if ($unknown_character != '?' && strpos($string, '?') !== FALSE) { | |
116 $hash = hash('sha256', $string); | |
117 $string = str_replace('?', $hash, $string); | |
118 } | |
119 | |
120 // Ensure the string is valid UTF8 for preg_split(). Unknown characters will | |
121 // be replaced by a question mark. | |
122 $string = mb_convert_encoding($string, 'UTF-8', 'UTF-8'); | |
123 | |
124 // Use the provided unknown character instead of a question mark. | |
125 if ($unknown_character != '?') { | |
126 $string = str_replace('?', $unknown_character, $string); | |
127 // Restore original question marks if necessary. | |
128 if ($hash !== FALSE) { | |
129 $string = str_replace($hash, '?', $string); | |
130 } | |
131 } | |
132 | |
110 // Split into Unicode characters and transliterate each one. | 133 // Split into Unicode characters and transliterate each one. |
111 foreach (preg_split('//u', $string, 0, PREG_SPLIT_NO_EMPTY) as $character) { | 134 foreach (preg_split('//u', $string, 0, PREG_SPLIT_NO_EMPTY) as $character) { |
112 $code = self::ordUTF8($character); | 135 $code = self::ordUTF8($character); |
113 if ($code == -1) { | 136 if ($code == -1) { |
114 $to_add = $unknown_character; | 137 $to_add = $unknown_character; |