style: Simplify CSSWideKeyword::parse.

Differential Revision: https://phabricator.services.mozilla.com/D5972
This commit is contained in:
Emilio Cobos Álvarez 2018-09-17 00:53:37 +00:00
parent 72ce653daf
commit bc39f16b4b
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -853,25 +853,22 @@ impl CSSWideKeyword {
CSSWideKeyword::Unset => "unset", CSSWideKeyword::Unset => "unset",
} }
} }
/// Takes the result of cssparser::Parser::expect_ident() and converts it
/// to a CSSWideKeyword.
pub fn from_ident<'i>(ident: &str) -> Option<Self> {
match_ignore_ascii_case! { ident,
// If modifying this set of keyword, also update values::CustomIdent::from_ident
"initial" => Some(CSSWideKeyword::Initial),
"inherit" => Some(CSSWideKeyword::Inherit),
"unset" => Some(CSSWideKeyword::Unset),
_ => None
}
}
} }
impl CSSWideKeyword { impl CSSWideKeyword {
fn parse(input: &mut Parser) -> Result<Self, ()> { fn parse(input: &mut Parser) -> Result<Self, ()> {
let ident = input.expect_ident().map_err(|_| ())?.clone(); let keyword = {
let ident = input.expect_ident().map_err(|_| ())?;
match_ignore_ascii_case! { ident,
// If modifying this set of keyword, also update values::CustomIdent::from_ident
"initial" => CSSWideKeyword::Initial,
"inherit" => CSSWideKeyword::Inherit,
"unset" => CSSWideKeyword::Unset,
_ => return Err(()),
}
};
input.expect_exhausted().map_err(|_| ())?; input.expect_exhausted().map_err(|_| ())?;
CSSWideKeyword::from_ident(&ident).ok_or(()) Ok(keyword)
} }
} }