Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Unified Diff: Source/core/css/parser/CSSTokenizer.cpp

Issue 962093002: CSS Tokenizer: Add an on-stack tokenizer scope (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/parser/CSSTokenizer.h ('k') | Source/core/css/parser/CSSTokenizerTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/parser/CSSTokenizer.cpp
diff --git a/Source/core/css/parser/CSSTokenizer.cpp b/Source/core/css/parser/CSSTokenizer.cpp
index ae934646219ccc30cec3e012c0c2e9fb3fd414e3..ec45d84642f9b2827016cf8eea15b16186b0f860 100644
--- a/Source/core/css/parser/CSSTokenizer.cpp
+++ b/Source/core/css/parser/CSSTokenizer.cpp
@@ -9,12 +9,45 @@ namespace blink {
#include "core/CSSTokenizerCodepoints.cpp"
}
+#include "core/css/parser/CSSParserTokenRange.h"
#include "core/css/parser/CSSTokenizerInputStream.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "wtf/unicode/CharacterNames.h"
namespace blink {
+CSSTokenizer::Scope::Scope(const String& string)
+{
+ // According to the spec, we should perform preprocessing here.
+ // See: http://dev.w3.org/csswg/css-syntax/#input-preprocessing
+ //
+ // However, we can skip this step since:
+ // * We're using HTML spaces (which accept \r and \f as a valid white space)
+ // * Do not count white spaces
+ // * consumeEscape replaces NULLs for replacement characters
+
+ if (string.isEmpty())
+ return;
+
+ // To avoid resizing we err on the side of reserving too much space.
+ // Most strings we tokenize have about 3.5 to 5 characters per token.
+ m_tokens.reserveInitialCapacity(string.length() / 3);
+
+ CSSTokenizerInputStream input(string);
+ CSSTokenizer tokenizer(input);
+ while (true) {
+ CSSParserToken token = tokenizer.nextToken();
+ if (token.type() == EOFToken)
+ return;
+ m_tokens.append(token);
+ }
+}
+
+CSSParserTokenRange CSSTokenizer::Scope::tokenRange()
+{
+ return m_tokens;
+}
+
// http://dev.w3.org/csswg/css-syntax/#name-start-code-point
static bool isNameStart(UChar c)
{
@@ -295,33 +328,6 @@ CSSParserToken CSSTokenizer::endOfFile(UChar cc)
return CSSParserToken(EOFToken);
}
-void CSSTokenizer::tokenize(String string, Vector<CSSParserToken>& outTokens)
-{
- // According to the spec, we should perform preprocessing here.
- // See: http://dev.w3.org/csswg/css-syntax/#input-preprocessing
- //
- // However, we can skip this step since:
- // * We're using HTML spaces (which accept \r and \f as a valid white space)
- // * Do not count white spaces
- // * consumeEscape replaces NULLs for replacement characters
-
- if (string.isEmpty())
- return;
-
- // To avoid resizing we err on the side of reserving too much space.
- // Most strings we tokenize have about 3.5 to 5 characters per token.
- outTokens.reserveInitialCapacity(string.length() / 3);
-
- CSSTokenizerInputStream input(string);
- CSSTokenizer tokenizer(input);
- while (true) {
- CSSParserToken token = tokenizer.nextToken();
- if (token.type() == EOFToken)
- return;
- outTokens.append(token);
- }
-}
-
CSSParserToken CSSTokenizer::nextToken()
{
// Unlike the HTMLTokenizer, the CSS Syntax spec is written
« no previous file with comments | « Source/core/css/parser/CSSTokenizer.h ('k') | Source/core/css/parser/CSSTokenizerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698