mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Use AsciiExt in ByteString implementations.
This commit is contained in:
parent
5f6b791e62
commit
bd77acfbb8
1 changed files with 3 additions and 10 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
//! The `ByteString` struct.
|
//! The `ByteString` struct.
|
||||||
|
|
||||||
|
use std::ascii::AsciiExt;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::ops;
|
use std::ops;
|
||||||
|
@ -36,20 +37,12 @@ impl ByteString {
|
||||||
|
|
||||||
/// Compare `self` to `other`, matching A–Z and a–z as equal.
|
/// Compare `self` to `other`, matching A–Z and a–z as equal.
|
||||||
pub fn eq_ignore_case(&self, other: &ByteString) -> bool {
|
pub fn eq_ignore_case(&self, other: &ByteString) -> bool {
|
||||||
// XXXManishearth make this more efficient
|
self.0.eq_ignore_ascii_case(&other.0)
|
||||||
self.to_lower() == other.to_lower()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `self` with A–Z replaced by a–z.
|
/// Returns `self` with A–Z replaced by a–z.
|
||||||
pub fn to_lower(&self) -> ByteString {
|
pub fn to_lower(&self) -> ByteString {
|
||||||
let ByteString(ref vec) = *self;
|
ByteString::new(self.0.to_ascii_lowercase())
|
||||||
ByteString::new(vec.iter().map(|&x| {
|
|
||||||
if x > 'A' as u8 && x < 'Z' as u8 {
|
|
||||||
x + ('a' as u8) - ('A' as u8)
|
|
||||||
} else {
|
|
||||||
x
|
|
||||||
}
|
|
||||||
}).collect())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether `self` is a `token`, as defined by
|
/// Returns whether `self` is a `token`, as defined by
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue