1
2
3
4
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#[cfg(feature = "ascii")]
mod data_ascii;
#[cfg(feature = "ascii")]
use data_ascii::LAY_CHARS;
#[cfg(feature = "bmp")]
mod data_bmp;
#[cfg(feature = "bmp")]
use data_bmp::LAY_CHARS;
use unicode_normalization::{
UnicodeNormalization,
};
pub fn lower_lay_char(c: char) -> char {
LAY_CHARS.get(c as usize).map(|&c| c as char).unwrap_or(c)
}
pub fn lower_lay_string(s: &str) -> String {
s.chars()
.map(|c| lower_lay_char(c))
.collect()
}
pub fn normalized_lower_lay_string(s: &str) -> String {
s.nfc()
.map(|c| lower_lay_char(c))
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_normalized_lower_lay_string() {
let s = "Comunicações";
assert_eq!(s.chars().count(), 14);
let s = normalized_lower_lay_string(s);
assert_eq!(s.chars().count(), 12);
assert_eq!(s, "comunicacoes");
}
}