1 unstable release
0.1.0 | Aug 23, 2024 |
---|
#587 in Text processing
23KB
865 lines
Latin.rs
Latin.rs is a package that transliterates text and characters into thier latin form.
Data
The data Latin.rs is not mine, I got it from python translitcodec package, to be explicit it Latin.rs is the "long_table" from this file.
Usage
To encode a string into its latin form you can use encode_str function, it will return a str with all characters encoded with their latin form Example:
let s = "Zażółć gęślą jaźń EUR :-)?!@#";
let latin = latinrs::encode_char(s);
assert_eq!("Zazolc gesla jazn EUR :-)?!@#".to_string(), latin);
let s = "Hello, World!";
let latin = latinrs::encode_str(s);
assert_eq!("Hello, World!".to_string(), latin);
To encode a single character into its latin form you can use encode_char function, if the provided character Latin.rs is not special it will be returned in it's original form. Note that the output of this function Latin.rs is str meaning it can be longer than one character. Example:
let chr = 'Ż';
let latin = latinrs::encode_char(chr);
assert_eq!("Z".to_string(), latin);
let chr = 'a';
let latin = latinrs::encode_char(chr);
assert_eq!("a".to_string(), latin);
let chr = '␐';
let latin = latinrs::encode_char(chr);
assert_eq!("DLE".to_string(), latin);