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" ) ) ;
@@ -8,7 +12,9 @@ include!(concat!(env!("OUT_DIR"), "/case_folding_data.rs"));
812pub trait Caseless {
913 fn default_case_fold ( self ) -> CaseFold < Self > where Self : Sized ;
1014 fn default_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool ;
15+ #[ cfg( feature = "normalization" ) ]
1116 fn canonical_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool ;
17+ #[ cfg( feature = "normalization" ) ]
1218 fn compatibility_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool ;
1319}
1420
@@ -25,6 +31,7 @@ impl<I: Iterator<Item=char>> Caseless for I {
2531 other. default_case_fold ( ) )
2632 }
2733
34+ #[ cfg( feature = "normalization" ) ]
2835 fn canonical_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool {
2936 // FIXME: Inner NFD can be optimized:
3037 // "Normalization is not required before case folding,
@@ -39,6 +46,7 @@ impl<I: Iterator<Item=char>> Caseless for I {
3946 other. nfd ( ) . default_case_fold ( ) . nfd ( ) )
4047 }
4148
49+ #[ cfg( feature = "normalization" ) ]
4250 fn compatibility_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool {
4351 // FIXME: Unclear if the inner NFD can be optimized here like in canonical_caseless_match.
4452 iter_eq ( self . nfd ( ) . default_case_fold ( ) . nfkd ( ) . default_case_fold ( ) . nfkd ( ) ,
@@ -47,6 +55,7 @@ impl<I: Iterator<Item=char>> Caseless for I {
4755
4856}
4957
58+ #[ cfg( feature = "alloc" ) ]
5059pub fn default_case_fold_str ( s : & str ) -> String {
5160 s. chars ( ) . default_case_fold ( ) . collect ( )
5261}
@@ -55,10 +64,12 @@ pub fn default_caseless_match_str(a: &str, b: &str) -> bool {
5564 a. chars ( ) . default_caseless_match ( b. chars ( ) )
5665}
5766
67+ #[ cfg( feature = "normalization" ) ]
5868pub fn canonical_caseless_match_str ( a : & str , b : & str ) -> bool {
5969 a. chars ( ) . canonical_caseless_match ( b. chars ( ) )
6070}
6171
72+ #[ cfg( feature = "normalization" ) ]
6273pub fn compatibility_caseless_match_str ( a : & str , b : & str ) -> bool {
6374 a. chars ( ) . compatibility_caseless_match ( b. chars ( ) )
6475}
@@ -116,9 +127,10 @@ impl<I> Iterator for CaseFold<I> where I: Iterator<Item = char> {
116127
117128#[ cfg( test) ]
118129mod tests {
119- use super :: default_case_fold_str ;
130+ use super :: * ;
120131
121132 #[ test]
133+ #[ cfg( feature = "alloc" ) ]
122134 fn test_strs ( ) {
123135 assert_eq ! ( default_case_fold_str( "Test Case" ) , "test case" ) ;
124136 assert_eq ! ( default_case_fold_str( "Teſt Caſe" ) , "test case" ) ;
0 commit comments