mirror of
https://github.com/servo/servo.git
synced 2025-06-11 01:50:10 +00:00
Add a match_ignore_ascii_case! macro that does not allocate.
It should replace `match foo.to_ascii_lower().as_slice() { ...}` @Manishearth I changed map.get to map.find in the lint to work around an ICE: task 'rustc' panicked at 'couldn't find node id 0 in the AST map' Does this look OK?
This commit is contained in:
parent
540d218885
commit
2e35d4e987
6 changed files with 34 additions and 12 deletions
|
@ -65,11 +65,10 @@ macro_rules! define_css_keyword_enum {
|
|||
|
||||
impl $name {
|
||||
pub fn parse(component_value: &::cssparser::ast::ComponentValue) -> Result<$name, ()> {
|
||||
use std::ascii::AsciiExt;
|
||||
match component_value {
|
||||
&::cssparser::ast::Ident(ref value) => {
|
||||
match value.to_ascii_lower().as_slice() {
|
||||
$( concat!($css) => Ok($name::$variant), )+
|
||||
match_ignore_ascii_case! { value:
|
||||
$( $css => Ok($name::$variant) ),+
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
|
@ -96,3 +95,23 @@ macro_rules! define_css_keyword_enum {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! match_ignore_ascii_case {
|
||||
( $value: expr: $( $string: expr => $result: expr ),+ _ => $fallback: expr, ) => {
|
||||
match_ignore_ascii_case! { $value:
|
||||
$( $string => $result ),+
|
||||
_ => $fallback
|
||||
}
|
||||
};
|
||||
( $value: expr: $( $string: expr => $result: expr ),+ _ => $fallback: expr ) => {
|
||||
{
|
||||
use std::ascii::AsciiExt;
|
||||
match $value.as_slice() {
|
||||
$( s if s.eq_ignore_ascii_case($string) => $result, )+
|
||||
_ => $fallback
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue