Use ascii_case_insensitive_phf_map! in PropertyId::parse

This commit is contained in:
Simon Sapin 2017-02-25 19:00:29 +01:00
parent 33ef6f78e5
commit 2f996e34f5
7 changed files with 21 additions and 69 deletions

View file

@ -7,8 +7,6 @@
#![deny(missing_docs)]
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;
@ -146,12 +144,3 @@ pub fn str_join<I, T>(strs: I, join: &str) -> String
acc
})
}
/// Like AsciiExt::to_ascii_lowercase, but avoids allocating when the input is already lower-case.
pub fn cow_into_ascii_lowercase<'a, S: Into<Cow<'a, str>>>(s: S) -> Cow<'a, str> {
let mut cow = s.into();
if let Some(first_uppercase) = cow.bytes().position(|byte| byte >= b'A' && byte <= b'Z') {
cow.to_mut()[first_uppercase..].make_ascii_lowercase();
}
cow
}