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
55
56
57
58
59
60
61
62
63
#[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,
};
#[inline(always)]
pub fn lower_lay_char(c: char) -> char {
if (c as usize) < LAY_CHARS.len() {
unsafe {
*LAY_CHARS.get_unchecked(c as usize)
}
} else {
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";
let nor = s.nfc().collect::<String>();
println!("{:?}", nor);
assert_eq!(s.chars().count(), 15);
let s = normalized_lower_lay_string(s);
assert_eq!(s.chars().count(), 12);
assert_eq!(s, "comunicacoes");
}
}