Index: Source/core/css/parser/MediaQueryTokenizer.h |
diff --git a/Source/core/css/parser/MediaQueryTokenizer.h b/Source/core/css/parser/MediaQueryTokenizer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7d31e7dd4a19dbf4bdc6e72d7e05cfebfcdb470d |
--- /dev/null |
+++ b/Source/core/css/parser/MediaQueryTokenizer.h |
@@ -0,0 +1,108 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MediaQueryTokenizer_h |
+#define MediaQueryTokenizer_h |
+ |
+#include "core/css/parser/MediaQueryToken.h" |
+#include "core/html/parser/InputStreamPreprocessor.h" |
+#include "wtf/text/WTFString.h" |
+ |
+#define CODE_POINTS_NUM 128 |
eseidel
2014/03/11 20:14:19
What is this for? Can it be a const instead of a
|
+ |
+namespace WebCore { |
+ |
+class MediaQueryInputStream; |
+ |
+class MediaQueryTokenizer { |
+ WTF_MAKE_NONCOPYABLE(MediaQueryTokenizer); |
+ WTF_MAKE_FAST_ALLOCATED; |
+public: |
+ MediaQueryTokenizer(); |
+ |
+ MediaQueryToken nextToken(MediaQueryInputStream&); |
+ static void tokenize(String, Vector<MediaQueryToken>&); |
+ |
+private: |
+ UChar consume(); |
+ void consume(unsigned); |
+ void reconsume(UChar); |
+ |
+ MediaQueryToken consumeNumericToken(); |
+ MediaQueryToken consumeIdentLikeToken(); |
+ MediaQueryToken consumeNumber(); |
+ |
+ void consumeUntilNonWhitespace(); |
+ |
+ bool consumeIfNext(UChar); |
+ String consumeName(); |
+ UChar consumeEscape(); |
+ |
+ bool nextTwoCharsAreValidEscape(); |
+ bool nextCharsAreNumber(); |
+ bool nextCharsAreIdentifier(); |
+ |
+ typedef MediaQueryToken (MediaQueryTokenizer::*CodePoint)(UChar); |
+ |
+ class CodePoints { |
+ public: |
+ CodePoint codePoints[CODE_POINTS_NUM]; |
+ |
+ CodePoints() |
+ { |
+ memset(codePoints, 0, CODE_POINTS_NUM); |
eseidel
2014/03/11 20:14:19
This could be static and stored in the binary inst
Yoav Weiss
2014/03/12 20:39:00
I'm not sure how to do that. I'd love some guidanc
eseidel
2014/03/13 00:49:36
You'd probably have to do it with static initializ
|
+ codePoints['\n'] = &MediaQueryTokenizer::whiteSpace; |
eseidel
2014/03/11 20:14:19
Why are we using a jump-table instead of an if-cas
Yoav Weiss
2014/03/12 20:39:00
I implemented it as a table following a comment by
eseidel
2014/03/13 00:49:36
I'm told that modern compilers are able to convert
|
+ codePoints['\r'] = &MediaQueryTokenizer::whiteSpace; |
+ codePoints['\t'] = &MediaQueryTokenizer::whiteSpace; |
+ codePoints[' '] = &MediaQueryTokenizer::whiteSpace; |
+ codePoints['\f'] = &MediaQueryTokenizer::whiteSpace; |
+ codePoints['('] = &MediaQueryTokenizer::leftParenthesis; |
+ codePoints[')'] = &MediaQueryTokenizer::rightParenthesis; |
+ codePoints['+'] = &MediaQueryTokenizer::plusOrFullStop; |
+ codePoints['.'] = &MediaQueryTokenizer::plusOrFullStop; |
+ codePoints[','] = &MediaQueryTokenizer::comma; |
+ codePoints['-'] = &MediaQueryTokenizer::hyphenMinus; |
+ codePoints['/'] = &MediaQueryTokenizer::solidus; |
+ codePoints[':'] = &MediaQueryTokenizer::colon; |
+ codePoints[';'] = &MediaQueryTokenizer::semiColon; |
+ codePoints['\\'] = &MediaQueryTokenizer::reverseSolidus; |
+ for (unsigned char digit = '0'; digit <= '9'; ++digit) |
+ codePoints[digit] = &MediaQueryTokenizer::asciiDigit; |
+ for (unsigned char alpha = 'a'; alpha <= 'z'; ++alpha) |
+ codePoints[alpha] = &MediaQueryTokenizer::nameStart; |
+ for (unsigned char alpha = 'A'; alpha <= 'Z'; ++alpha) |
+ codePoints[alpha] = &MediaQueryTokenizer::nameStart; |
+ codePoints['_'] = &MediaQueryTokenizer::nameStart; |
+ codePoints[kEndOfFileMarker] = &MediaQueryTokenizer::endOfFile; |
+ } |
+ }; |
+ |
+ CodePoints* codePoints() |
+ { |
+ static CodePoints codePoints; |
+ return &codePoints; |
+ } |
+ |
+ MediaQueryToken whiteSpace(UChar); |
+ MediaQueryToken leftParenthesis(UChar); |
+ MediaQueryToken rightParenthesis(UChar); |
+ MediaQueryToken plusOrFullStop(UChar); |
+ MediaQueryToken comma(UChar); |
+ MediaQueryToken hyphenMinus(UChar); |
+ MediaQueryToken solidus(UChar); |
+ MediaQueryToken colon(UChar); |
+ MediaQueryToken semiColon(UChar); |
+ MediaQueryToken reverseSolidus(UChar); |
+ MediaQueryToken asciiDigit(UChar); |
+ MediaQueryToken nameStart(UChar); |
+ MediaQueryToken endOfFile(UChar); |
+ |
+ MediaQueryInputStream* m_input; |
+}; |
+ |
+ |
+ |
+} // namespace WebCore |
+ |
+#endif // MediaQueryTokenizer_h |