mirror of
https://github.com/servo/servo.git
synced 2025-07-24 07:40:27 +01:00
Add Atom::to_ascii_lowercase
This commit is contained in:
parent
75d6796cbd
commit
524fcac191
2 changed files with 37 additions and 5 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -1629,7 +1629,7 @@ dependencies = [
|
|||
"phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"string_cache 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"string_cache 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"string_cache_codegen 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tendril 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -2702,7 +2702,7 @@ dependencies = [
|
|||
name = "servo_atoms"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"string_cache 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"string_cache 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"string_cache_codegen 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -2851,7 +2851,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "string_cache"
|
||||
version = "0.5.1"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"debug_unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -3738,7 +3738,7 @@ dependencies = [
|
|||
"checksum skeptic 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dd7d8dc1315094150052d0ab767840376335a98ac66ef313ff911cdf439a5b69"
|
||||
"checksum slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b4fcaed89ab08ef143da37bc52adbcc04d4a69014f4c1208d6b51f0c47bc23"
|
||||
"checksum smallvec 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e40af10aafe98b4d8294ae8388d8a5cd0707c65d364872efe72d063ec44bee0"
|
||||
"checksum string_cache 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2c77392ab481a7b315078ae0cbfd827c7fcd7b0840235f0f9c24d8c7443593b5"
|
||||
"checksum string_cache 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e7c8ba7515dd502b75080d989b819d31fb72686a82320d8006f665003c42ef79"
|
||||
"checksum string_cache_codegen 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "479cde50c3539481f33906a387f2bd17c8e87cb848c35b6021d41fb81ff9b4d7"
|
||||
"checksum string_cache_shared 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b1884d1bc09741d466d9b14e6d37ac89d6909cbcac41dd9ae982d4d063bbedfc"
|
||||
"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694"
|
||||
|
|
|
@ -11,7 +11,7 @@ use gecko_bindings::bindings::Gecko_Atomize;
|
|||
use gecko_bindings::bindings::Gecko_Atomize16;
|
||||
use gecko_bindings::bindings::Gecko_ReleaseAtom;
|
||||
use gecko_bindings::structs::nsIAtom;
|
||||
use nsstring::nsAString;
|
||||
use nsstring::{nsAString, nsString};
|
||||
use precomputed_hash::PrecomputedHash;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::borrow::{Cow, Borrow};
|
||||
|
@ -176,6 +176,31 @@ impl WeakAtom {
|
|||
let const_ptr: *const nsIAtom = &self.0;
|
||||
const_ptr as *mut nsIAtom
|
||||
}
|
||||
|
||||
/// Convert this atom to ASCII lower-case
|
||||
pub fn to_ascii_lowercase(&self) -> Atom {
|
||||
let slice = self.as_slice();
|
||||
match slice.iter().position(|&char16| (b'A' as u16) <= char16 && char16 <= (b'Z' as u16)) {
|
||||
None => self.clone(),
|
||||
Some(i) => {
|
||||
let mut buffer: [u16; 64] = unsafe { mem::uninitialized() };
|
||||
let mut vec;
|
||||
let mutable_slice = if let Some(buffer_prefix) = buffer.get_mut(..slice.len()) {
|
||||
buffer_prefix.copy_from_slice(slice);
|
||||
buffer_prefix
|
||||
} else {
|
||||
vec = slice.to_vec();
|
||||
&mut vec
|
||||
};
|
||||
for char16 in &mut mutable_slice[i..] {
|
||||
if *char16 <= 0x7F {
|
||||
*char16 = (*char16 as u8).to_ascii_lowercase() as u16
|
||||
}
|
||||
}
|
||||
Atom::from(&*mutable_slice)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for WeakAtom {
|
||||
|
@ -321,6 +346,13 @@ impl<'a> From<&'a str> for Atom {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a [u16]> for Atom {
|
||||
#[inline]
|
||||
fn from(slice: &[u16]) -> Atom {
|
||||
Atom::from(&*nsString::from(slice))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a nsAString> for Atom {
|
||||
#[inline]
|
||||
fn from(string: &nsAString) -> Atom {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue