style: Add <keyword>::from_ident helper to avoid tokenizing the same value multiple times.

This commit is contained in:
Emilio Cobos Álvarez 2017-03-26 18:11:02 +02:00
parent c2d9f663af
commit a5436e9091
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -117,7 +117,12 @@ macro_rules! __define_css_keyword_enum__actual {
/// Parse this property from a CSS input stream.
pub fn parse(input: &mut ::cssparser::Parser) -> Result<$name, ()> {
let ident = input.expect_ident()?;
match_ignore_ascii_case! { &ident,
Self::from_ident(&ident)
}
/// Parse this property from an already-tokenized identifier.
pub fn from_ident(ident: &str) -> Result<$name, ()> {
match_ignore_ascii_case! { ident,
$( $css => Ok($name::$variant), )+
_ => Err(())
}