const_str/__ctfe/
eq_ignore_ascii_case.rs1pub struct EqIgnoreAsciiCase<T1, T2>(pub T1, pub T2);
2
3const fn eq_ignore_ascii_case(lhs: &[u8], rhs: &[u8]) -> bool {
4 if lhs.len() != rhs.len() {
5 return false;
6 }
7 let mut i = 0;
8 while i < lhs.len() {
9 let l = lhs[i].to_ascii_lowercase();
10 let r = rhs[i].to_ascii_lowercase();
11 if l != r {
12 return false;
13 }
14 i += 1;
15 }
16 true
17}
18
19impl EqIgnoreAsciiCase<&[u8], &[u8]> {
20 pub const fn const_eval(&self) -> bool {
21 eq_ignore_ascii_case(self.0, self.1)
22 }
23}
24
25impl EqIgnoreAsciiCase<&str, &str> {
26 pub const fn const_eval(&self) -> bool {
27 eq_ignore_ascii_case(self.0.as_bytes(), self.1.as_bytes())
28 }
29}
30
31impl<const N1: usize, const N2: usize> EqIgnoreAsciiCase<&[u8; N1], &[u8; N2]> {
32 pub const fn const_eval(&self) -> bool {
33 eq_ignore_ascii_case(self.0.as_slice(), self.1.as_slice())
34 }
35}
36
37#[macro_export]
65macro_rules! eq_ignore_ascii_case {
66 ($lhs:expr, $rhs:expr) => {
67 $crate::__ctfe::EqIgnoreAsciiCase($lhs, $rhs).const_eval()
68 };
69}