const LOZYNSKY_RULES: &[(&str, &str)] = &[
("Дь", "Ď"),
("дь", "ď"),
("Ль", "L"),
("ль", "l"),
("Нь", "Ń"),
("нь", "ń"),
("Рь", "R’"),
("рь", "r’"),
("Сь", "Ś"),
("сь", "ś"),
("Ть", "Ť"),
("ть", "ť"),
("Ць", "Ć"),
("ць", "ć"),
("Зь", "Ź"),
("зь", "ź"),
("А", "A"),
("а", "a"),
("Б", "B"),
("б", "b"),
("В", "W"),
("в", "w"),
("Г", "H"),
("г", "h"),
("Ґ", "G"),
("ґ", "g"),
("Д", "D"),
("д", "d"),
("Е", "E"),
("е", "e"),
("Є", "Je"),
("є", "je"),
("Ж", "Ż"),
("ж", "ż"),
("З", "Z"),
("з", "z"),
("И", "Y"),
("и", "y"),
("І", "I"),
("і", "i"),
("Ї", "Ji"),
("ї", "ji"),
("Й", "J"),
("й", "j"),
("К", "K"),
("к", "k"),
("Л", "Ł"),
("л", "ł"),
("М", "M"),
("м", "m"),
("Н", "N"),
("н", "n"),
("О", "O"),
("о", "o"),
("П", "P"),
("п", "p"),
("Р", "R"),
("р", "r"),
("С", "S"),
("с", "s"),
("Т", "T"),
("т", "t"),
("У", "U"),
("у", "u"),
("Ф", "F"),
("ф", "f"),
("Х", "Ch"),
("х", "ch"),
("Ц", "C"),
("ц", "c"),
("Ч", "Cz"),
("ч", "cz"),
("Ш", "Sz"),
("ш", "sz"),
("Щ", "Szcz"),
("щ", "szcz"),
("Ю", "Ju"),
("ю", "ju"),
("Я", "Ja"),
("я", "ja"),
("Ь", "’"),
("ь", "’"),
];
pub fn transliterate_lozynsky(text: &str) -> String {
let mut output = String::with_capacity(text.len());
let mut index = 0;
while index < text.len() {
let mut matched = false;
for (cyrillic, latin) in LOZYNSKY_RULES {
if text[index..].starts_with(cyrillic) {
output.push_str(latin);
index += cyrillic.len();
matched = true;
break;
}
}
if !matched {
if let Some(ch) = text[index..].chars().next() {
output.push(ch);
index += ch.len_utf8();
} else {
break;
}
}
}
output
}