49
|
1 |
/*
|
|
2 |
* Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: CSS Lexer
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#ifndef TCSSReader_H
|
|
19 |
#define TCSSReader_H
|
|
20 |
|
|
21 |
// INCLUDES
|
|
22 |
#include "nwx_defs.h"
|
|
23 |
#include <nw_string_string.h>
|
|
24 |
#include <e32std.h>
|
|
25 |
|
|
26 |
// CONSTANTS
|
|
27 |
|
|
28 |
// MACROS
|
|
29 |
|
|
30 |
// DATA TYPES
|
|
31 |
|
|
32 |
enum TCSSReaderTokenType{
|
|
33 |
SPACE = 1,
|
|
34 |
ATKEYWORD,
|
|
35 |
HASH,
|
|
36 |
ASTERISK,
|
|
37 |
COMMA,
|
|
38 |
DOT,
|
|
39 |
COLON,
|
|
40 |
HYPHEN,
|
|
41 |
SEMI_COLON,
|
|
42 |
LEFT_BRACE,
|
|
43 |
RIGHT_BRACE,
|
|
44 |
LEFT_BRACKET,
|
|
45 |
RIGHT_BRACKET,
|
|
46 |
EQUALS,
|
|
47 |
CHARSET_RULE,
|
|
48 |
IMPORT_RULE,
|
|
49 |
MEDIA_RULE,
|
|
50 |
LINK_PSEUDO_CLASS,
|
|
51 |
VISITED_PSEUDO_CLASS,
|
|
52 |
FOCUS_PSEUDO_CLASS,
|
|
53 |
ACTIVE_PSEUDO_CLASS,
|
|
54 |
CACHED_PSEUDO_CLASS,
|
|
55 |
IMPORTANT,
|
|
56 |
VERTICAL_LINE,
|
|
57 |
CDO,
|
|
58 |
CDC,
|
|
59 |
BUFFER_END,
|
|
60 |
IDENTIFIER,
|
|
61 |
EMS,
|
|
62 |
EXS,
|
|
63 |
PXS,
|
|
64 |
INS,
|
|
65 |
CMS,
|
|
66 |
MMS,
|
|
67 |
PTS,
|
|
68 |
PERCENTAGE,
|
|
69 |
PCS,
|
|
70 |
NUMBER,
|
|
71 |
URI,
|
|
72 |
RGB,
|
|
73 |
STRING,
|
|
74 |
RIGHT_PARENTHESIS,
|
|
75 |
DIGIT,
|
|
76 |
ALPHA,
|
|
77 |
INVALID
|
|
78 |
};
|
|
79 |
|
|
80 |
// FUNCTION PROTOTYPES
|
|
81 |
|
|
82 |
// FORWARD DECLARATIONS
|
|
83 |
|
|
84 |
// CLASS DECLARATION
|
|
85 |
|
|
86 |
/**
|
|
87 |
* This class is a unit of text
|
|
88 |
* @lib css.lib
|
|
89 |
* @since 2.1
|
|
90 |
*/
|
|
91 |
class TCSSReaderUnit
|
|
92 |
{
|
|
93 |
public:
|
|
94 |
// constructor
|
|
95 |
TCSSReaderUnit(TText8* aStorage, TUint32 aLength, TUint32 aNumChars)
|
|
96 |
{
|
|
97 |
iStorage = aStorage;
|
|
98 |
iLength = aLength;
|
|
99 |
iNumChars = aNumChars;
|
|
100 |
}
|
|
101 |
|
|
102 |
TCSSReaderUnit()
|
|
103 |
{
|
|
104 |
iStorage = NULL;
|
|
105 |
iLength = 0;
|
|
106 |
iNumChars = 0;
|
|
107 |
}
|
|
108 |
|
|
109 |
void Init(TText8* aStorage, TUint32 aLength, TUint32 aNumChars)
|
|
110 |
{
|
|
111 |
iStorage = aStorage;
|
|
112 |
iLength = aLength;
|
|
113 |
iNumChars = aNumChars;
|
|
114 |
}
|
|
115 |
/**
|
|
116 |
* Converts the text to unicode
|
|
117 |
* @since 2.1
|
|
118 |
* @param aEncoding: encoding of the document being parsed
|
|
119 |
* return unicode String
|
|
120 |
*/
|
|
121 |
TText16* GetUnicodeL(TUint32 aEncoding);
|
|
122 |
TText16* GetUnicode(TUint32 aEncoding);
|
|
123 |
|
|
124 |
public: //data
|
|
125 |
// pointer to beginning of text
|
|
126 |
TText8* iStorage;
|
|
127 |
// length of storage
|
|
128 |
TUint32 iLength;
|
|
129 |
// number of character
|
|
130 |
TUint32 iNumChars;
|
|
131 |
};
|
|
132 |
// CLASS DECLARATION
|
|
133 |
|
|
134 |
/**
|
|
135 |
* This class is the lexer for CSS syntax
|
|
136 |
* @lib css.lib
|
|
137 |
* @since 2.1
|
|
138 |
*/
|
|
139 |
class TCSSReader
|
|
140 |
{
|
|
141 |
public:
|
|
142 |
// constructor
|
|
143 |
TCSSReader(TText8* aBuffer, TUint32 aLength, TUint32 aEncoding)
|
|
144 |
{
|
|
145 |
iBuffer = aBuffer;
|
|
146 |
iLength = aLength;
|
|
147 |
iEncoding = aEncoding;
|
|
148 |
iPosition = 0;
|
|
149 |
}
|
|
150 |
|
|
151 |
TCSSReader()
|
|
152 |
{
|
|
153 |
iBuffer = NULL;
|
|
154 |
iLength = 0;
|
|
155 |
iEncoding = 0;
|
|
156 |
iPosition = 0;
|
|
157 |
}
|
|
158 |
|
|
159 |
void Init(TText8* aBuffer, TUint32 aLength, TUint32 aEncoding)
|
|
160 |
{
|
|
161 |
iBuffer = aBuffer;
|
|
162 |
iLength = aLength;
|
|
163 |
iEncoding = aEncoding;
|
|
164 |
iPosition = 0;
|
|
165 |
}
|
|
166 |
|
|
167 |
/**
|
|
168 |
* Skips white space as defined by CSS2 Spec
|
|
169 |
* @since 2.1
|
|
170 |
* return void
|
|
171 |
*/
|
|
172 |
void SkipWhiteSpaces();
|
|
173 |
|
|
174 |
/**
|
|
175 |
* Finds if the media type is valid (all or handheld)
|
|
176 |
* @since 2.1
|
|
177 |
* @param aMedia: media to be evaluated
|
|
178 |
* return ETrue if media is valid else EFalse
|
|
179 |
*/
|
|
180 |
TBool IsValidMedia(TCSSReaderUnit* aMedia);
|
|
181 |
|
|
182 |
TInt8 ReadNextToken(TCSSReaderUnit* aStr);
|
|
183 |
|
|
184 |
TInt8 GetPseudoClass();
|
|
185 |
|
|
186 |
TInt8 ReadNumberToken(TCSSReaderUnit* aStr);
|
|
187 |
|
|
188 |
TBool ReadIdentifier(TCSSReaderUnit* aStr);
|
|
189 |
|
|
190 |
TBool ReadString(TCSSReaderUnit* aStr);
|
|
191 |
|
|
192 |
TBool ReadName(TCSSReaderUnit* aStr);
|
|
193 |
|
|
194 |
TBool ReadURI(TCSSReaderUnit* aStr);
|
|
195 |
|
|
196 |
TBool ReadCharset();
|
|
197 |
|
|
198 |
TBrowserStatusCode GoToToken(TUint8 aTokenType, TText8** aPosition);
|
|
199 |
|
|
200 |
/**
|
|
201 |
* Ignores the At-rule of CSS starting at given position
|
|
202 |
* @since 2.1
|
|
203 |
* @param aPosition - starting of At-Rule
|
|
204 |
* return void
|
|
205 |
*/
|
|
206 |
TBool IgnoreAtRule(TUint32 aPosition);
|
|
207 |
|
|
208 |
/**
|
|
209 |
* Sets position of the reader
|
|
210 |
* @since 2.1
|
|
211 |
* @param aPosition - position of reader
|
|
212 |
* return void
|
|
213 |
*/
|
|
214 |
inline void SetPosition(TUint32 aPosition){iPosition = aPosition;}
|
|
215 |
|
|
216 |
/**
|
|
217 |
* Returns pointer to the buffer
|
|
218 |
* @since 2.1
|
|
219 |
* return pointer to the buffer
|
|
220 |
*/
|
|
221 |
inline TText8* GetBuffer(){return iBuffer;}
|
|
222 |
|
|
223 |
/**
|
|
224 |
* Returns length of buffer
|
|
225 |
* @since 2.1
|
|
226 |
* return length of buffer
|
|
227 |
*/
|
|
228 |
inline TUint32 GetLength(){return iLength;}
|
|
229 |
|
|
230 |
/**
|
|
231 |
* Returns current position of reader
|
|
232 |
* @since 2.1
|
|
233 |
* return current position of reader
|
|
234 |
*/
|
|
235 |
inline TUint32 GetPosition(){return iPosition;}
|
|
236 |
|
|
237 |
/**
|
|
238 |
* Returns encoding of buffer
|
|
239 |
* @since 2.1
|
|
240 |
* return encoding of buffer
|
|
241 |
*/
|
|
242 |
inline TUint32 GetEncoding(){return iEncoding;}
|
|
243 |
|
|
244 |
/**
|
|
245 |
* Advances the buffer by certain number of bytes
|
|
246 |
* @since 2.1
|
|
247 |
* @param aNumBytes - number of bytes to advance
|
|
248 |
* return void
|
|
249 |
*/
|
|
250 |
TBool Advance(TUint32 aNumBytes);
|
|
251 |
|
|
252 |
/**
|
|
253 |
* Sets encoding of the document
|
|
254 |
* @since 2.1
|
|
255 |
* @param aEncoding - encoding of buffer
|
|
256 |
* return void
|
|
257 |
*/
|
|
258 |
inline void SetEncoding(TUint32 aEncoding){iEncoding = aEncoding;}
|
|
259 |
|
|
260 |
/**
|
|
261 |
* Returns pointer to the buffer storage where reader is positioned
|
|
262 |
* @since 2.1
|
|
263 |
* return pointer to the buffer storage where reader is positioned
|
|
264 |
*/
|
|
265 |
inline TText8* GetBufferPointer(){return (iBuffer+iPosition);}
|
|
266 |
|
|
267 |
/**
|
|
268 |
* Gets the encoding associated with the text
|
|
269 |
* @since 2.1
|
|
270 |
* return encoding of the document being parsed
|
|
271 |
*/
|
|
272 |
TUint32 GetCharsetVal();
|
|
273 |
|
|
274 |
/**
|
|
275 |
* Reads a character
|
|
276 |
* @since 2.1
|
|
277 |
* return encoding of the document being parsed
|
|
278 |
*/
|
|
279 |
TInt32 ReadChar(TText16* aChar);
|
|
280 |
|
|
281 |
TUint16 ReadEscape(TText16* aOutChar);
|
|
282 |
|
|
283 |
private: // Functions
|
|
284 |
|
|
285 |
TBool Equals(const TText16* aStr, TBool aCaseInsensitive);
|
|
286 |
|
|
287 |
TBool ReadBlock(TText16 aClosingChar);
|
|
288 |
|
|
289 |
private: // Data
|
|
290 |
|
|
291 |
// pointer to the CSS buffer
|
|
292 |
TText8* iBuffer;
|
|
293 |
// length of buffer
|
|
294 |
TUint32 iLength;
|
|
295 |
// encoding of buffer
|
|
296 |
TUint32 iEncoding;
|
|
297 |
// position in the buffer
|
|
298 |
TUint32 iPosition;
|
|
299 |
};
|
|
300 |
|
|
301 |
#endif /* TCSSReader_H */
|
|
302 |
|