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" ) ) ;
6
10
7
11
12
+ #[ cfg( feature = "normalization" ) ]
8
13
pub trait Caseless {
9
14
fn default_case_fold ( self ) -> CaseFold < Self > where Self : Sized ;
10
15
fn default_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool ;
11
16
fn canonical_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool ;
12
17
fn compatibility_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool ;
13
18
}
14
19
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
+
15
29
impl < I : Iterator < Item =char > > Caseless for I {
16
30
fn default_case_fold ( self ) -> CaseFold < I > {
17
31
CaseFold {
@@ -25,6 +39,7 @@ impl<I: Iterator<Item=char>> Caseless for I {
25
39
other. default_case_fold ( ) )
26
40
}
27
41
42
+ #[ cfg( feature = "normalization" ) ]
28
43
fn canonical_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool {
29
44
// FIXME: Inner NFD can be optimized:
30
45
// "Normalization is not required before case folding,
@@ -39,6 +54,7 @@ impl<I: Iterator<Item=char>> Caseless for I {
39
54
other. nfd ( ) . default_case_fold ( ) . nfd ( ) )
40
55
}
41
56
57
+ #[ cfg( feature = "normalization" ) ]
42
58
fn compatibility_caseless_match < J : Iterator < Item =char > > ( self , other : J ) -> bool {
43
59
// FIXME: Unclear if the inner NFD can be optimized here like in canonical_caseless_match.
44
60
iter_eq ( self . nfd ( ) . default_case_fold ( ) . nfkd ( ) . default_case_fold ( ) . nfkd ( ) ,
@@ -47,6 +63,7 @@ impl<I: Iterator<Item=char>> Caseless for I {
47
63
48
64
}
49
65
66
+ #[ cfg( feature = "alloc" ) ]
50
67
pub fn default_case_fold_str ( s : & str ) -> String {
51
68
s. chars ( ) . default_case_fold ( ) . collect ( )
52
69
}
@@ -55,10 +72,12 @@ pub fn default_caseless_match_str(a: &str, b: &str) -> bool {
55
72
a. chars ( ) . default_caseless_match ( b. chars ( ) )
56
73
}
57
74
75
+ #[ cfg( feature = "normalization" ) ]
58
76
pub fn canonical_caseless_match_str ( a : & str , b : & str ) -> bool {
59
77
a. chars ( ) . canonical_caseless_match ( b. chars ( ) )
60
78
}
61
79
80
+ #[ cfg( feature = "normalization" ) ]
62
81
pub fn compatibility_caseless_match_str ( a : & str , b : & str ) -> bool {
63
82
a. chars ( ) . compatibility_caseless_match ( b. chars ( ) )
64
83
}
@@ -116,9 +135,10 @@ impl<I> Iterator for CaseFold<I> where I: Iterator<Item = char> {
116
135
117
136
#[ cfg( test) ]
118
137
mod tests {
119
- use super :: default_case_fold_str ;
138
+ use super :: * ;
120
139
121
140
#[ test]
141
+ #[ cfg( feature = "alloc" ) ]
122
142
fn test_strs ( ) {
123
143
assert_eq ! ( default_case_fold_str( "Test Case" ) , "test case" ) ;
124
144
assert_eq ! ( default_case_fold_str( "Teſt Caſe" ) , "test case" ) ;
0 commit comments