| 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 21 matching lines...) Expand all Loading... |
| 32 // To avoid resizing we err on the side of reserving too much space. | 32 // To avoid resizing we err on the side of reserving too much space. |
| 33 // Most strings we tokenize have about 3.5 to 5 characters per token. | 33 // Most strings we tokenize have about 3.5 to 5 characters per token. |
| 34 m_tokens.reserveInitialCapacity(string.length() / 3); | 34 m_tokens.reserveInitialCapacity(string.length() / 3); |
| 35 | 35 |
| 36 while (true) { | 36 while (true) { |
| 37 CSSParserToken token = nextToken(); | 37 CSSParserToken token = nextToken(); |
| 38 if (token.type() == CommentToken) | 38 if (token.type() == CommentToken) |
| 39 continue; | 39 continue; |
| 40 if (token.type() == EOFToken) | 40 if (token.type() == EOFToken) |
| 41 return; | 41 return; |
| 42 m_tokens.append(token); | 42 m_tokens.push_back(token); |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 | 45 |
| 46 CSSTokenizer::CSSTokenizer(const String& string, | 46 CSSTokenizer::CSSTokenizer(const String& string, |
| 47 CSSParserObserverWrapper& wrapper) | 47 CSSParserObserverWrapper& wrapper) |
| 48 : m_input(string) { | 48 : m_input(string) { |
| 49 if (string.isEmpty()) | 49 if (string.isEmpty()) |
| 50 return; | 50 return; |
| 51 | 51 |
| 52 unsigned offset = 0; | 52 unsigned offset = 0; |
| 53 while (true) { | 53 while (true) { |
| 54 CSSParserToken token = nextToken(); | 54 CSSParserToken token = nextToken(); |
| 55 if (token.type() == EOFToken) | 55 if (token.type() == EOFToken) |
| 56 break; | 56 break; |
| 57 if (token.type() == CommentToken) { | 57 if (token.type() == CommentToken) { |
| 58 wrapper.addComment(offset, m_input.offset(), m_tokens.size()); | 58 wrapper.addComment(offset, m_input.offset(), m_tokens.size()); |
| 59 } else { | 59 } else { |
| 60 m_tokens.append(token); | 60 m_tokens.push_back(token); |
| 61 wrapper.addToken(offset); | 61 wrapper.addToken(offset); |
| 62 } | 62 } |
| 63 offset = m_input.offset(); | 63 offset = m_input.offset(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 wrapper.addToken(offset); | 66 wrapper.addToken(offset); |
| 67 wrapper.finalizeConstruction(m_tokens.begin()); | 67 wrapper.finalizeConstruction(m_tokens.begin()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 CSSParserTokenRange CSSTokenizer::tokenRange() { | 70 CSSParserTokenRange CSSTokenizer::tokenRange() { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 94 m_input.advance(); | 94 m_input.advance(); |
| 95 return current; | 95 return current; |
| 96 } | 96 } |
| 97 | 97 |
| 98 CSSParserToken CSSTokenizer::whiteSpace(UChar cc) { | 98 CSSParserToken CSSTokenizer::whiteSpace(UChar cc) { |
| 99 m_input.advanceUntilNonWhitespace(); | 99 m_input.advanceUntilNonWhitespace(); |
| 100 return CSSParserToken(WhitespaceToken); | 100 return CSSParserToken(WhitespaceToken); |
| 101 } | 101 } |
| 102 | 102 |
| 103 CSSParserToken CSSTokenizer::blockStart(CSSParserTokenType type) { | 103 CSSParserToken CSSTokenizer::blockStart(CSSParserTokenType type) { |
| 104 m_blockStack.append(type); | 104 m_blockStack.push_back(type); |
| 105 return CSSParserToken(type, CSSParserToken::BlockStart); | 105 return CSSParserToken(type, CSSParserToken::BlockStart); |
| 106 } | 106 } |
| 107 | 107 |
| 108 CSSParserToken CSSTokenizer::blockStart(CSSParserTokenType blockType, | 108 CSSParserToken CSSTokenizer::blockStart(CSSParserTokenType blockType, |
| 109 CSSParserTokenType type, | 109 CSSParserTokenType type, |
| 110 StringView name) { | 110 StringView name) { |
| 111 m_blockStack.append(blockType); | 111 m_blockStack.push_back(blockType); |
| 112 return CSSParserToken(type, name, CSSParserToken::BlockStart); | 112 return CSSParserToken(type, name, CSSParserToken::BlockStart); |
| 113 } | 113 } |
| 114 | 114 |
| 115 CSSParserToken CSSTokenizer::blockEnd(CSSParserTokenType type, | 115 CSSParserToken CSSTokenizer::blockEnd(CSSParserTokenType type, |
| 116 CSSParserTokenType startType) { | 116 CSSParserTokenType startType) { |
| 117 if (!m_blockStack.isEmpty() && m_blockStack.back() == startType) { | 117 if (!m_blockStack.isEmpty() && m_blockStack.back() == startType) { |
| 118 m_blockStack.pop_back(); | 118 m_blockStack.pop_back(); |
| 119 return CSSParserToken(type, CSSParserToken::BlockEnd); | 119 return CSSParserToken(type, CSSParserToken::BlockEnd); |
| 120 } | 120 } |
| 121 return CSSParserToken(type); | 121 return CSSParserToken(type); |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 } | 670 } |
| 671 | 671 |
| 672 bool CSSTokenizer::nextCharsAreIdentifier() { | 672 bool CSSTokenizer::nextCharsAreIdentifier() { |
| 673 UChar first = consume(); | 673 UChar first = consume(); |
| 674 bool areIdentifier = nextCharsAreIdentifier(first); | 674 bool areIdentifier = nextCharsAreIdentifier(first); |
| 675 reconsume(first); | 675 reconsume(first); |
| 676 return areIdentifier; | 676 return areIdentifier; |
| 677 } | 677 } |
| 678 | 678 |
| 679 StringView CSSTokenizer::registerString(const String& string) { | 679 StringView CSSTokenizer::registerString(const String& string) { |
| 680 m_stringPool.append(string); | 680 m_stringPool.push_back(string); |
| 681 return string; | 681 return string; |
| 682 } | 682 } |
| 683 | 683 |
| 684 } // namespace blink | 684 } // namespace blink |
| OLD | NEW |