1 | /*
|
---|
2 | * Copyright 2001-2004 The Apache Software Foundation.
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | */
|
---|
16 |
|
---|
17 | /*
|
---|
18 | * $Id: Token.hpp,v 1.8 2004/09/08 13:56:47 peiyongz Exp $
|
---|
19 | */
|
---|
20 |
|
---|
21 | #if !defined(TOKEN_HPP)
|
---|
22 | #define TOKEN_HPP
|
---|
23 |
|
---|
24 | // ---------------------------------------------------------------------------
|
---|
25 | // Includes
|
---|
26 | // ---------------------------------------------------------------------------
|
---|
27 | #include <xercesc/util/RuntimeException.hpp>
|
---|
28 | #include <xercesc/util/PlatformUtils.hpp>
|
---|
29 |
|
---|
30 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
31 |
|
---|
32 | // ---------------------------------------------------------------------------
|
---|
33 | // Forward Declaration
|
---|
34 | // ---------------------------------------------------------------------------
|
---|
35 | class RangeToken;
|
---|
36 | class TokenFactory;
|
---|
37 |
|
---|
38 |
|
---|
39 | class XMLUTIL_EXPORT Token : public XMemory
|
---|
40 | {
|
---|
41 | public:
|
---|
42 | // -----------------------------------------------------------------------
|
---|
43 | // Public Constructors and Destructor
|
---|
44 | // -----------------------------------------------------------------------
|
---|
45 | Token(const unsigned short tokType
|
---|
46 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
47 | );
|
---|
48 | virtual ~Token();
|
---|
49 |
|
---|
50 | // -----------------------------------------------------------------------
|
---|
51 | // Public Constants
|
---|
52 | // -----------------------------------------------------------------------
|
---|
53 | // Token types
|
---|
54 | enum {
|
---|
55 | T_CHAR = 0,
|
---|
56 | T_CONCAT = 1,
|
---|
57 | T_UNION = 2,
|
---|
58 | T_CLOSURE = 3,
|
---|
59 | T_RANGE = 4,
|
---|
60 | T_NRANGE = 5,
|
---|
61 | T_PAREN = 6,
|
---|
62 | T_EMPTY = 7,
|
---|
63 | T_ANCHOR = 8,
|
---|
64 | T_NONGREEDYCLOSURE = 9,
|
---|
65 | T_STRING = 10,
|
---|
66 | T_DOT = 11,
|
---|
67 | T_BACKREFERENCE = 12,
|
---|
68 | T_LOOKAHEAD = 20,
|
---|
69 | T_NEGATIVELOOKAHEAD = 21,
|
---|
70 | T_LOOKBEHIND = 22,
|
---|
71 | T_NEGATIVELOOKBEHIND = 23,
|
---|
72 | T_INDEPENDENT = 24,
|
---|
73 | T_MODIFIERGROUP = 25,
|
---|
74 | T_CONDITION = 26
|
---|
75 | };
|
---|
76 |
|
---|
77 | static const XMLInt32 UTF16_MAX;
|
---|
78 | static const unsigned short FC_CONTINUE;
|
---|
79 | static const unsigned short FC_TERMINAL;
|
---|
80 | static const unsigned short FC_ANY;
|
---|
81 |
|
---|
82 | // -----------------------------------------------------------------------
|
---|
83 | // Getter methods
|
---|
84 | // -----------------------------------------------------------------------
|
---|
85 | unsigned short getTokenType() const;
|
---|
86 | int getMinLength() const;
|
---|
87 | int getMaxLength() const;
|
---|
88 | virtual Token* getChild(const int index) const;
|
---|
89 | virtual int size() const;
|
---|
90 | virtual int getMin() const;
|
---|
91 | virtual int getMax() const;
|
---|
92 | virtual int getNoParen() const;
|
---|
93 | virtual int getReferenceNo() const;
|
---|
94 | virtual const XMLCh* getString() const;
|
---|
95 | virtual XMLInt32 getChar() const;
|
---|
96 |
|
---|
97 | // -----------------------------------------------------------------------
|
---|
98 | // Setter methods
|
---|
99 | // -----------------------------------------------------------------------
|
---|
100 | void setTokenType(const unsigned short tokType);
|
---|
101 | virtual void setMin(const int minVal);
|
---|
102 | virtual void setMax(const int maxVal);
|
---|
103 |
|
---|
104 | // -----------------------------------------------------------------------
|
---|
105 | // Range manipulation methods
|
---|
106 | // -----------------------------------------------------------------------
|
---|
107 | virtual void addRange(const XMLInt32 start, const XMLInt32 end);
|
---|
108 | virtual void mergeRanges(const Token *const tok);
|
---|
109 | virtual void sortRanges();
|
---|
110 | virtual void compactRanges();
|
---|
111 | virtual void subtractRanges(RangeToken* const tok);
|
---|
112 | virtual void intersectRanges(RangeToken* const tok);
|
---|
113 |
|
---|
114 | // -----------------------------------------------------------------------
|
---|
115 | // Putter methods
|
---|
116 | // -----------------------------------------------------------------------
|
---|
117 | virtual void addChild(Token* const child, TokenFactory* const tokFactory);
|
---|
118 |
|
---|
119 | // -----------------------------------------------------------------------
|
---|
120 | // Helper methods
|
---|
121 | // -----------------------------------------------------------------------
|
---|
122 | int analyzeFirstCharacter(RangeToken* const rangeTok, const int options,
|
---|
123 | TokenFactory* const tokFactory);
|
---|
124 | Token* findFixedString(int options, int& outOptions);
|
---|
125 |
|
---|
126 | private:
|
---|
127 | // -----------------------------------------------------------------------
|
---|
128 | // Unimplemented constructors and operators
|
---|
129 | // -----------------------------------------------------------------------
|
---|
130 | Token(const Token&);
|
---|
131 | Token& operator=(const Token&);
|
---|
132 |
|
---|
133 | // -----------------------------------------------------------------------
|
---|
134 | // Private Helper methods
|
---|
135 | // -----------------------------------------------------------------------
|
---|
136 | bool isSet(const int options, const unsigned int flag);
|
---|
137 | bool isShorterThan(Token* const tok);
|
---|
138 |
|
---|
139 | // -----------------------------------------------------------------------
|
---|
140 | // Private data members
|
---|
141 | // -----------------------------------------------------------------------
|
---|
142 | unsigned short fTokenType;
|
---|
143 | protected:
|
---|
144 | MemoryManager* const fMemoryManager;
|
---|
145 | };
|
---|
146 |
|
---|
147 |
|
---|
148 | // ---------------------------------------------------------------------------
|
---|
149 | // Token: getter methods
|
---|
150 | // ---------------------------------------------------------------------------
|
---|
151 | inline unsigned short Token::getTokenType() const {
|
---|
152 |
|
---|
153 | return fTokenType;
|
---|
154 | }
|
---|
155 |
|
---|
156 | inline int Token::size() const {
|
---|
157 |
|
---|
158 | return 0;
|
---|
159 | }
|
---|
160 |
|
---|
161 | inline Token* Token::getChild(const int) const {
|
---|
162 |
|
---|
163 | return 0;
|
---|
164 | }
|
---|
165 |
|
---|
166 | inline int Token::getMin() const {
|
---|
167 |
|
---|
168 | return -1;
|
---|
169 | }
|
---|
170 |
|
---|
171 | inline int Token::getMax() const {
|
---|
172 |
|
---|
173 | return -1;
|
---|
174 | }
|
---|
175 |
|
---|
176 | inline int Token::getReferenceNo() const {
|
---|
177 |
|
---|
178 | return 0;
|
---|
179 | }
|
---|
180 |
|
---|
181 | inline int Token::getNoParen() const {
|
---|
182 |
|
---|
183 | return 0;
|
---|
184 | }
|
---|
185 |
|
---|
186 | inline const XMLCh* Token::getString() const {
|
---|
187 |
|
---|
188 | return 0;
|
---|
189 | }
|
---|
190 |
|
---|
191 | inline XMLInt32 Token::getChar() const {
|
---|
192 |
|
---|
193 | return -1;
|
---|
194 | }
|
---|
195 |
|
---|
196 | // ---------------------------------------------------------------------------
|
---|
197 | // Token: setter methods
|
---|
198 | // ---------------------------------------------------------------------------
|
---|
199 | inline void Token::setTokenType(const unsigned short tokType) {
|
---|
200 |
|
---|
201 | fTokenType = tokType;
|
---|
202 | }
|
---|
203 |
|
---|
204 | inline void Token::setMax(const int) {
|
---|
205 | // ClosureToken
|
---|
206 | }
|
---|
207 |
|
---|
208 | inline void Token::setMin(const int) {
|
---|
209 | // ClosureToken
|
---|
210 | }
|
---|
211 |
|
---|
212 | inline bool Token::isSet(const int options, const unsigned int flag) {
|
---|
213 |
|
---|
214 | return (options & flag) == flag;
|
---|
215 | }
|
---|
216 |
|
---|
217 | // ---------------------------------------------------------------------------
|
---|
218 | // Token: setter methods
|
---|
219 | // ---------------------------------------------------------------------------
|
---|
220 | inline void Token::addChild(Token* const, TokenFactory* const) {
|
---|
221 |
|
---|
222 | ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
---|
223 | }
|
---|
224 |
|
---|
225 | // ---------------------------------------------------------------------------
|
---|
226 | // Token: Range manipulation methods
|
---|
227 | // ---------------------------------------------------------------------------
|
---|
228 | inline void Token::addRange(const XMLInt32, const XMLInt32) {
|
---|
229 |
|
---|
230 | ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
---|
231 | }
|
---|
232 |
|
---|
233 | inline void Token::mergeRanges(const Token *const) {
|
---|
234 |
|
---|
235 | ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
---|
236 | }
|
---|
237 |
|
---|
238 | inline void Token::sortRanges() {
|
---|
239 |
|
---|
240 | ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
---|
241 | }
|
---|
242 |
|
---|
243 | inline void Token::compactRanges() {
|
---|
244 |
|
---|
245 | ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
---|
246 | }
|
---|
247 |
|
---|
248 | inline void Token::subtractRanges(RangeToken* const) {
|
---|
249 |
|
---|
250 | ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
---|
251 | }
|
---|
252 |
|
---|
253 | inline void Token::intersectRanges(RangeToken* const) {
|
---|
254 |
|
---|
255 | ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
---|
256 | }
|
---|
257 |
|
---|
258 | XERCES_CPP_NAMESPACE_END
|
---|
259 |
|
---|
260 | #endif
|
---|
261 |
|
---|
262 | /**
|
---|
263 | * End of file Token.hpp
|
---|
264 | */
|
---|
265 |
|
---|