OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef MediaQueryTokenizer_h | |
6 #define MediaQueryTokenizer_h | |
7 | |
8 #include "core/css/parser/MediaQueryToken.h" | |
9 #include "core/html/parser/InputStreamPreprocessor.h" | |
10 #include "wtf/text/WTFString.h" | |
11 | |
12 #define CODE_POINTS_NUM 128 | |
eseidel
2014/03/11 20:14:19
What is this for? Can it be a const instead of a
| |
13 | |
14 namespace WebCore { | |
15 | |
16 class MediaQueryInputStream; | |
17 | |
18 class MediaQueryTokenizer { | |
19 WTF_MAKE_NONCOPYABLE(MediaQueryTokenizer); | |
20 WTF_MAKE_FAST_ALLOCATED; | |
21 public: | |
22 MediaQueryTokenizer(); | |
23 | |
24 MediaQueryToken nextToken(MediaQueryInputStream&); | |
25 static void tokenize(String, Vector<MediaQueryToken>&); | |
26 | |
27 private: | |
28 UChar consume(); | |
29 void consume(unsigned); | |
30 void reconsume(UChar); | |
31 | |
32 MediaQueryToken consumeNumericToken(); | |
33 MediaQueryToken consumeIdentLikeToken(); | |
34 MediaQueryToken consumeNumber(); | |
35 | |
36 void consumeUntilNonWhitespace(); | |
37 | |
38 bool consumeIfNext(UChar); | |
39 String consumeName(); | |
40 UChar consumeEscape(); | |
41 | |
42 bool nextTwoCharsAreValidEscape(); | |
43 bool nextCharsAreNumber(); | |
44 bool nextCharsAreIdentifier(); | |
45 | |
46 typedef MediaQueryToken (MediaQueryTokenizer::*CodePoint)(UChar); | |
47 | |
48 class CodePoints { | |
49 public: | |
50 CodePoint codePoints[CODE_POINTS_NUM]; | |
51 | |
52 CodePoints() | |
53 { | |
54 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
| |
55 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
| |
56 codePoints['\r'] = &MediaQueryTokenizer::whiteSpace; | |
57 codePoints['\t'] = &MediaQueryTokenizer::whiteSpace; | |
58 codePoints[' '] = &MediaQueryTokenizer::whiteSpace; | |
59 codePoints['\f'] = &MediaQueryTokenizer::whiteSpace; | |
60 codePoints['('] = &MediaQueryTokenizer::leftParenthesis; | |
61 codePoints[')'] = &MediaQueryTokenizer::rightParenthesis; | |
62 codePoints['+'] = &MediaQueryTokenizer::plusOrFullStop; | |
63 codePoints['.'] = &MediaQueryTokenizer::plusOrFullStop; | |
64 codePoints[','] = &MediaQueryTokenizer::comma; | |
65 codePoints['-'] = &MediaQueryTokenizer::hyphenMinus; | |
66 codePoints['/'] = &MediaQueryTokenizer::solidus; | |
67 codePoints[':'] = &MediaQueryTokenizer::colon; | |
68 codePoints[';'] = &MediaQueryTokenizer::semiColon; | |
69 codePoints['\\'] = &MediaQueryTokenizer::reverseSolidus; | |
70 for (unsigned char digit = '0'; digit <= '9'; ++digit) | |
71 codePoints[digit] = &MediaQueryTokenizer::asciiDigit; | |
72 for (unsigned char alpha = 'a'; alpha <= 'z'; ++alpha) | |
73 codePoints[alpha] = &MediaQueryTokenizer::nameStart; | |
74 for (unsigned char alpha = 'A'; alpha <= 'Z'; ++alpha) | |
75 codePoints[alpha] = &MediaQueryTokenizer::nameStart; | |
76 codePoints['_'] = &MediaQueryTokenizer::nameStart; | |
77 codePoints[kEndOfFileMarker] = &MediaQueryTokenizer::endOfFile; | |
78 } | |
79 }; | |
80 | |
81 CodePoints* codePoints() | |
82 { | |
83 static CodePoints codePoints; | |
84 return &codePoints; | |
85 } | |
86 | |
87 MediaQueryToken whiteSpace(UChar); | |
88 MediaQueryToken leftParenthesis(UChar); | |
89 MediaQueryToken rightParenthesis(UChar); | |
90 MediaQueryToken plusOrFullStop(UChar); | |
91 MediaQueryToken comma(UChar); | |
92 MediaQueryToken hyphenMinus(UChar); | |
93 MediaQueryToken solidus(UChar); | |
94 MediaQueryToken colon(UChar); | |
95 MediaQueryToken semiColon(UChar); | |
96 MediaQueryToken reverseSolidus(UChar); | |
97 MediaQueryToken asciiDigit(UChar); | |
98 MediaQueryToken nameStart(UChar); | |
99 MediaQueryToken endOfFile(UChar); | |
100 | |
101 MediaQueryInputStream* m_input; | |
102 }; | |
103 | |
104 | |
105 | |
106 } // namespace WebCore | |
107 | |
108 #endif // MediaQueryTokenizer_h | |
OLD | NEW |