1+ #![ cfg_attr( not( feature = "alloc" ) , no_std) ]
2+
3+ #[ cfg( feature = "normalization" ) ]
14use unicode_normalization:: UnicodeNormalization ;
25
6+ #[ cfg( feature = "normalization" ) ]
37extern crate unicode_normalization;
48
59include ! ( concat!( env!( "OUT_DIR" ) , "/case_folding_data.rs" ) ) ;
610
711
12+ #[ cfg( feature = "normalization" ) ]
813pub trait Caseless {
914 fn default_case_fold ( self ) -> CaseFold < Self > where Self : Sized ;
1015 fn default_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool ;
1116 fn canonical_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool ;
1217 fn compatibility_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool ;
1318}
1419
20+ #[ cfg( not( feature = "normalization" ) ) ]
21+ // This trait is private when the `normalization` feature is disabled. Otherwise, external crates
22+ // implementing the version without the `normalization` methods might get linked into projects that
23+ // do use the `normalization` feature, causing a trait mismatch error.
24+ trait Caseless {
25+ fn default_case_fold ( self ) -> CaseFold < Self > where Self : Sized ;
26+ fn default_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool ;
27+ }
28+
1529impl < I : Iterator < Item =char > > Caseless for I {
1630 fn default_case_fold ( self ) -> CaseFold < I > {
1731 CaseFold {
@@ -25,6 +39,7 @@ impl<I: Iterator<Item=char>> Caseless for I {
2539 other. default_case_fold ( ) )
2640 }
2741
42+ #[ cfg( feature = "normalization" ) ]
2843 fn canonical_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool {
2944 // FIXME: Inner NFD can be optimized:
3045 // "Normalization is not required before case folding,
@@ -39,6 +54,7 @@ impl<I: Iterator<Item=char>> Caseless for I {
3954 other. nfd ( ) . default_case_fold ( ) . nfd ( ) )
4055 }
4156
57+ #[ cfg( feature = "normalization" ) ]
4258 fn compatibility_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool {
4359 // FIXME: Unclear if the inner NFD can be optimized here like in canonical_caseless_match.
4460 iter_eq ( self . nfd ( ) . default_case_fold ( ) . nfkd ( ) . default_case_fold ( ) . nfkd ( ) ,
@@ -47,6 +63,7 @@ impl<I: Iterator<Item=char>> Caseless for I {
4763
4864}
4965
66+ #[ cfg( feature = "alloc" ) ]
5067pub fn default_case_fold_str ( s : & str ) -> String {
5168 s. chars ( ) . default_case_fold ( ) . collect ( )
5269}
@@ -55,10 +72,12 @@ pub fn default_caseless_match_str(a: &str, b: &str) -> bool {
5572 a. chars ( ) . default_caseless_match ( b. chars ( ) )
5673}
5774
75+ #[ cfg( feature = "normalization" ) ]
5876pub fn canonical_caseless_match_str ( a : & str , b : & str ) -> bool {
5977 a. chars ( ) . canonical_caseless_match ( b. chars ( ) )
6078}
6179
80+ #[ cfg( feature = "normalization" ) ]
6281pub fn compatibility_caseless_match_str ( a : & str , b : & str ) -> bool {
6382 a. chars ( ) . compatibility_caseless_match ( b. chars ( ) )
6483}
@@ -116,9 +135,10 @@ impl<I> Iterator for CaseFold<I> where I: Iterator<Item = char> {
116135
117136#[ cfg( test) ]
118137mod tests {
119- use super :: default_case_fold_str ;
138+ use super :: * ;
120139
121140 #[ test]
141+ #[ cfg( feature = "alloc" ) ]
122142 fn test_strs ( ) {
123143 assert_eq ! ( default_case_fold_str( "Test Case" ) , "test case" ) ;
124144 assert_eq ! ( default_case_fold_str( "Teſt Caſe" ) , "test case" ) ;
0 commit comments