1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
2 | // Copyright (C) 2016 Apple 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 | #pragma once |
31 | |
32 | #include "CSSParserToken.h" |
33 | #include "CSSTokenizerInputStream.h" |
34 | #include <climits> |
35 | #include <wtf/text/StringView.h> |
36 | #include <wtf/text/WTFString.h> |
37 | |
38 | namespace WebCore { |
39 | |
40 | class CSSTokenizerInputStream; |
41 | class CSSParserObserverWrapper; |
42 | class CSSParserTokenRange; |
43 | |
44 | class CSSTokenizer { |
45 | WTF_MAKE_NONCOPYABLE(CSSTokenizer); |
46 | WTF_MAKE_FAST_ALLOCATED; |
47 | public: |
48 | CSSTokenizer(const String&); |
49 | CSSTokenizer(const String&, CSSParserObserverWrapper&); // For the inspector |
50 | |
51 | CSSParserTokenRange tokenRange() const; |
52 | unsigned tokenCount(); |
53 | |
54 | Vector<String>&& escapedStringsForAdoption() { return WTFMove(m_stringPool); } |
55 | |
56 | private: |
57 | CSSParserToken nextToken(); |
58 | |
59 | UChar consume(); |
60 | void reconsume(UChar); |
61 | |
62 | CSSParserToken (); |
63 | CSSParserToken consumeIdentLikeToken(); |
64 | CSSParserToken (); |
65 | CSSParserToken consumeStringTokenUntil(UChar); |
66 | CSSParserToken consumeUnicodeRange(); |
67 | CSSParserToken consumeUrlToken(); |
68 | |
69 | void consumeBadUrlRemnants(); |
70 | void consumeSingleWhitespaceIfNext(); |
71 | void (); |
72 | |
73 | bool consumeIfNext(UChar); |
74 | StringView consumeName(); |
75 | UChar32 consumeEscape(); |
76 | |
77 | bool nextTwoCharsAreValidEscape(); |
78 | bool nextCharsAreNumber(UChar); |
79 | bool nextCharsAreNumber(); |
80 | bool nextCharsAreIdentifier(UChar); |
81 | bool nextCharsAreIdentifier(); |
82 | |
83 | CSSParserToken blockStart(CSSParserTokenType); |
84 | CSSParserToken blockStart(CSSParserTokenType blockType, CSSParserTokenType, StringView); |
85 | CSSParserToken blockEnd(CSSParserTokenType, CSSParserTokenType startType); |
86 | |
87 | CSSParserToken whiteSpace(UChar); |
88 | CSSParserToken leftParenthesis(UChar); |
89 | CSSParserToken rightParenthesis(UChar); |
90 | CSSParserToken leftBracket(UChar); |
91 | CSSParserToken rightBracket(UChar); |
92 | CSSParserToken leftBrace(UChar); |
93 | CSSParserToken rightBrace(UChar); |
94 | CSSParserToken plusOrFullStop(UChar); |
95 | CSSParserToken comma(UChar); |
96 | CSSParserToken hyphenMinus(UChar); |
97 | CSSParserToken asterisk(UChar); |
98 | CSSParserToken lessThan(UChar); |
99 | CSSParserToken solidus(UChar); |
100 | CSSParserToken colon(UChar); |
101 | CSSParserToken semiColon(UChar); |
102 | CSSParserToken hash(UChar); |
103 | CSSParserToken circumflexAccent(UChar); |
104 | CSSParserToken dollarSign(UChar); |
105 | CSSParserToken verticalLine(UChar); |
106 | CSSParserToken tilde(UChar); |
107 | CSSParserToken commercialAt(UChar); |
108 | CSSParserToken reverseSolidus(UChar); |
109 | CSSParserToken asciiDigit(UChar); |
110 | CSSParserToken letterU(UChar); |
111 | CSSParserToken nameStart(UChar); |
112 | CSSParserToken stringStart(UChar); |
113 | CSSParserToken endOfFile(UChar); |
114 | |
115 | StringView registerString(const String&); |
116 | |
117 | using CodePoint = CSSParserToken (CSSTokenizer::*)(UChar); |
118 | static const CodePoint codePoints[]; |
119 | |
120 | Vector<CSSParserTokenType, 8> m_blockStack; |
121 | CSSTokenizerInputStream m_input; |
122 | |
123 | Vector<CSSParserToken, 32> m_tokens; |
124 | // We only allocate strings when escapes are used. |
125 | Vector<String> m_stringPool; |
126 | }; |
127 | |
128 | } // namespace WebCore |
129 | |