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

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

Issue 209503003: Convert MediaQueryTokenizer's codepoints array to be static data (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Refactored python code 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
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/MediaQueryTokenizer.h" 6 #include "core/css/parser/MediaQueryTokenizer.h"
7 7
8 namespace WebCore {
9 #include "MediaQueryTokenizerCodepoints.cpp"
10 }
11
8 #include "core/css/parser/MediaQueryInputStream.h" 12 #include "core/css/parser/MediaQueryInputStream.h"
9 #include "core/html/parser/HTMLParserIdioms.h" 13 #include "core/html/parser/HTMLParserIdioms.h"
10 #include "wtf/unicode/CharacterNames.h" 14 #include "wtf/unicode/CharacterNames.h"
11 15
12 namespace WebCore { 16 namespace WebCore {
13 17
14 const unsigned codePointsNumber = SCHAR_MAX + 1;
15
16 class MediaQueryTokenizer::CodePoints {
17 public:
18 MediaQueryTokenizer::CodePoint codePoints[codePointsNumber];
19
20 // FIXME: Move the codePoint array to be a static one, generated by build sc ripts
21 CodePoints()
22 {
23 memset(codePoints, 0, codePointsNumber);
24 codePoints['\n'] = &MediaQueryTokenizer::whiteSpace;
25 codePoints['\r'] = &MediaQueryTokenizer::whiteSpace;
26 codePoints['\t'] = &MediaQueryTokenizer::whiteSpace;
27 codePoints[' '] = &MediaQueryTokenizer::whiteSpace;
28 codePoints['\f'] = &MediaQueryTokenizer::whiteSpace;
29 codePoints['('] = &MediaQueryTokenizer::leftParenthesis;
30 codePoints[')'] = &MediaQueryTokenizer::rightParenthesis;
31 codePoints['+'] = &MediaQueryTokenizer::plusOrFullStop;
32 codePoints['.'] = &MediaQueryTokenizer::plusOrFullStop;
33 codePoints[','] = &MediaQueryTokenizer::comma;
34 codePoints['-'] = &MediaQueryTokenizer::hyphenMinus;
35 codePoints['/'] = &MediaQueryTokenizer::solidus;
36 codePoints[':'] = &MediaQueryTokenizer::colon;
37 codePoints[';'] = &MediaQueryTokenizer::semiColon;
38 codePoints['\\'] = &MediaQueryTokenizer::reverseSolidus;
39 for (unsigned char digit = '0'; digit <= '9'; ++digit)
40 codePoints[digit] = &MediaQueryTokenizer::asciiDigit;
41 for (unsigned char alpha = 'a'; alpha <= 'z'; ++alpha)
42 codePoints[alpha] = &MediaQueryTokenizer::nameStart;
43 for (unsigned char alpha = 'A'; alpha <= 'Z'; ++alpha)
44 codePoints[alpha] = &MediaQueryTokenizer::nameStart;
45 codePoints['_'] = &MediaQueryTokenizer::nameStart;
46 codePoints[kEndOfFileMarker] = &MediaQueryTokenizer::endOfFile;
47 }
48 };
49
50 MediaQueryTokenizer::CodePoints* MediaQueryTokenizer::codePoints()
51 {
52 static CodePoints codePoints;
53 return &codePoints;
54 }
55
56 // http://dev.w3.org/csswg/css-syntax/#name-start-code-point 18 // http://dev.w3.org/csswg/css-syntax/#name-start-code-point
57 static bool isNameStart(UChar c) 19 static bool isNameStart(UChar c)
58 { 20 {
59 if (isASCIIAlpha(c)) 21 if (isASCIIAlpha(c))
60 return true; 22 return true;
61 if (c == '_') 23 if (c == '_')
62 return true; 24 return true;
63 return !isASCII(c); 25 return !isASCII(c);
64 } 26 }
65 27
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // We could move to the stateful model and instead create 171 // We could move to the stateful model and instead create
210 // states for all the "next 3 codepoints are X" cases. 172 // states for all the "next 3 codepoints are X" cases.
211 // State-machine tokenizers are easier to write to handle 173 // State-machine tokenizers are easier to write to handle
212 // incremental tokenization of partial sources. 174 // incremental tokenization of partial sources.
213 // However, for now we follow the spec exactly. 175 // However, for now we follow the spec exactly.
214 UChar cc = consume(); 176 UChar cc = consume();
215 CodePoint codePointFunc = 0; 177 CodePoint codePointFunc = 0;
216 178
217 if (isASCII(cc)) { 179 if (isASCII(cc)) {
218 ASSERT_WITH_SECURITY_IMPLICATION(cc < codePointsNumber); 180 ASSERT_WITH_SECURITY_IMPLICATION(cc < codePointsNumber);
219 codePointFunc = codePoints()->codePoints[cc]; 181 codePointFunc = codePoints[cc];
220 } else { 182 } else {
221 codePointFunc = &MediaQueryTokenizer::nameStart; 183 codePointFunc = &MediaQueryTokenizer::nameStart;
222 } 184 }
223 185
224 if (codePointFunc) 186 if (codePointFunc)
225 return ((this)->*(codePointFunc))(cc); 187 return ((this)->*(codePointFunc))(cc);
226 188
227 return MediaQueryToken(DelimiterToken, cc); 189 return MediaQueryToken(DelimiterToken, cc);
228 } 190 }
229 191
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 if (firstChar == '-') { 384 if (firstChar == '-') {
423 if (isNameStart(m_input.peek(1))) 385 if (isNameStart(m_input.peek(1)))
424 return true; 386 return true;
425 return nextTwoCharsAreValidEscape(); 387 return nextTwoCharsAreValidEscape();
426 } 388 }
427 389
428 return false; 390 return false;
429 } 391 }
430 392
431 } // namespace WebCore 393 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698