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:
Simon Sapin 2014-12-21 11:17:53 +00:00
parent 540d218885
commit 2e35d4e987
6 changed files with 34 additions and 12 deletions

View file

@ -7,6 +7,9 @@ authors = ["The Servo Project Developers"]
name = "util"
path = "lib.rs"
[dependencies.plugins]
path = "../plugins"
[dependencies.cssparser]
git = "https://github.com/servo/rust-cssparser"

View file

@ -19,8 +19,8 @@ macro_rules! define_cursor {
impl Cursor {
pub fn from_css_keyword(keyword: &str) -> Result<Cursor, ()> {
match keyword.to_ascii_lower().as_slice() {
$( concat!($css) => Ok(Cursor::$variant), )+
match_ignore_ascii_case! { keyword:
$( concat!($css) => Ok(Cursor::$variant) ),+
_ => Err(())
}
}

View file

@ -31,10 +31,9 @@ extern crate string_cache;
extern crate unicode;
extern crate url;
#[phase(plugin)]
extern crate string_cache_macros;
#[phase(plugin)]
extern crate lazy_static;
#[phase(plugin)] extern crate plugins;
#[phase(plugin)] extern crate string_cache_macros;
#[phase(plugin)] extern crate lazy_static;
use std::sync::Arc;