Aer/tests/unicode_characters.aer
belliash 4d8d92092e
All checks were successful
The build was successful.
Refactor foreach() loop.
In AerScript, the foreach() loop is syntatically more similiar to C#, than PHP. However the optional '$key => $value' construct is still available, because arrays in AerScript are still a hashmaps.
2019-04-30 23:38:59 +02:00

59 lines
1.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class Unicode {
public string unicon(string $str, bool $to_uni = true) {
string $cpp;
string[] $cp = {'А' => 'А', 'а' => 'а',
"Б" => "Б", "б" => "б",
"В" => "В", "в" => "в",
"Г" => "Г", "г" => "г",
"Д" => "Д", "д" => "д",
"Е" => "Е", "е" => "е",
"Ё" => "Ё", "ё" => "ё",
"Ж" => "Ж", "ж" => "ж",
"З" => "З", "з" => "з",
"И" => "И", "и" => "и",
"Й" => "Й", "й" => "й",
"К" => "К", "к" => "к",
"Л" => "Л", "л" => "л",
"М" => "М", "м" => "м",
"Н" => "Н", "н" => "н",
"О" => "О", "о" => "о",
"П" => "П", "п" => "п",
"Р" => "Р", "р" => "р",
"С" => "С", "с" => "с",
"Т" => "Т", "т" => "т",
"У" => "У", "у" => "у",
"Ф" => "Ф", "ф" => "ф",
"Х" => "Х", "х" => "х",
"Ц" => "Ц", "ц" => "ц",
"Ч" => "Ч", "ч" => "ч",
"Ш" => "Ш", "ш" => "ш",
"Щ" => "Щ", "щ" => "щ",
"Ъ" => "Ъ", "ъ" => "ъ",
"Ы" => "Ы", "ы" => "ы",
"Ь" => "Ь", "ь" => "ь",
"Э" => "Э", "э" => "э",
"Ю" => "Ю", "ю" => "ю",
"Я" => "Я", "я" => "я"};
if($to_uni) {
$str = strtr($str, $cp);
} else {
foreach($c in $cp) {
$cpp[$c] = array_search($c, $cp);
}
$str = strtr($str, $cpp);
}
return $str;
}
}
final class Program {
public void main() {
object $unicode = new Unicode();
var_dump($unicode->unicon("ИфйжБЦ"));
}
}