mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Make starts_with_ignore_ascii_case not lie if the strings are the same length.
This commit is contained in:
parent
d8a22d8bd7
commit
9e00efc8a5
2 changed files with 7 additions and 1 deletions
|
@ -148,6 +148,6 @@ pub fn str_join<I, T>(strs: I, join: &str) -> String
|
||||||
|
|
||||||
/// Returns true if a given string has a given prefix with case-insensitive match.
|
/// Returns true if a given string has a given prefix with case-insensitive match.
|
||||||
pub fn starts_with_ignore_ascii_case(string: &str, prefix: &str) -> bool {
|
pub fn starts_with_ignore_ascii_case(string: &str, prefix: &str) -> bool {
|
||||||
string.len() > prefix.len() &&
|
string.len() >= prefix.len() &&
|
||||||
string.as_bytes()[0..prefix.len()].eq_ignore_ascii_case(prefix.as_bytes())
|
string.as_bytes()[0..prefix.len()].eq_ignore_ascii_case(prefix.as_bytes())
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,12 @@ pub fn test_str_join_many() {
|
||||||
assert_eq!(actual, expected);
|
assert_eq!(actual, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
pub fn test_starts_with_ignore_ascii_case_basic() {
|
||||||
|
assert!(starts_with_ignore_ascii_case("-webkit-", "-webkit-"));
|
||||||
|
assert!(starts_with_ignore_ascii_case("-webkit-foo", "-webkit-"));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_starts_with_ignore_ascii_case_char_boundary() {
|
pub fn test_starts_with_ignore_ascii_case_char_boundary() {
|
||||||
assert!(!starts_with_ignore_ascii_case("aaaaa💩", "-webkit-"));
|
assert!(!starts_with_ignore_ascii_case("aaaaa💩", "-webkit-"));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue