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
37
38
39
40
41
pub trait EqIgnoreAsciiCase {
fn eq_ignore_ascii_case_with_lowercase<S: AsRef<[u8]>>(&self, b: S) -> bool;
fn eq_ignore_ascii_case_with_uppercase<S: AsRef<[u8]>>(&self, b: S) -> bool;
}
impl<T: AsRef<[u8]>> EqIgnoreAsciiCase for T {
#[inline]
fn eq_ignore_ascii_case_with_lowercase<S: AsRef<[u8]>>(&self, b: S) -> bool {
let b = b.as_ref();
debug_assert!(!b.iter().any(|e| e.is_ascii_uppercase()));
let a = self.as_ref();
if a.len() != b.len() {
return false;
}
!a.iter().map(|e| e.to_ascii_lowercase()).zip(b.iter().copied()).any(|(ac, bc)| ac != bc)
}
#[inline]
fn eq_ignore_ascii_case_with_uppercase<S: AsRef<[u8]>>(&self, b: S) -> bool {
let b = b.as_ref();
debug_assert!(!b.iter().any(|e| e.is_ascii_lowercase()));
let a = self.as_ref();
if a.len() != b.len() {
return false;
}
!a.iter().map(|e| e.to_ascii_uppercase()).zip(b.iter().copied()).any(|(ac, bc)| ac != bc)
}
}