1
+ #![ cfg_attr( not( feature = "alloc" ) , no_std) ]
2
+
3
+ #[ cfg( feature = "normalization" ) ]
1
4
use unicode_normalization:: UnicodeNormalization ;
2
5
6
+ #[ cfg( feature = "normalization" ) ]
3
7
extern crate unicode_normalization;
4
8
5
9
include ! ( concat!( env!( "OUT_DIR" ) , "/case_folding_data.rs" ) ) ;
@@ -8,7 +12,9 @@ include!(concat!(env!("OUT_DIR"), "/case_folding_data.rs"));
8
12
pub trait Caseless {
9
13
fn default_case_fold ( self ) -> CaseFold < Self > where Self : Sized ;
10
14
fn default_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool ;
15
+ #[ cfg( feature = "normalization" ) ]
11
16
fn canonical_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool ;
17
+ #[ cfg( feature = "normalization" ) ]
12
18
fn compatibility_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool ;
13
19
}
14
20
@@ -25,6 +31,7 @@ impl<I: Iterator<Item=char>> Caseless for I {
25
31
other. default_case_fold ( ) )
26
32
}
27
33
34
+ #[ cfg( feature = "normalization" ) ]
28
35
fn canonical_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool {
29
36
// FIXME: Inner NFD can be optimized:
30
37
// "Normalization is not required before case folding,
@@ -39,6 +46,7 @@ impl<I: Iterator<Item=char>> Caseless for I {
39
46
other. nfd ( ) . default_case_fold ( ) . nfd ( ) )
40
47
}
41
48
49
+ #[ cfg( feature = "normalization" ) ]
42
50
fn compatibility_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool {
43
51
// FIXME: Unclear if the inner NFD can be optimized here like in canonical_caseless_match.
44
52
iter_eq ( self . nfd ( ) . default_case_fold ( ) . nfkd ( ) . default_case_fold ( ) . nfkd ( ) ,
@@ -47,6 +55,7 @@ impl<I: Iterator<Item=char>> Caseless for I {
47
55
48
56
}
49
57
58
+ #[ cfg( feature = "alloc" ) ]
50
59
pub fn default_case_fold_str ( s : & str ) -> String {
51
60
s. chars ( ) . default_case_fold ( ) . collect ( )
52
61
}
@@ -55,10 +64,12 @@ pub fn default_caseless_match_str(a: &str, b: &str) -> bool {
55
64
a. chars ( ) . default_caseless_match ( b. chars ( ) )
56
65
}
57
66
67
+ #[ cfg( feature = "normalization" ) ]
58
68
pub fn canonical_caseless_match_str ( a : & str , b : & str ) -> bool {
59
69
a. chars ( ) . canonical_caseless_match ( b. chars ( ) )
60
70
}
61
71
72
+ #[ cfg( feature = "normalization" ) ]
62
73
pub fn compatibility_caseless_match_str ( a : & str , b : & str ) -> bool {
63
74
a. chars ( ) . compatibility_caseless_match ( b. chars ( ) )
64
75
}
@@ -116,9 +127,10 @@ impl<I> Iterator for CaseFold<I> where I: Iterator<Item = char> {
116
127
117
128
#[ cfg( test) ]
118
129
mod tests {
119
- use super :: default_case_fold_str ;
130
+ use super :: * ;
120
131
121
132
#[ test]
133
+ #[ cfg( feature = "alloc" ) ]
122
134
fn test_strs ( ) {
123
135
assert_eq ! ( default_case_fold_str( "Test Case" ) , "test case" ) ;
124
136
assert_eq ! ( default_case_fold_str( "Teſt Caſe" ) , "test case" ) ;
0 commit comments