Last active
April 3, 2024 20:16
-
-
Save juliarose/875a43724c966a101a7063d11790fa96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A possibly more efficient way to match pluralized strings case-insensitively. | |
// For example matching "burgers" and "burger" with fewer iterations. | |
// Untested | |
fn eq_ignore_ascii_case_with_tail(mut lhs: &str, rhs: &str, tail: char) -> bool { | |
let mut lhs_len = lhs.len(); | |
let rhs_len = rhs.len(); | |
if lhs_len == rhs_len + 1 && lhs.ends_with(tail) { | |
lhs = &lhs[..lhs_len - 1]; | |
lhs_len -= 1; | |
} | |
if lhs_len != rhs_len { | |
return false; | |
} | |
std::iter::zip(lhs.as_bytes(), rhs.as_bytes()).all(|(a, b)| a.eq_ignore_ascii_case(b)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment