Skip to content

Commit ea6843d

Browse files
committed
Don’t borrow $input in match_ignore_ascii_case!
Let users pass a `&foo` borrow. `&Cow<str>` can auto-deref to `&str`.
1 parent 5a17750 commit ea6843d

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ match_ignore_ascii_case! { string,
106106
}
107107
```
108108
109-
The macro also takes a slice of the value,
110-
so that a `String` or `CowString` could be passed directly instead of a `&str`.
111-
112109
*/
113110
#[macro_export]
114111
macro_rules! match_ignore_ascii_case {
@@ -125,7 +122,7 @@ macro_rules! match_ignore_ascii_case {
125122
// finished parsing
126123
(@inner $value:expr, () -> ($(($string:expr => $result:expr))*) $fallback:expr ) => {
127124
{
128-
_cssparser_internal__max_len!(&$value[..] => lowercase, $($string),+);
125+
_cssparser_internal__max_len!($value => lowercase, $($string),+);
129126
match lowercase {
130127
$(
131128
Some($string) => $result,

src/nth.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ pub fn parse_nth(input: &mut Parser) -> Result<(i32, i32), ()> {
1616
Token::Number(value) => Ok((0, try!(value.int_value.ok_or(())) as i32)),
1717
Token::Dimension(value, unit) => {
1818
let a = try!(value.int_value.ok_or(())) as i32;
19-
match_ignore_ascii_case! { unit,
19+
match_ignore_ascii_case! { &unit,
2020
"n" => parse_b(input, a),
2121
"n-" => parse_signless_b(input, a, -1),
2222
_ => Ok((a, try!(parse_n_dash_digits(&*unit))))
2323
}
2424
}
2525
Token::Ident(value) => {
26-
match_ignore_ascii_case! { value,
26+
match_ignore_ascii_case! { &value,
2727
"even" => Ok((2, 0)),
2828
"odd" => Ok((2, 1)),
2929
"n" => parse_b(input, 1),
@@ -39,7 +39,7 @@ pub fn parse_nth(input: &mut Parser) -> Result<(i32, i32), ()> {
3939
}
4040
Token::Delim('+') => match try!(input.next_including_whitespace()) {
4141
Token::Ident(value) => {
42-
match_ignore_ascii_case! { value,
42+
match_ignore_ascii_case! { &value,
4343
"n" => parse_b(input, 1),
4444
"n-" => parse_signless_b(input, 1, -1),
4545
_ => Ok((1, try!(parse_n_dash_digits(&*value))))

0 commit comments

Comments
 (0)