|
| 1 | +/// Returns `true` if `s` starts with `prefix`, ignoring ASCII case differences |
| 2 | +pub fn starts_with_ignore_ascii_case(s: &str, prefix: &str) -> bool { |
| 3 | + s.get(..prefix.len()) |
| 4 | + .is_some_and(|t| prefix.eq_ignore_ascii_case(t)) |
| 5 | +} |
| 6 | + |
| 7 | +#[cfg(test)] |
| 8 | +mod tests { |
| 9 | + use super::*; |
| 10 | + use rstest::rstest; |
| 11 | + |
| 12 | + #[rstest] |
| 13 | + #[case("Hello, World!", "hello", true)] |
| 14 | + #[case("Hello, World!", "HELLO", true)] |
| 15 | + #[case("hello, world!", "HELLO", true)] |
| 16 | + #[case("hello", "hello world", false)] |
| 17 | + #[case("Hellö, World!", "hello", false)] |
| 18 | + #[case("Hello, Wörld!", "hello", true)] |
| 19 | + #[case("", "hello", false)] |
| 20 | + #[case("Holla, World!", "hello", false)] |
| 21 | + #[case("Hello", "hello", true)] |
| 22 | + #[case("Hell", "hello", false)] |
| 23 | + fn test(#[case] s: &str, #[case] prefix: &str, #[case] r: bool) { |
| 24 | + assert_eq!(starts_with_ignore_ascii_case(s, prefix), r); |
| 25 | + } |
| 26 | +} |
0 commit comments