pub trait BytesExt {
fn matches_special_lowercase<B: AsRef<[u8]>>(self, other: B) -> bool;
}
fn matches_special_lowercase_imp(a: &[u8], b: &[u8]) -> bool {
a.len() == b.len() && a.iter().zip(b).all(|(&a, &b)| { a | 0b100000 == b })
}
impl BytesExt for &[u8] {
fn matches_special_lowercase<B: AsRef<[u8]>>(self, other: B) -> bool {
matches_special_lowercase_imp(self.as_ref(), other.as_ref())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn matches_special_lowercase() {
let cases = [
(["ocean.toml", "ocean.toml"], true),
(["OCEAN.toMl", "ocean.toml"], true),
(["ocean.toml", "OCEAN.toml"], false),
(["ocean.tom", "ocean.toml"], false),
];
for &([a, b], cond) in cases.iter() {
assert_eq!(a.as_bytes().matches_special_lowercase(b), cond);
}
}
}