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 |
| 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 consumeUntilNotWhitespace(); |
| 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); |
| 55 codePoints['\n'] = &MediaQueryTokenizer::whiteSpace; |
| 56 codePoints['\r'] = &MediaQueryTokenizer::whiteSpace; |
| 57 codePoints['\t'] = &MediaQueryTokenizer::whiteSpace; |
| 58 codePoints[' '] = &MediaQueryTokenizer::whiteSpace; |
| 59 codePoints['\f'] = &MediaQueryTokenizer::whiteSpace; |
| 60 codePoints['('] = &MediaQueryTokenizer::leftParen; |
| 61 codePoints[')'] = &MediaQueryTokenizer::rightParen; |
| 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* getCodePoints() |
| 82 { |
| 83 static CodePoints codePoints; |
| 84 return &codePoints; |
| 85 } |
| 86 |
| 87 MediaQueryToken whiteSpace(UChar); |
| 88 MediaQueryToken leftParen(UChar); |
| 89 MediaQueryToken rightParen(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 |