| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/css/parser/CSSTokenizer.h" | 6 #include "core/css/parser/CSSTokenizer.h" |
| 7 | 7 |
| 8 namespace blink { | 8 namespace blink { |
| 9 #include "core/CSSTokenizerCodepoints.cpp" | 9 #include "core/CSSTokenizerCodepoints.cpp" |
| 10 } | 10 } |
| 11 | 11 |
| 12 #include "core/css/parser/CSSParserObserverWrapper.h" | 12 #include "core/css/parser/CSSParserObserverWrapper.h" |
| 13 #include "core/css/parser/CSSParserTokenRange.h" | 13 #include "core/css/parser/CSSParserTokenRange.h" |
| 14 #include "core/css/parser/CSSTokenizerInputStream.h" | 14 #include "core/css/parser/CSSTokenizerInputStream.h" |
| 15 #include "core/html/parser/HTMLParserIdioms.h" | 15 #include "core/html/parser/HTMLParserIdioms.h" |
| 16 #include "wtf/text/CharacterNames.h" | 16 #include "wtf/text/CharacterNames.h" |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 | 19 |
| 20 CSSTokenizer::Scope::Scope(const String& string) | 20 CSSTokenizer::Scope::Scope(const String& string) |
| 21 : m_string(string) | 21 : m_string(string) |
| 22 { | 22 { |
| 23 // According to the spec, we should perform preprocessing here. | 23 // According to the spec, we should perform preprocessing here. |
| 24 // See: http://dev.w3.org/csswg/css-syntax/#input-preprocessing | 24 // See: http://dev.w3.org/csswg/css-syntax/#input-preprocessing |
| 25 // | 25 // |
| 26 // However, we can skip this step since: | 26 // However, we can skip this step since: |
| 27 // * We're using HTML spaces (which accept \r and \f as a valid white space) | 27 // * We're using HTML spaces (which accept \r and \f as a valid white space) |
| 28 // * Do not count white spaces | 28 // * Do not count white spaces |
| 29 // * CSSTokenizerInputStream::peek replaces NULLs for replacement characters | 29 // * CSSTokenizerInputStream::peek replaces NULLs for replacement characters |
| 30 | 30 |
| 31 if (string.isEmpty()) | 31 if (string.isEmpty()) |
| 32 return; | 32 return; |
| 33 | 33 |
| 34 // To avoid resizing we err on the side of reserving too much space. | 34 // To avoid resizing we err on the side of reserving too much space. |
| 35 // Most strings we tokenize have about 3.5 to 5 characters per token. | 35 // Most strings we tokenize have about 3.5 to 5 characters per token. |
| 36 m_tokens.reserveInitialCapacity(string.length() / 3); | 36 m_tokens.reserveInitialCapacity(string.length() / 3); |
| 37 | 37 |
| 38 CSSTokenizerInputStream input(string); | 38 CSSTokenizerInputStream input(string); |
| 39 CSSTokenizer tokenizer(input, *this); | 39 CSSTokenizer tokenizer(input, *this); |
| 40 while (true) { | 40 while (true) { |
| 41 CSSParserToken token = tokenizer.nextToken(); | 41 CSSParserToken token = tokenizer.nextToken(); |
| 42 if (token.type() == CommentToken) | 42 if (token.type() == CommentToken) |
| 43 continue; | 43 continue; |
| 44 if (token.type() == EOFToken) | 44 if (token.type() == EOFToken) |
| 45 return; | 45 return; |
| 46 m_tokens.append(token); | 46 m_tokens.append(token); |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 CSSTokenizer::Scope::Scope(const String& string, CSSParserObserverWrapper& wrapp
er) | 50 CSSTokenizer::Scope::Scope(const String& string, CSSParserObserverWrapper& wrapp
er) |
| 51 : m_string(string) | 51 : m_string(string) |
| 52 { | 52 { |
| 53 if (string.isEmpty()) | 53 if (string.isEmpty()) |
| 54 return; | 54 return; |
| 55 | 55 |
| 56 CSSTokenizerInputStream input(string); | 56 CSSTokenizerInputStream input(string); |
| 57 CSSTokenizer tokenizer(input, *this); | 57 CSSTokenizer tokenizer(input, *this); |
| 58 | 58 |
| 59 unsigned offset = 0; | 59 unsigned offset = 0; |
| 60 while (true) { | 60 while (true) { |
| 61 CSSParserToken token = tokenizer.nextToken(); | 61 CSSParserToken token = tokenizer.nextToken(); |
| (...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 | 785 |
| 786 CSSParserString CSSTokenizer::registerString(const String& string) | 786 CSSParserString CSSTokenizer::registerString(const String& string) |
| 787 { | 787 { |
| 788 m_scope.storeString(string); | 788 m_scope.storeString(string); |
| 789 CSSParserString result; | 789 CSSParserString result; |
| 790 result.init(string); | 790 result.init(string); |
| 791 return result; | 791 return result; |
| 792 } | 792 } |
| 793 | 793 |
| 794 } // namespace blink | 794 } // namespace blink |
| OLD | NEW |