pub struct Transliterator { /* private fields */ }
Expand description
The Transliterator
struct allows for the transliteration
of the string of characters of Cyrillic alphabet UTF-8 to Latin alphabet
and back.
Implementations§
Source§impl Transliterator
impl Transliterator
Sourcepub fn new(custom_rules: CharsMapping) -> Self
pub fn new(custom_rules: CharsMapping) -> Self
Creates a new Transliterator
with transliteration table
Examples
use translit::{Transliterator, CharsMapping};
let table: CharsMapping =
[
("а", "a"),
("с", "s"),
("д", "d"),
("ф", "f"),
].iter()
.cloned()
.collect();
let trasliterator = Transliterator::new(table);
let res = trasliterator.convert("фасад", false);
assert_eq!("fasad", res);
Examples found in repository?
examples/web-gost779.rs (line 28)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
fn main() {
let v: CharsMapping = [
(" ", "-"),
(",", ""),
(":", ""),
(";", ""),
("№", ""),
("ь", ""),
("ъ", ""),
("Ы", "Y"),
("Э", "E"),
("ы", "y"),
("э", "e"),
]
.iter()
.cloned()
.collect();
let mut custom_table = gost779b_ru();
custom_table.retain(|&x| !x.1.contains("`"));
custom_table.retain(|&x| !x.1.contains("#"));
custom_table.extend(v.iter());
let trn = Transliterator::new(custom_table);
let source =
"Общие вопросы по языку, получение помощи".to_lowercase();
assert_eq!(
"obshhie-voprosy-po-yazyku-poluchenie-pomoshhi",
trn.to_latin(&source)
);
}
Trait Implementations§
Source§impl FromLatin for Transliterator
impl FromLatin for Transliterator
Source§fn from_latin(&self, src: &str) -> String
fn from_latin(&self, src: &str) -> String
The wrapper on the method convert
of transliteration from the Latin alphabet
Auto Trait Implementations§
impl Freeze for Transliterator
impl RefUnwindSafe for Transliterator
impl Send for Transliterator
impl Sync for Transliterator
impl Unpin for Transliterator
impl UnwindSafe for Transliterator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more