@@ -35,7 +35,7 @@ pub fn next_component_value(parser: &mut Parser) -> Option<ComponentValue> {
35
35
let c = parser. current_char ( ) ;
36
36
Some ( match c {
37
37
'-' => {
38
- if parser. starts_with ( ~ "-->") {
38
+ if parser. starts_with ( "-->" ) {
39
39
parser. position += 3 ;
40
40
CDC
41
41
}
@@ -46,7 +46,7 @@ pub fn next_component_value(parser: &mut Parser) -> Option<ComponentValue> {
46
46
}
47
47
} ,
48
48
'<' => {
49
- if parser.starts_with(~ " <!--") {
49
+ if parser. starts_with ( "<!--" ) {
50
50
parser. position += 4 ;
51
51
CDO
52
52
} else {
@@ -57,6 +57,12 @@ pub fn next_component_value(parser: &mut Parser) -> Option<ComponentValue> {
57
57
'0' ..'9' | '.' | '+' => consume_numeric ( parser) ,
58
58
'u' | 'U' => consume_unicode_range ( parser) ,
59
59
'a' ..'z' | 'A' ..'Z' | '_' | '\\' => consume_ident ( parser) ,
60
+ '~' if parser. starts_with ( "~=" ) => { parser. position += 2 ; IncludeMath }
61
+ '|' if parser. starts_with ( "|=" ) => { parser. position += 2 ; DashMatch }
62
+ '^' if parser. starts_with ( "^=" ) => { parser. position += 2 ; PrefixMatch }
63
+ '$' if parser. starts_with ( "$=" ) => { parser. position += 2 ; SuffixMatch }
64
+ '*' if parser. starts_with ( "*=" ) => { parser. position += 2 ; SubstringMatch }
65
+ '|' if parser. starts_with ( "||" ) => { parser. position += 2 ; Column }
60
66
_ if c >= '\x80' => consume_ident ( parser) , // Non-ASCII
61
67
_ => {
62
68
match parser. consume_char ( ) {
@@ -82,18 +88,6 @@ pub fn next_component_value(parser: &mut Parser) -> Option<ComponentValue> {
82
88
']' => CloseSquareBraket ,
83
89
'{' => CurlyBraketBlock ( consume_block ( parser, CloseCurlyBraket ) ) ,
84
90
'}' => CloseCurlyBraket ,
85
- '~' if !parser. is_eof ( ) && parser. current_char ( ) == '='
86
- => { parser. position += 1 ; IncludeMath }
87
- ' |' if !parser. is_eof ( ) && parser. current_char ( ) == '='
88
- => { parser. position += 1 ; DashMatch }
89
- ' |' if !parser. is_eof ( ) && parser. current_char ( ) == '|'
90
- => { parser. position += 1 ; Column }
91
- ' ^' if !parser. is_eof ( ) && parser. current_char ( ) == '='
92
- => { parser. position += 1 ; PrefixMatch }
93
- ' $' if !parser. is_eof ( ) && parser. current_char ( ) == '='
94
- => { parser. position += 1 ; SuffixMatch }
95
- ' * ' if !parser. is_eof ( ) && parser. current_char ( ) == '='
96
- => { parser. position += 1 ; SubstringMatch }
97
91
_ => Delim ( c)
98
92
}
99
93
}
@@ -170,20 +164,15 @@ impl Parser {
170
164
}
171
165
172
166
#[ inline]
173
- fn starts_with( & self , needle: ~str ) -> bool {
174
- // XXX Duplicate str::match_at which is not public.
175
- let mut i = self . position;
176
- if i + needle. len( ) > self . length { return false }
177
- let haystack: & str = self . input;
178
- for needle. bytes_iter( ) . advance |c| { if haystack[ i] != c { return false; } i += 1 u; }
179
- return true ;
167
+ fn starts_with( & self , needle: & str) -> bool {
168
+ self . input. slice_from( self . position) . starts_with( needle)
180
169
}
181
170
}
182
171
183
172
184
173
#[ inline]
185
174
fn consume_comments( parser: & mut Parser ) {
186
- while parser. starts_with( ~ "/* ") {
175
+ while parser. starts_with( "/*" ) {
187
176
parser. position += 2 ; // +2 to consume "/*"
188
177
match parser. input. slice_from( parser. position) . find_str( "*/" ) {
189
178
// +2 to consume "*/"
@@ -215,7 +204,7 @@ macro_rules! is_match(
215
204
216
205
#[ inline]
217
206
fn is_invalid_escape( parser: & mut Parser ) -> bool {
218
- parser. next_n_chars ( 2 ) == ~ [ '\\' , '\n' ]
207
+ parser. starts_with ( " \\ \n " )
219
208
}
220
209
221
210
@@ -249,11 +238,11 @@ fn consume_quoted_string(parser: &mut Parser, single_quote: bool) -> ComponentVa
249
238
return BadString ;
250
239
} ,
251
240
'\\' => {
252
- match parser. next_n_chars( 1 ) {
253
- [ '\n' ] => parser. position += 1 , // Escaped newline
254
- [ ] => ( ) , // Escaped EOF
255
- _ => string. push_char( consume_escape( parser) )
241
+ if !parser. is_eof( ) {
242
+ if parser. current_char( ) == '\n' { parser. position += 1 } // Escaped newline
243
+ else { string. push_char( consume_escape( parser) ) }
256
244
}
245
+ // else: escaped EOF, do nothing.
257
246
}
258
247
c => string. push_char( c) ,
259
248
}
@@ -514,9 +503,11 @@ fn consume_unquoted_url(parser: &mut Parser) -> ComponentValue {
514
503
')' => break ,
515
504
'\x00' ..'\x08' | '\x0B' | '\x0E' ..'\x1F' | '\x7F' // non-printable
516
505
| '"' | '\'' | '(' => return consume_bad_url( parser) ,
517
- '\\' => match parser. next_n_chars( 1 ) {
518
- [ '\n' ] => return consume_bad_url( parser) ,
519
- _ => consume_escape( parser)
506
+ '\\' => {
507
+ if !parser. is_eof( ) && parser. current_char( ) == '\n' {
508
+ return consume_bad_url( parser)
509
+ }
510
+ consume_escape( parser)
520
511
} ,
521
512
c => c
522
513
} ;
0 commit comments