Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/css/parser/CSSTokenizer.h" | 5 #include "core/css/parser/CSSTokenizer.h" |
| 6 | 6 |
| 7 namespace blink { | 7 namespace blink { |
| 8 #include "core/CSSTokenizerCodepoints.cpp" | 8 #include "core/CSSTokenizerCodepoints.cpp" |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 m_input.pushBack(c); | 107 m_input.pushBack(c); |
| 108 } | 108 } |
| 109 | 109 |
| 110 UChar CSSTokenizer::consume() | 110 UChar CSSTokenizer::consume() |
| 111 { | 111 { |
| 112 UChar current = m_input.nextInputChar(); | 112 UChar current = m_input.nextInputChar(); |
| 113 m_input.advance(); | 113 m_input.advance(); |
| 114 return current; | 114 return current; |
| 115 } | 115 } |
| 116 | 116 |
| 117 void CSSTokenizer::consume(unsigned offset) | |
|
esprehn
2016/06/27 21:46:29
This is confusing, but there was actually two meth
| |
| 118 { | |
| 119 m_input.advance(offset); | |
| 120 } | |
| 121 | |
| 122 CSSParserToken CSSTokenizer::whiteSpace(UChar cc) | 117 CSSParserToken CSSTokenizer::whiteSpace(UChar cc) |
| 123 { | 118 { |
| 124 m_input.advanceUntilNonWhitespace(); | 119 m_input.advanceUntilNonWhitespace(); |
| 125 return CSSParserToken(WhitespaceToken); | 120 return CSSParserToken(WhitespaceToken); |
| 126 } | 121 } |
| 127 | 122 |
| 128 static bool popIfBlockMatches(Vector<CSSParserTokenType>& blockStack, CSSParserT okenType type) | 123 static bool popIfBlockMatches(Vector<CSSParserTokenType>& blockStack, CSSParserT okenType type) |
| 129 { | 124 { |
| 130 if (!blockStack.isEmpty() && blockStack.last() == type) { | 125 if (!blockStack.isEmpty() && blockStack.last() == type) { |
| 131 blockStack.removeLast(); | 126 blockStack.removeLast(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 ASSERT(cc == '*'); | 192 ASSERT(cc == '*'); |
| 198 if (consumeIfNext('=')) | 193 if (consumeIfNext('=')) |
| 199 return CSSParserToken(SubstringMatchToken); | 194 return CSSParserToken(SubstringMatchToken); |
| 200 return CSSParserToken(DelimiterToken, '*'); | 195 return CSSParserToken(DelimiterToken, '*'); |
| 201 } | 196 } |
| 202 | 197 |
| 203 CSSParserToken CSSTokenizer::lessThan(UChar cc) | 198 CSSParserToken CSSTokenizer::lessThan(UChar cc) |
| 204 { | 199 { |
| 205 ASSERT(cc == '<'); | 200 ASSERT(cc == '<'); |
| 206 if (m_input.peek(0) == '!' && m_input.peek(1) == '-' && m_input.peek(2) == ' -') { | 201 if (m_input.peek(0) == '!' && m_input.peek(1) == '-' && m_input.peek(2) == ' -') { |
| 207 consume(3); | 202 m_input.advance(3); |
| 208 return CSSParserToken(CDOToken); | 203 return CSSParserToken(CDOToken); |
| 209 } | 204 } |
| 210 return CSSParserToken(DelimiterToken, '<'); | 205 return CSSParserToken(DelimiterToken, '<'); |
| 211 } | 206 } |
| 212 | 207 |
| 213 CSSParserToken CSSTokenizer::comma(UChar cc) | 208 CSSParserToken CSSTokenizer::comma(UChar cc) |
| 214 { | 209 { |
| 215 return CSSParserToken(CommaToken); | 210 return CSSParserToken(CommaToken); |
| 216 } | 211 } |
| 217 | 212 |
| 218 CSSParserToken CSSTokenizer::hyphenMinus(UChar cc) | 213 CSSParserToken CSSTokenizer::hyphenMinus(UChar cc) |
| 219 { | 214 { |
| 220 if (nextCharsAreNumber(cc)) { | 215 if (nextCharsAreNumber(cc)) { |
| 221 reconsume(cc); | 216 reconsume(cc); |
| 222 return consumeNumericToken(); | 217 return consumeNumericToken(); |
| 223 } | 218 } |
| 224 if (m_input.peek(0) == '-' && m_input.peek(1) == '>') { | 219 if (m_input.peek(0) == '-' && m_input.peek(1) == '>') { |
| 225 consume(2); | 220 m_input.advance(2); |
| 226 return CSSParserToken(CDCToken); | 221 return CSSParserToken(CDCToken); |
| 227 } | 222 } |
| 228 if (nextCharsAreIdentifier(cc)) { | 223 if (nextCharsAreIdentifier(cc)) { |
| 229 reconsume(cc); | 224 reconsume(cc); |
| 230 return consumeIdentLikeToken(); | 225 return consumeIdentLikeToken(); |
| 231 } | 226 } |
| 232 return CSSParserToken(DelimiterToken, cc); | 227 return CSSParserToken(DelimiterToken, cc); |
| 233 } | 228 } |
| 234 | 229 |
| 235 CSSParserToken CSSTokenizer::solidus(UChar cc) | 230 CSSParserToken CSSTokenizer::solidus(UChar cc) |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 CSSParserToken CSSTokenizer::asciiDigit(UChar cc) | 313 CSSParserToken CSSTokenizer::asciiDigit(UChar cc) |
| 319 { | 314 { |
| 320 reconsume(cc); | 315 reconsume(cc); |
| 321 return consumeNumericToken(); | 316 return consumeNumericToken(); |
| 322 } | 317 } |
| 323 | 318 |
| 324 CSSParserToken CSSTokenizer::letterU(UChar cc) | 319 CSSParserToken CSSTokenizer::letterU(UChar cc) |
| 325 { | 320 { |
| 326 if (m_input.nextInputChar() == '+' | 321 if (m_input.nextInputChar() == '+' |
| 327 && (isASCIIHexDigit(m_input.peek(1)) || m_input.peek(1) == '?')) { | 322 && (isASCIIHexDigit(m_input.peek(1)) || m_input.peek(1) == '?')) { |
| 328 consume(); | 323 m_input.advance(); |
| 329 return consumeUnicodeRange(); | 324 return consumeUnicodeRange(); |
| 330 } | 325 } |
| 331 reconsume(cc); | 326 reconsume(cc); |
| 332 return consumeIdentLikeToken(); | 327 return consumeIdentLikeToken(); |
| 333 } | 328 } |
| 334 | 329 |
| 335 CSSParserToken CSSTokenizer::nameStart(UChar cc) | 330 CSSParserToken CSSTokenizer::nameStart(UChar cc) |
| 336 { | 331 { |
| 337 reconsume(cc); | 332 reconsume(cc); |
| 338 return consumeIdentLikeToken(); | 333 return consumeIdentLikeToken(); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 } | 529 } |
| 535 | 530 |
| 536 UChar32 end = start; | 531 UChar32 end = start; |
| 537 if (lengthRemaining && consumeIfNext('?')) { | 532 if (lengthRemaining && consumeIfNext('?')) { |
| 538 do { | 533 do { |
| 539 start *= 16; | 534 start *= 16; |
| 540 end = end * 16 + 0xF; | 535 end = end * 16 + 0xF; |
| 541 --lengthRemaining; | 536 --lengthRemaining; |
| 542 } while (lengthRemaining && consumeIfNext('?')); | 537 } while (lengthRemaining && consumeIfNext('?')); |
| 543 } else if (m_input.nextInputChar() == '-' && isASCIIHexDigit(m_input.peek(1) )) { | 538 } else if (m_input.nextInputChar() == '-' && isASCIIHexDigit(m_input.peek(1) )) { |
| 544 consume(); | 539 m_input.advance(); |
| 545 lengthRemaining = 6; | 540 lengthRemaining = 6; |
| 546 end = 0; | 541 end = 0; |
| 547 do { | 542 do { |
| 548 end = end * 16 + toASCIIHexValue(consume()); | 543 end = end * 16 + toASCIIHexValue(consume()); |
| 549 --lengthRemaining; | 544 --lengthRemaining; |
| 550 } while (lengthRemaining && isASCIIHexDigit(m_input.nextInputChar())); | 545 } while (lengthRemaining && isASCIIHexDigit(m_input.nextInputChar())); |
| 551 } | 546 } |
| 552 | 547 |
| 553 return CSSParserToken(UnicodeRangeToken, start, end); | 548 return CSSParserToken(UnicodeRangeToken, start, end); |
| 554 } | 549 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 if (twoCharsAreValidEscape(cc, m_input.nextInputChar())) | 612 if (twoCharsAreValidEscape(cc, m_input.nextInputChar())) |
| 618 consumeEscape(); | 613 consumeEscape(); |
| 619 } | 614 } |
| 620 } | 615 } |
| 621 | 616 |
| 622 void CSSTokenizer::consumeSingleWhitespaceIfNext() | 617 void CSSTokenizer::consumeSingleWhitespaceIfNext() |
| 623 { | 618 { |
| 624 // We check for \r\n and HTML spaces since we don't do preprocessing | 619 // We check for \r\n and HTML spaces since we don't do preprocessing |
| 625 UChar c = m_input.nextInputChar(); | 620 UChar c = m_input.nextInputChar(); |
| 626 if (c == '\r' && m_input.peek(1) == '\n') | 621 if (c == '\r' && m_input.peek(1) == '\n') |
| 627 consume(2); | 622 m_input.advance(2); |
| 628 else if (isHTMLSpace(c)) | 623 else if (isHTMLSpace(c)) |
| 629 consume(); | 624 m_input.advance(); |
| 630 } | 625 } |
| 631 | 626 |
| 632 void CSSTokenizer::consumeUntilCommentEndFound() | 627 void CSSTokenizer::consumeUntilCommentEndFound() |
| 633 { | 628 { |
| 634 UChar c = consume(); | 629 UChar c = consume(); |
| 635 while (true) { | 630 while (true) { |
| 636 if (c == kEndOfFileMarker) | 631 if (c == kEndOfFileMarker) |
| 637 return; | 632 return; |
| 638 if (c != '*') { | 633 if (c != '*') { |
| 639 c = consume(); | 634 c = consume(); |
| 640 continue; | 635 continue; |
| 641 } | 636 } |
| 642 c = consume(); | 637 c = consume(); |
| 643 if (c == '/') | 638 if (c == '/') |
| 644 return; | 639 return; |
| 645 } | 640 } |
| 646 } | 641 } |
| 647 | 642 |
| 648 bool CSSTokenizer::consumeIfNext(UChar character) | 643 bool CSSTokenizer::consumeIfNext(UChar character) |
| 649 { | 644 { |
| 650 if (m_input.nextInputChar() == character) { | 645 if (m_input.nextInputChar() == character) { |
| 651 consume(); | 646 m_input.advance(); |
| 652 return true; | 647 return true; |
| 653 } | 648 } |
| 654 return false; | 649 return false; |
| 655 } | 650 } |
| 656 | 651 |
| 657 // http://www.w3.org/TR/css3-syntax/#consume-a-name | 652 // http://www.w3.org/TR/css3-syntax/#consume-a-name |
| 658 StringView CSSTokenizer::consumeName() | 653 StringView CSSTokenizer::consumeName() |
| 659 { | 654 { |
| 660 // Names without escapes get handled without allocations | 655 // Names without escapes get handled without allocations |
| 661 for (unsigned size = 0; ; ++size) { | 656 for (unsigned size = 0; ; ++size) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 765 return areIdentifier; | 760 return areIdentifier; |
| 766 } | 761 } |
| 767 | 762 |
| 768 StringView CSSTokenizer::registerString(const String& string) | 763 StringView CSSTokenizer::registerString(const String& string) |
| 769 { | 764 { |
| 770 m_scope.storeString(string); | 765 m_scope.storeString(string); |
| 771 return string; | 766 return string; |
| 772 } | 767 } |
| 773 | 768 |
| 774 } // namespace blink | 769 } // namespace blink |
| OLD | NEW |