aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/gecko_string_cache/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/style/gecko_string_cache/mod.rs')
-rw-r--r--components/style/gecko_string_cache/mod.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/components/style/gecko_string_cache/mod.rs b/components/style/gecko_string_cache/mod.rs
index b612c027c45..63ba6d7977c 100644
--- a/components/style/gecko_string_cache/mod.rs
+++ b/components/style/gecko_string_cache/mod.rs
@@ -13,6 +13,7 @@ use gecko_bindings::bindings::Gecko_ReleaseAtom;
use gecko_bindings::structs::nsIAtom;
use nsstring::nsAString;
use precomputed_hash::PrecomputedHash;
+use std::ascii::AsciiExt;
use std::borrow::{Cow, Borrow};
use std::char::{self, DecodeUtf16};
use std::fmt::{self, Write};
@@ -224,6 +225,25 @@ impl Atom {
Atom(WeakAtom::new(ptr))
}
}
+
+ /// Return whether two atoms are ASCII-case-insensitive matches
+ pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool {
+ let a = self.as_slice();
+ let b = other.as_slice();
+ a.len() == b.len() && a.iter().zip(b).all(|(&a16, &b16)| {
+ if a16 <= 0x7F && b16 <= 0x7F {
+ (a16 as u8).eq_ignore_ascii_case(&(b16 as u8))
+ } else {
+ a16 == b16
+ }
+ })
+ }
+
+ /// Return whether this atom is an ASCII-case-insensitive match for the given string
+ pub fn eq_str_ignore_ascii_case(&self, other: &str) -> bool {
+ self.chars().map(|r| r.map(|c: char| c.to_ascii_lowercase()))
+ .eq(other.chars().map(|c: char| Ok(c.to_ascii_lowercase())))
+ }
}
impl Hash for Atom {