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

Side by Side Diff: Source/core/css/parser/MediaQueryTokenizer.h

Issue 171383002: A thread-safe Media Query Parser (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Refactored and passes tests Created 6 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef MediaQueryTokenizer_h
32 #define MediaQueryTokenizer_h
33
34 #include "core/css/parser/CSSToken.h"
35 #include "core/html/parser/InputStreamPreprocessor.h"
36 #include "wtf/text/WTFString.h"
37
38 #define CODE_POINTS_NUM 128
39
40 namespace WebCore {
41
42 class CSSInputStream;
43
44 class MediaQueryTokenizer {
45 WTF_MAKE_NONCOPYABLE(MediaQueryTokenizer);
46 WTF_MAKE_FAST_ALLOCATED;
47 public:
48 MediaQueryTokenizer();
49
50 CSSToken nextToken(CSSInputStream&);
51 static void tokenize(String, Vector<CSSToken>&);
52
53 private:
54 UChar consume();
55 void consume(unsigned);
56 void reconsume(UChar);
57
58 CSSToken consumeNumericToken();
59 CSSToken consumeIdentLikeToken();
60 CSSToken consumeNumber();
61
62 void consumeUntilNotWhitespace();
63
64 bool consumeIfNext(UChar);
65 String consumeName();
66 UChar consumeEscape();
67
68 bool nextTwoCharsAreValidEscape();
69 bool nextCharsAreNumber();
70 bool nextCharsAreIdentifier();
71
72 typedef CSSToken (MediaQueryTokenizer::*CodePoint)(UChar);
73
74 class CodePoints {
75 public:
76 CodePoint codePoints[CODE_POINTS_NUM];
77
78 CodePoints()
79 {
80 memset(codePoints, 0, CODE_POINTS_NUM);
81 codePoints['\n'] = &MediaQueryTokenizer::whiteSpace;
82 codePoints['\r'] = &MediaQueryTokenizer::whiteSpace;
83 codePoints['\t'] = &MediaQueryTokenizer::whiteSpace;
84 codePoints[' '] = &MediaQueryTokenizer::whiteSpace;
85 codePoints['\f'] = &MediaQueryTokenizer::whiteSpace;
86 codePoints['('] = &MediaQueryTokenizer::leftParen;
87 codePoints[')'] = &MediaQueryTokenizer::rightParen;
88 codePoints['+'] = &MediaQueryTokenizer::plusOrFullStop;
89 codePoints['.'] = &MediaQueryTokenizer::plusOrFullStop;
90 codePoints[','] = &MediaQueryTokenizer::comma;
91 codePoints['-'] = &MediaQueryTokenizer::hyphenMinus;
92 codePoints['/'] = &MediaQueryTokenizer::solidus;
93 codePoints[':'] = &MediaQueryTokenizer::colon;
94 codePoints[';'] = &MediaQueryTokenizer::semiColon;
95 codePoints['\\'] = &MediaQueryTokenizer::reverseSolidus;
96 for (char digit = '0'; digit <= '9'; ++digit)
97 codePoints[digit] = &MediaQueryTokenizer::asciiDigit;
98 for (char alpha = 'a'; alpha <= 'z'; ++alpha)
99 codePoints[alpha] = &MediaQueryTokenizer::nameStart;
100 for (char alpha = 'A'; alpha <= 'Z'; ++alpha)
101 codePoints[alpha] = &MediaQueryTokenizer::nameStart;
102 codePoints['_'] = &MediaQueryTokenizer::nameStart;
103 codePoints[kEndOfFileMarker] = &MediaQueryTokenizer::endOfFile;
104 }
105 };
106
107 CodePoints* getCodePoints()
108 {
109 static CodePoints codePoints;
110 return &codePoints;
111 }
112
113 CSSToken whiteSpace(UChar);
114 CSSToken leftParen(UChar);
115 CSSToken rightParen(UChar);
116 CSSToken plusOrFullStop(UChar);
117 CSSToken comma(UChar);
118 CSSToken hyphenMinus(UChar);
119 CSSToken solidus(UChar);
120 CSSToken colon(UChar);
121 CSSToken semiColon(UChar);
122 CSSToken reverseSolidus(UChar);
123 CSSToken asciiDigit(UChar);
124 CSSToken nameStart(UChar);
125 CSSToken endOfFile(UChar);
126
127 CSSInputStream* m_input;
128 };
129
130
131
132 } // namespace WebCore
133
134 #endif // MediaQueryTokenizer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698