Function decancer::cure_char

source ·
pub fn cure_char<C: Into<u32>>(code: C) -> Translation
Expand description

Cures a single character/unicode codepoint.

Output will always be in lowercase.

§Examples

Most of the time, this would yield only a single unicode character:

use decancer::Translation;

assert_eq!(decancer::cure_char('E'), Translation::Character('e'));

However, for several special cases, it would yield an ASCII &'static str:

use decancer::Translation;

assert_eq!(decancer::cure_char('æ'), Translation::String("ae"));
assert_eq!(decancer::cure_char('ij'), Translation::String("ij"));
assert_eq!(decancer::cure_char('œ'), Translation::String("oe"));
assert_eq!(decancer::cure_char('🆐'), Translation::String("dj"));
assert_eq!(decancer::cure_char('🆑'), Translation::String("cl"));
assert_eq!(decancer::cure_char('🆔'), Translation::String("id"));
assert_eq!(decancer::cure_char('🆖'), Translation::String("ng"));
assert_eq!(decancer::cure_char('🆗'), Translation::String("ok"));
assert_eq!(decancer::cure_char('🆚'), Translation::String("vs"));
assert_eq!(decancer::cure_char('🜀'), Translation::String("qe"));
assert_eq!(decancer::cure_char('🜇'), Translation::String("ar"));

assert_eq!(decancer::cure_char('⅓'), Translation::String("1/3"));
assert_eq!(decancer::cure_char('⅔'), Translation::String("2/3"));
assert_eq!(decancer::cure_char('⅕'), Translation::String("1/5"));
assert_eq!(decancer::cure_char('⅖'), Translation::String("2/5"));
assert_eq!(decancer::cure_char('⅗'), Translation::String("3/5"));
assert_eq!(decancer::cure_char('⅘'), Translation::String("4/5"));
assert_eq!(decancer::cure_char('㋍'), Translation::String("erg"));
assert_eq!(decancer::cure_char('㋏'), Translation::String("ltd"));

assert_eq!(decancer::cure_char('㍴'), Translation::String("bar"));
assert_eq!(decancer::cure_char('㎈'), Translation::String("cal"));
assert_eq!(decancer::cure_char('㎭'), Translation::String("rad"));
assert_eq!(decancer::cure_char('㏇'), Translation::String("co."));
assert_eq!(decancer::cure_char('㏒'), Translation::String("log"));
assert_eq!(decancer::cure_char('㏕'), Translation::String("mil"));
assert_eq!(decancer::cure_char('㏖'), Translation::String("mol"));
assert_eq!(decancer::cure_char('㏙'), Translation::String("ppm"));

If your unicode character is a control character, surrogate, combining character (e.g diacritics), private use character, byte order character, or any invalid unicode value (e.g beyond char::MAX), you would get None:

use decancer::Translation;

assert_eq!(decancer::cure_char(0xD800u32), Translation::None);
assert_eq!(decancer::cure_char(char::REPLACEMENT_CHARACTER), Translation::None);
assert_eq!(decancer::cure_char((char::MAX as u32) + 1), Translation::None);