summaryrefslogtreecommitdiff
path: root/src/normalize/mod.rs
blob: 62942018c1b330d50af6fa1a7b43fd7cb1688eac (plain)
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
mod string;

pub mod nfc {
    use std::string::String as StdString;

    use unicode_normalization::UnicodeNormalization as _;

    pub type String = super::string::String<Nfc>;

    #[derive(Clone, Debug, Default, Eq, PartialEq)]
    pub struct Nfc;

    impl super::string::Normalize for Nfc {
        fn normalize(&self, value: &str) -> StdString {
            value.nfc().collect()
        }
    }
}

pub mod ident {
    use std::string::String as StdString;

    use unicode_casefold::UnicodeCaseFold as _;
    use unicode_normalization::UnicodeNormalization as _;

    pub type String = super::string::String<Ident>;

    #[derive(Clone, Debug, Default, Eq, PartialEq)]
    pub struct Ident;

    impl super::string::Normalize for Ident {
        fn normalize(&self, value: &str) -> StdString {
            value.case_fold().nfkc().collect()
        }
    }
}