Chromium Code Reviews| 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..2790b2869324421516e9cb327b83bcc32ea9e9bc |
| --- /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 |
| + |
| +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 consumeUntilNotWhitespace(); |
|
kenneth.r.christiansen
2014/03/08 22:37:47
non ?
You terminology mixes until and till
|
| + |
| + 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); |
| + codePoints['\n'] = &MediaQueryTokenizer::whiteSpace; |
| + codePoints['\r'] = &MediaQueryTokenizer::whiteSpace; |
| + codePoints['\t'] = &MediaQueryTokenizer::whiteSpace; |
| + codePoints[' '] = &MediaQueryTokenizer::whiteSpace; |
| + codePoints['\f'] = &MediaQueryTokenizer::whiteSpace; |
| + codePoints['('] = &MediaQueryTokenizer::leftParen; |
| + codePoints[')'] = &MediaQueryTokenizer::rightParen; |
| + 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* getCodePoints() |
|
kenneth.r.christiansen
2014/03/08 22:37:47
why not just codePoints()?
|
| + { |
| + static CodePoints codePoints; |
| + return &codePoints; |
| + } |
| + |
| + MediaQueryToken whiteSpace(UChar); |
| + MediaQueryToken leftParen(UChar); |
| + MediaQueryToken rightParen(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 |