mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Rework MediaType to be an atom-based struct instead of an enum.
MozReview-Commit-ID: 1Tfrs9PBkhA
This commit is contained in:
parent
77cb5371b3
commit
557ffa979d
9 changed files with 92 additions and 72 deletions
|
@ -8,6 +8,7 @@
|
|||
|
||||
use num_traits::ToPrimitive;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::borrow::Cow;
|
||||
use std::convert::AsRef;
|
||||
use std::iter::{Filter, Peekable};
|
||||
use std::str::Split;
|
||||
|
@ -151,3 +152,13 @@ pub fn starts_with_ignore_ascii_case(string: &str, prefix: &str) -> bool {
|
|||
string.len() >= prefix.len() &&
|
||||
string.as_bytes()[0..prefix.len()].eq_ignore_ascii_case(prefix.as_bytes())
|
||||
}
|
||||
|
||||
/// Returns an ascii lowercase version of a string, only allocating if needed.
|
||||
pub fn string_as_ascii_lowercase<'a>(input: &'a str) -> Cow<'a, str> {
|
||||
if input.bytes().any(|c| matches!(c, b'A'...b'Z')) {
|
||||
input.to_ascii_lowercase().into()
|
||||
} else {
|
||||
// Already ascii lowercase.
|
||||
Cow::Borrowed(input)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue