sl@0
|
1 |
// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32\euser\us_lex16.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "us_std.h"
|
sl@0
|
19 |
|
sl@0
|
20 |
|
sl@0
|
21 |
|
sl@0
|
22 |
|
sl@0
|
23 |
EXPORT_C TLex16::TLex16()
|
sl@0
|
24 |
: iNext(NULL),iBuf(NULL),iEnd(NULL),iMark(NULL)
|
sl@0
|
25 |
/**
|
sl@0
|
26 |
Default cosntructor.
|
sl@0
|
27 |
|
sl@0
|
28 |
Constructs a TLex16, initialising its members to NULL.
|
sl@0
|
29 |
*/
|
sl@0
|
30 |
{}
|
sl@0
|
31 |
|
sl@0
|
32 |
|
sl@0
|
33 |
|
sl@0
|
34 |
|
sl@0
|
35 |
EXPORT_C void TLex16::Assign(const TUint16 *aString)
|
sl@0
|
36 |
/**
|
sl@0
|
37 |
Assigns a string to this object from another string.
|
sl@0
|
38 |
|
sl@0
|
39 |
@param aString A pointer to a string to be assigned.
|
sl@0
|
40 |
*/
|
sl@0
|
41 |
{
|
sl@0
|
42 |
|
sl@0
|
43 |
iMark.iPtr=iNext=iBuf=aString;
|
sl@0
|
44 |
iEnd=iBuf+User::StringLength(aString);
|
sl@0
|
45 |
}
|
sl@0
|
46 |
|
sl@0
|
47 |
|
sl@0
|
48 |
|
sl@0
|
49 |
|
sl@0
|
50 |
EXPORT_C void TLex16::Assign(const TDesC16 &aDes)
|
sl@0
|
51 |
/**
|
sl@0
|
52 |
Assigns a string to this object from a descriptor.
|
sl@0
|
53 |
|
sl@0
|
54 |
@param aDes The descriptor to be assigned.
|
sl@0
|
55 |
*/
|
sl@0
|
56 |
{
|
sl@0
|
57 |
|
sl@0
|
58 |
iMark.iPtr=iNext=iBuf=aDes.Ptr();
|
sl@0
|
59 |
iEnd=iBuf+aDes.Length();
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
|
sl@0
|
63 |
|
sl@0
|
64 |
|
sl@0
|
65 |
EXPORT_C void TLex16::UnGet()
|
sl@0
|
66 |
/**
|
sl@0
|
67 |
Decrements the next character position, allowing the previously "got" character
|
sl@0
|
68 |
to be re-read.
|
sl@0
|
69 |
|
sl@0
|
70 |
@panic USER 64, if the previous character is before the start of the string.
|
sl@0
|
71 |
*/
|
sl@0
|
72 |
{
|
sl@0
|
73 |
|
sl@0
|
74 |
__ASSERT_ALWAYS(iNext>iBuf,Panic(ETLex16UnGetUnderflow));
|
sl@0
|
75 |
iNext--;
|
sl@0
|
76 |
}
|
sl@0
|
77 |
|
sl@0
|
78 |
|
sl@0
|
79 |
|
sl@0
|
80 |
|
sl@0
|
81 |
EXPORT_C void TLex16::UnGetToMark(const TLexMark16 aMark)
|
sl@0
|
82 |
/**
|
sl@0
|
83 |
Sets the next character position to the supplied extraction mark position.
|
sl@0
|
84 |
|
sl@0
|
85 |
@param aMark Mark to copy to the next character position.
|
sl@0
|
86 |
|
sl@0
|
87 |
@panic USER 68, if the extraction mark is before the start or beyond the end
|
sl@0
|
88 |
of the string.
|
sl@0
|
89 |
*/
|
sl@0
|
90 |
{
|
sl@0
|
91 |
|
sl@0
|
92 |
ValidateMark(aMark);
|
sl@0
|
93 |
iNext=aMark.iPtr;
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
|
sl@0
|
97 |
|
sl@0
|
98 |
|
sl@0
|
99 |
EXPORT_C void TLex16::Inc(TInt aNumber)
|
sl@0
|
100 |
/**
|
sl@0
|
101 |
Increments the next character position by aNumber.
|
sl@0
|
102 |
|
sl@0
|
103 |
@param aNumber The number of characters to increment the next character
|
sl@0
|
104 |
position by.
|
sl@0
|
105 |
|
sl@0
|
106 |
@panic USER 65, if the increment puts the next character position before the
|
sl@0
|
107 |
start or beyond the end of the string.
|
sl@0
|
108 |
*/
|
sl@0
|
109 |
{
|
sl@0
|
110 |
|
sl@0
|
111 |
iNext+=aNumber;
|
sl@0
|
112 |
__ASSERT_ALWAYS(iNext>=iBuf && iNext<=iEnd,Panic(ETLex16IncOutOfRange));
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
|
sl@0
|
116 |
|
sl@0
|
117 |
|
sl@0
|
118 |
EXPORT_C void TLex16::Inc()
|
sl@0
|
119 |
/**
|
sl@0
|
120 |
Increments to the next character position.
|
sl@0
|
121 |
|
sl@0
|
122 |
@panic USER 65, if the increment puts the next character position before the
|
sl@0
|
123 |
start or beyond the end of the string.
|
sl@0
|
124 |
*/
|
sl@0
|
125 |
{
|
sl@0
|
126 |
|
sl@0
|
127 |
if (!Eos())
|
sl@0
|
128 |
iNext++;
|
sl@0
|
129 |
__ASSERT_ALWAYS(iNext<=iEnd,Panic(ETLex16IncOutOfRange));
|
sl@0
|
130 |
}
|
sl@0
|
131 |
|
sl@0
|
132 |
|
sl@0
|
133 |
|
sl@0
|
134 |
|
sl@0
|
135 |
EXPORT_C TChar TLex16::Get()
|
sl@0
|
136 |
/**
|
sl@0
|
137 |
Gets the next character in the string and increments the next
|
sl@0
|
138 |
character position.
|
sl@0
|
139 |
|
sl@0
|
140 |
@return Next character to be read. 0 if at the end of the string.
|
sl@0
|
141 |
*/
|
sl@0
|
142 |
{
|
sl@0
|
143 |
|
sl@0
|
144 |
if (Eos())
|
sl@0
|
145 |
return(0);
|
sl@0
|
146 |
return(*iNext++);
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
|
sl@0
|
150 |
|
sl@0
|
151 |
|
sl@0
|
152 |
EXPORT_C TChar TLex16::Peek() const
|
sl@0
|
153 |
/**
|
sl@0
|
154 |
Shows the next character to be returned by Get().
|
sl@0
|
155 |
|
sl@0
|
156 |
@return Character to be returned by the next call to Get(). 0 if at the end of the
|
sl@0
|
157 |
string.
|
sl@0
|
158 |
|
sl@0
|
159 |
@see TLex16::Get
|
sl@0
|
160 |
*/
|
sl@0
|
161 |
{
|
sl@0
|
162 |
|
sl@0
|
163 |
if (Eos())
|
sl@0
|
164 |
return(0);
|
sl@0
|
165 |
return(*iNext);
|
sl@0
|
166 |
}
|
sl@0
|
167 |
|
sl@0
|
168 |
|
sl@0
|
169 |
|
sl@0
|
170 |
|
sl@0
|
171 |
EXPORT_C void TLex16::SkipSpace()
|
sl@0
|
172 |
/**
|
sl@0
|
173 |
Moves the next character position past any white space (space or separator).
|
sl@0
|
174 |
|
sl@0
|
175 |
Stops if at the end of string.
|
sl@0
|
176 |
*/
|
sl@0
|
177 |
{
|
sl@0
|
178 |
|
sl@0
|
179 |
while (!Eos() && Peek().IsSpace())
|
sl@0
|
180 |
iNext++;
|
sl@0
|
181 |
}
|
sl@0
|
182 |
|
sl@0
|
183 |
|
sl@0
|
184 |
|
sl@0
|
185 |
|
sl@0
|
186 |
EXPORT_C void TLex16::SkipAndMark(TInt aNumber,TLexMark16& aMark)
|
sl@0
|
187 |
/**
|
sl@0
|
188 |
Moves the next character position a specified number of characters and copies
|
sl@0
|
189 |
it to the specified extraction mark.
|
sl@0
|
190 |
|
sl@0
|
191 |
@param aNumber Number of characters to skip.
|
sl@0
|
192 |
@param aMark On return, set to the next character position.
|
sl@0
|
193 |
|
sl@0
|
194 |
@panic USER 66, if the skip moves the next character position either to before
|
sl@0
|
195 |
the start or beyond the end of the string.
|
sl@0
|
196 |
*/
|
sl@0
|
197 |
{
|
sl@0
|
198 |
|
sl@0
|
199 |
iNext+=aNumber;
|
sl@0
|
200 |
__ASSERT_ALWAYS(iNext>=iBuf && iNext<=iEnd,Panic(ETLex16SkipOutOfRange));
|
sl@0
|
201 |
Mark(aMark);
|
sl@0
|
202 |
}
|
sl@0
|
203 |
|
sl@0
|
204 |
|
sl@0
|
205 |
|
sl@0
|
206 |
|
sl@0
|
207 |
EXPORT_C void TLex16::SkipSpaceAndMark(TLexMark16& aMark)
|
sl@0
|
208 |
/**
|
sl@0
|
209 |
Moves the next character position past any white space and copies it to the
|
sl@0
|
210 |
specified extraction mark.
|
sl@0
|
211 |
|
sl@0
|
212 |
Stops if at the end of the string.
|
sl@0
|
213 |
|
sl@0
|
214 |
@param aMark On return, contains a reference to the next character position.
|
sl@0
|
215 |
*/
|
sl@0
|
216 |
{
|
sl@0
|
217 |
|
sl@0
|
218 |
SkipSpace();
|
sl@0
|
219 |
Mark(aMark);
|
sl@0
|
220 |
}
|
sl@0
|
221 |
|
sl@0
|
222 |
|
sl@0
|
223 |
|
sl@0
|
224 |
|
sl@0
|
225 |
EXPORT_C void TLex16::SkipCharacters()
|
sl@0
|
226 |
/**
|
sl@0
|
227 |
Moves the next character position to the next white space (space or separator).
|
sl@0
|
228 |
|
sl@0
|
229 |
Stops if at the end of the string.
|
sl@0
|
230 |
*/
|
sl@0
|
231 |
{
|
sl@0
|
232 |
|
sl@0
|
233 |
while (!Eos() && !Peek().IsSpace())
|
sl@0
|
234 |
iNext++;
|
sl@0
|
235 |
}
|
sl@0
|
236 |
|
sl@0
|
237 |
|
sl@0
|
238 |
|
sl@0
|
239 |
|
sl@0
|
240 |
EXPORT_C TInt TLex16::TokenLength(const TLexMark16 aMark) const
|
sl@0
|
241 |
/**
|
sl@0
|
242 |
Gets the length of the token starting at the specified extraction mark.
|
sl@0
|
243 |
|
sl@0
|
244 |
@param aMark Extraction mark indicating the start of the token.
|
sl@0
|
245 |
|
sl@0
|
246 |
@return Length of the token.
|
sl@0
|
247 |
|
sl@0
|
248 |
@panic USER 68, if the specified mark is before the start or beyond the end
|
sl@0
|
249 |
of the string.
|
sl@0
|
250 |
*/
|
sl@0
|
251 |
{
|
sl@0
|
252 |
|
sl@0
|
253 |
ValidateMark(aMark);
|
sl@0
|
254 |
return (iNext-aMark.iPtr);
|
sl@0
|
255 |
}
|
sl@0
|
256 |
|
sl@0
|
257 |
|
sl@0
|
258 |
|
sl@0
|
259 |
|
sl@0
|
260 |
EXPORT_C TPtrC16 TLex16::MarkedToken(const TLexMark16 aMark) const
|
sl@0
|
261 |
/**
|
sl@0
|
262 |
Extracts the token, starting at the specified mark
|
sl@0
|
263 |
|
sl@0
|
264 |
@param aMark Extraction mark indicating the start of the token.
|
sl@0
|
265 |
|
sl@0
|
266 |
@return Extracted token.
|
sl@0
|
267 |
|
sl@0
|
268 |
@panic USER 68, if the specified mark is before the start or beyond the end
|
sl@0
|
269 |
of the string.
|
sl@0
|
270 |
*/
|
sl@0
|
271 |
{
|
sl@0
|
272 |
|
sl@0
|
273 |
return(TPtrC16(aMark.iPtr,TokenLength(aMark)));
|
sl@0
|
274 |
}
|
sl@0
|
275 |
|
sl@0
|
276 |
|
sl@0
|
277 |
|
sl@0
|
278 |
|
sl@0
|
279 |
EXPORT_C TPtrC16 TLex16::MarkedToken() const
|
sl@0
|
280 |
//
|
sl@0
|
281 |
// Extract the internally marked token
|
sl@0
|
282 |
// there is the assumption here that iMark is always valid
|
sl@0
|
283 |
/**
|
sl@0
|
284 |
Extracts the marked token.
|
sl@0
|
285 |
|
sl@0
|
286 |
Note that the function assumes that the current extraction mark is valid.
|
sl@0
|
287 |
|
sl@0
|
288 |
@return Extracted token.
|
sl@0
|
289 |
|
sl@0
|
290 |
@panic USER 68, if the specified mark is before the start or beyond the end
|
sl@0
|
291 |
of the string.
|
sl@0
|
292 |
*/
|
sl@0
|
293 |
{
|
sl@0
|
294 |
|
sl@0
|
295 |
return(TPtrC16(iMark.iPtr,TokenLength()));
|
sl@0
|
296 |
}
|
sl@0
|
297 |
|
sl@0
|
298 |
|
sl@0
|
299 |
|
sl@0
|
300 |
|
sl@0
|
301 |
EXPORT_C TPtrC16 TLex16::NextToken()
|
sl@0
|
302 |
/**
|
sl@0
|
303 |
Strips any white space and extracts the next token.
|
sl@0
|
304 |
|
sl@0
|
305 |
@return Extracted token.
|
sl@0
|
306 |
*/
|
sl@0
|
307 |
{
|
sl@0
|
308 |
TLexMark16 mark;
|
sl@0
|
309 |
|
sl@0
|
310 |
SkipSpaceAndMark(mark);
|
sl@0
|
311 |
SkipCharacters();
|
sl@0
|
312 |
return(TPtrC16(mark.iPtr,iNext-mark.iPtr));
|
sl@0
|
313 |
}
|
sl@0
|
314 |
|
sl@0
|
315 |
|
sl@0
|
316 |
|
sl@0
|
317 |
|
sl@0
|
318 |
EXPORT_C TPtrC16 TLex16::Remainder() const
|
sl@0
|
319 |
/**
|
sl@0
|
320 |
Gets a descriptor containing all the text from the next character position
|
sl@0
|
321 |
to the end of the string.
|
sl@0
|
322 |
|
sl@0
|
323 |
@return Text from the next character position onwards.
|
sl@0
|
324 |
|
sl@0
|
325 |
@panic USER 17, if the value of (next character position - extraction mark) is
|
sl@0
|
326 |
negative.
|
sl@0
|
327 |
*/
|
sl@0
|
328 |
{
|
sl@0
|
329 |
|
sl@0
|
330 |
return(TPtrC16(iNext,iEnd-iNext));
|
sl@0
|
331 |
}
|
sl@0
|
332 |
|
sl@0
|
333 |
|
sl@0
|
334 |
|
sl@0
|
335 |
|
sl@0
|
336 |
EXPORT_C TPtrC16 TLex16::RemainderFromMark(const TLexMark16 aMark) const
|
sl@0
|
337 |
/**
|
sl@0
|
338 |
Gets a descriptor containing all the text from the specified extraction mark
|
sl@0
|
339 |
to the end of the string.
|
sl@0
|
340 |
|
sl@0
|
341 |
@param aMark Extraction mark indicating where remaining text starts.
|
sl@0
|
342 |
|
sl@0
|
343 |
@return Text from the specified extraction mark onwards.
|
sl@0
|
344 |
|
sl@0
|
345 |
@panic USER 17, if the value of (next character position - extraction mark) is
|
sl@0
|
346 |
negative.
|
sl@0
|
347 |
@panic USER 68, if the specified mark is before the start or beyond the end
|
sl@0
|
348 |
of the string.
|
sl@0
|
349 |
*/
|
sl@0
|
350 |
{
|
sl@0
|
351 |
|
sl@0
|
352 |
ValidateMark(aMark);
|
sl@0
|
353 |
return(TPtrC16(aMark.iPtr,iEnd-aMark.iPtr));
|
sl@0
|
354 |
}
|
sl@0
|
355 |
|
sl@0
|
356 |
|
sl@0
|
357 |
|
sl@0
|
358 |
|
sl@0
|
359 |
EXPORT_C TPtrC16 TLex16::RemainderFromMark() const
|
sl@0
|
360 |
//
|
sl@0
|
361 |
// Return the remainder from iMark
|
sl@0
|
362 |
// There is an assumption here that the internal mark will always be valid
|
sl@0
|
363 |
//
|
sl@0
|
364 |
/**
|
sl@0
|
365 |
Gets a descriptor containing all the text from the extraction mark to the end
|
sl@0
|
366 |
of the string.
|
sl@0
|
367 |
|
sl@0
|
368 |
The function assumes that the current extraction mark is valid.
|
sl@0
|
369 |
|
sl@0
|
370 |
@return Text from the extraction mark onwards.
|
sl@0
|
371 |
*/
|
sl@0
|
372 |
{
|
sl@0
|
373 |
|
sl@0
|
374 |
return(TPtrC16(iMark.iPtr,iEnd-iMark.iPtr));
|
sl@0
|
375 |
}
|
sl@0
|
376 |
|
sl@0
|
377 |
|
sl@0
|
378 |
|
sl@0
|
379 |
|
sl@0
|
380 |
EXPORT_C TInt TLex16::Offset() const
|
sl@0
|
381 |
//
|
sl@0
|
382 |
// Return the offset from iNext to the lex start.
|
sl@0
|
383 |
//
|
sl@0
|
384 |
/**
|
sl@0
|
385 |
Gets the offset of the next character position from the start of the string.
|
sl@0
|
386 |
|
sl@0
|
387 |
@return Offset of next character position.
|
sl@0
|
388 |
*/
|
sl@0
|
389 |
{
|
sl@0
|
390 |
|
sl@0
|
391 |
return((TUint)(iNext-iBuf));
|
sl@0
|
392 |
}
|
sl@0
|
393 |
|
sl@0
|
394 |
|
sl@0
|
395 |
|
sl@0
|
396 |
|
sl@0
|
397 |
EXPORT_C TInt TLex16::MarkedOffset(const TLexMark16 aMark) const
|
sl@0
|
398 |
/**
|
sl@0
|
399 |
Gets the offset of the specified extraction mark from the start of the string.
|
sl@0
|
400 |
|
sl@0
|
401 |
@param aMark Extraction mark.
|
sl@0
|
402 |
|
sl@0
|
403 |
@return The offset of the extraction mark.
|
sl@0
|
404 |
|
sl@0
|
405 |
@panic USER 68, if the specified mark is before the start or beyond the end
|
sl@0
|
406 |
of the string.
|
sl@0
|
407 |
*/
|
sl@0
|
408 |
{
|
sl@0
|
409 |
|
sl@0
|
410 |
ValidateMark(aMark);
|
sl@0
|
411 |
return((TUint)(aMark.iPtr-iBuf));
|
sl@0
|
412 |
}
|
sl@0
|
413 |
|
sl@0
|
414 |
|
sl@0
|
415 |
|
sl@0
|
416 |
|
sl@0
|
417 |
EXPORT_C TInt TLex16::BoundedVal(TUint32 &aVal,TRadix aRadix,TUint aLimit)
|
sl@0
|
418 |
/**
|
sl@0
|
419 |
Parses the string to extract a 32-bit unsigned integer, using the
|
sl@0
|
420 |
specified radix, and checks that it is within the specified limit.
|
sl@0
|
421 |
|
sl@0
|
422 |
The specified radix is one of binary, octal, decimal, or hexadecimal.
|
sl@0
|
423 |
|
sl@0
|
424 |
@param aVal On return, contains the extracted integer.
|
sl@0
|
425 |
@param aRadix The radix to use when converting the number.
|
sl@0
|
426 |
@param aLimit The upper limit.
|
sl@0
|
427 |
|
sl@0
|
428 |
@return KErrNone if successful.
|
sl@0
|
429 |
KErrGeneral if the next character position is initially at the end of the string
|
sl@0
|
430 |
or no valid characters found initially.
|
sl@0
|
431 |
KErrOverflow if there is sign overflow, i.e. converted value greater than limit.
|
sl@0
|
432 |
If error codes KErrGeneral or KErrOverflow are returned, the object's
|
sl@0
|
433 |
members are left unaltered.
|
sl@0
|
434 |
*/
|
sl@0
|
435 |
{
|
sl@0
|
436 |
|
sl@0
|
437 |
TUint l=aLimit/aRadix;
|
sl@0
|
438 |
TUint v=0;
|
sl@0
|
439 |
TUint d=0;
|
sl@0
|
440 |
TLexMark16 mark(iNext);
|
sl@0
|
441 |
while (!Eos())
|
sl@0
|
442 |
{
|
sl@0
|
443 |
TChar c=Peek();
|
sl@0
|
444 |
if (!c.IsHexDigit())
|
sl@0
|
445 |
break;
|
sl@0
|
446 |
c=Get();
|
sl@0
|
447 |
if (c.IsAlpha())
|
sl@0
|
448 |
{
|
sl@0
|
449 |
c.UpperCase();
|
sl@0
|
450 |
c-=('A'-10);
|
sl@0
|
451 |
}
|
sl@0
|
452 |
else
|
sl@0
|
453 |
c-='0';
|
sl@0
|
454 |
if (c>=(TUint)aRadix)
|
sl@0
|
455 |
{
|
sl@0
|
456 |
iNext--;
|
sl@0
|
457 |
break;
|
sl@0
|
458 |
}
|
sl@0
|
459 |
if (v>l)
|
sl@0
|
460 |
{
|
sl@0
|
461 |
UnGetToMark(mark);
|
sl@0
|
462 |
return(KErrOverflow);
|
sl@0
|
463 |
}
|
sl@0
|
464 |
TUint o=v;
|
sl@0
|
465 |
v*=aRadix;
|
sl@0
|
466 |
v+=c;
|
sl@0
|
467 |
if (o>v)
|
sl@0
|
468 |
{
|
sl@0
|
469 |
UnGetToMark(mark);
|
sl@0
|
470 |
return(KErrOverflow);
|
sl@0
|
471 |
}
|
sl@0
|
472 |
d++;
|
sl@0
|
473 |
}
|
sl@0
|
474 |
if (d==0)
|
sl@0
|
475 |
{
|
sl@0
|
476 |
UnGetToMark(mark);
|
sl@0
|
477 |
return(KErrGeneral);
|
sl@0
|
478 |
}
|
sl@0
|
479 |
if (v>aLimit)
|
sl@0
|
480 |
{
|
sl@0
|
481 |
UnGetToMark(mark);
|
sl@0
|
482 |
return(KErrOverflow);
|
sl@0
|
483 |
}
|
sl@0
|
484 |
aVal=v;
|
sl@0
|
485 |
return(KErrNone);
|
sl@0
|
486 |
}
|
sl@0
|
487 |
|
sl@0
|
488 |
|
sl@0
|
489 |
|
sl@0
|
490 |
|
sl@0
|
491 |
EXPORT_C TInt TLex16::BoundedVal(TInt32 &aVal,TInt aLimit)
|
sl@0
|
492 |
/**
|
sl@0
|
493 |
Parses the string to extract a 32-bit signed integer, and checks that it is
|
sl@0
|
494 |
within the specified limit.
|
sl@0
|
495 |
|
sl@0
|
496 |
@param aVal On return, contains the extracted integer.
|
sl@0
|
497 |
@param aLimit The upper limit.
|
sl@0
|
498 |
|
sl@0
|
499 |
@return KErrNone if successful.
|
sl@0
|
500 |
KErrGeneral if the next character position is initially at the end of the string
|
sl@0
|
501 |
or no valid characters found initially.
|
sl@0
|
502 |
KErrOverflow if there is sign overflow, i.e. converted value greater than limit.
|
sl@0
|
503 |
If error codes KErrGeneral or KErrOverflow are returned, the object's
|
sl@0
|
504 |
members are left unaltered.
|
sl@0
|
505 |
*/
|
sl@0
|
506 |
{
|
sl@0
|
507 |
|
sl@0
|
508 |
if (Eos())
|
sl@0
|
509 |
return(KErrGeneral);
|
sl@0
|
510 |
TUint lim=aLimit;
|
sl@0
|
511 |
TLexMark16 mark(iNext);
|
sl@0
|
512 |
TUint s=FALSE;
|
sl@0
|
513 |
TChar c=Peek();
|
sl@0
|
514 |
if (c=='-')
|
sl@0
|
515 |
{
|
sl@0
|
516 |
lim++;
|
sl@0
|
517 |
s++;
|
sl@0
|
518 |
Inc();
|
sl@0
|
519 |
}
|
sl@0
|
520 |
else if (c=='+')
|
sl@0
|
521 |
Inc();
|
sl@0
|
522 |
TUint32 v;
|
sl@0
|
523 |
TInt r=BoundedVal(v,EDecimal,lim);
|
sl@0
|
524 |
if (r==KErrNone)
|
sl@0
|
525 |
{
|
sl@0
|
526 |
if (v>lim)
|
sl@0
|
527 |
r=KErrOverflow;
|
sl@0
|
528 |
else if (s)
|
sl@0
|
529 |
aVal=(-((TInt32)v));
|
sl@0
|
530 |
else
|
sl@0
|
531 |
aVal=v;
|
sl@0
|
532 |
}
|
sl@0
|
533 |
if (r!=KErrNone)
|
sl@0
|
534 |
UnGetToMark(mark);
|
sl@0
|
535 |
return(r);
|
sl@0
|
536 |
}
|
sl@0
|
537 |
|
sl@0
|
538 |
|
sl@0
|
539 |
|
sl@0
|
540 |
|
sl@0
|
541 |
EXPORT_C TInt TLex16::BoundedVal(TInt64& aVal, TRadix aRadix, const TInt64& aLimit)
|
sl@0
|
542 |
/**
|
sl@0
|
543 |
Parses the string to extract a 64-bit signed integer, using the
|
sl@0
|
544 |
specified radix, and checks that it is within the specified limit.
|
sl@0
|
545 |
|
sl@0
|
546 |
The specified radix is one of binary, octal, decimal, or hexadecimal.
|
sl@0
|
547 |
|
sl@0
|
548 |
@param aVal On return, contains the extracted integer.
|
sl@0
|
549 |
@param aRadix The radix to use when converting the number.
|
sl@0
|
550 |
@param aLimit The upper limit.
|
sl@0
|
551 |
|
sl@0
|
552 |
@return KErrNone if successful.
|
sl@0
|
553 |
KErrGeneral if the next character position is initially at the end of the string
|
sl@0
|
554 |
or no valid characters found initially.
|
sl@0
|
555 |
KErrOverflow if there is sign overflow, i.e. converted value greater than limit.
|
sl@0
|
556 |
If error codes KErrGeneral or KErrOverflow are returned, the object's
|
sl@0
|
557 |
members are left unaltered.
|
sl@0
|
558 |
*/
|
sl@0
|
559 |
{
|
sl@0
|
560 |
TUint64 rad = aRadix;
|
sl@0
|
561 |
TUint64 lim = static_cast<TUint64>(aLimit);
|
sl@0
|
562 |
|
sl@0
|
563 |
lim /= rad;
|
sl@0
|
564 |
|
sl@0
|
565 |
TUint64 v = 0;
|
sl@0
|
566 |
TUint digit=0;
|
sl@0
|
567 |
TLexMark16 mark(iNext);
|
sl@0
|
568 |
while (!Eos())
|
sl@0
|
569 |
{
|
sl@0
|
570 |
TChar c=Peek();
|
sl@0
|
571 |
if (!c.IsHexDigit())
|
sl@0
|
572 |
break;
|
sl@0
|
573 |
c=Get();
|
sl@0
|
574 |
if (c.IsAlpha())
|
sl@0
|
575 |
{
|
sl@0
|
576 |
c.UpperCase();
|
sl@0
|
577 |
c-=('A'-10);
|
sl@0
|
578 |
}
|
sl@0
|
579 |
else
|
sl@0
|
580 |
c-='0';
|
sl@0
|
581 |
if (c >= rad)
|
sl@0
|
582 |
{
|
sl@0
|
583 |
iNext--;
|
sl@0
|
584 |
break;
|
sl@0
|
585 |
}
|
sl@0
|
586 |
if (v > lim)
|
sl@0
|
587 |
{
|
sl@0
|
588 |
UnGetToMark(mark);
|
sl@0
|
589 |
return(KErrOverflow);
|
sl@0
|
590 |
}
|
sl@0
|
591 |
TUint64 old = v;
|
sl@0
|
592 |
v*=rad;
|
sl@0
|
593 |
v+=c;
|
sl@0
|
594 |
if (old > v)
|
sl@0
|
595 |
{
|
sl@0
|
596 |
UnGetToMark(mark);
|
sl@0
|
597 |
return(KErrOverflow);
|
sl@0
|
598 |
}
|
sl@0
|
599 |
digit++;
|
sl@0
|
600 |
}
|
sl@0
|
601 |
if (digit==0)
|
sl@0
|
602 |
{
|
sl@0
|
603 |
UnGetToMark(mark);
|
sl@0
|
604 |
return(KErrGeneral);
|
sl@0
|
605 |
}
|
sl@0
|
606 |
if (v > static_cast<TUint64>(aLimit))
|
sl@0
|
607 |
{
|
sl@0
|
608 |
UnGetToMark(mark);
|
sl@0
|
609 |
return(KErrOverflow);
|
sl@0
|
610 |
}
|
sl@0
|
611 |
aVal = static_cast<TInt64>(v);
|
sl@0
|
612 |
return(KErrNone);
|
sl@0
|
613 |
}
|
sl@0
|
614 |
|
sl@0
|
615 |
|
sl@0
|
616 |
|
sl@0
|
617 |
|
sl@0
|
618 |
EXPORT_C TInt TLex16::BoundedVal(TInt64& aVal, const TInt64& aLimit)
|
sl@0
|
619 |
/**
|
sl@0
|
620 |
Parses the string to extract a 64-bit signed integer, and checks that it
|
sl@0
|
621 |
is within the specified limit.
|
sl@0
|
622 |
|
sl@0
|
623 |
@param aVal On return, contains the extracted integer.
|
sl@0
|
624 |
@param aLimit The upper limit.
|
sl@0
|
625 |
|
sl@0
|
626 |
@return KErrNone if successful.
|
sl@0
|
627 |
KErrGeneral if the next character position is initially at the end of the string
|
sl@0
|
628 |
or no valid characters found initially.
|
sl@0
|
629 |
KErrOverflow if there is sign overflow, i.e. converted value greater than limit.
|
sl@0
|
630 |
If error codes KErrGeneral or KErrOverflow are returned, the object's
|
sl@0
|
631 |
members are left unaltered.
|
sl@0
|
632 |
*/
|
sl@0
|
633 |
{
|
sl@0
|
634 |
|
sl@0
|
635 |
if (Eos())
|
sl@0
|
636 |
return(KErrGeneral);
|
sl@0
|
637 |
TInt64 lim = aLimit;
|
sl@0
|
638 |
TLexMark16 mark(iNext);
|
sl@0
|
639 |
TBool s=EFalse;
|
sl@0
|
640 |
TChar c=Peek();
|
sl@0
|
641 |
if (c=='-')
|
sl@0
|
642 |
{
|
sl@0
|
643 |
lim++;
|
sl@0
|
644 |
s++;
|
sl@0
|
645 |
Inc();
|
sl@0
|
646 |
}
|
sl@0
|
647 |
else if (c=='+')
|
sl@0
|
648 |
Inc();
|
sl@0
|
649 |
TInt64 v;
|
sl@0
|
650 |
TInt r=BoundedVal(v,EDecimal,lim);
|
sl@0
|
651 |
if (r==KErrNone)
|
sl@0
|
652 |
{
|
sl@0
|
653 |
if (v>lim)
|
sl@0
|
654 |
r=KErrOverflow;
|
sl@0
|
655 |
else if (s)
|
sl@0
|
656 |
aVal=(-v);
|
sl@0
|
657 |
else
|
sl@0
|
658 |
aVal=v;
|
sl@0
|
659 |
}
|
sl@0
|
660 |
if (r!=KErrNone)
|
sl@0
|
661 |
UnGetToMark(mark);
|
sl@0
|
662 |
return(r);
|
sl@0
|
663 |
}
|
sl@0
|
664 |
|
sl@0
|
665 |
|
sl@0
|
666 |
|
sl@0
|
667 |
|
sl@0
|
668 |
EXPORT_C TInt TLex16::Val(TInt8 &aVal)
|
sl@0
|
669 |
/**
|
sl@0
|
670 |
Parses the string to extract a signed 8-bit integer.
|
sl@0
|
671 |
|
sl@0
|
672 |
@param aVal On return, contains the extracted integer.
|
sl@0
|
673 |
|
sl@0
|
674 |
@return KErrNone if successful.
|
sl@0
|
675 |
KErrGeneral if the next character position is initially at the end of the string
|
sl@0
|
676 |
or no valid characters found initially.
|
sl@0
|
677 |
KErrOverflow if there is sign overflow, i.e. converted value greater than limit.
|
sl@0
|
678 |
If error codes KErrGeneral or KErrOverflow are returned, the object's
|
sl@0
|
679 |
members are left unaltered.
|
sl@0
|
680 |
*/
|
sl@0
|
681 |
{
|
sl@0
|
682 |
|
sl@0
|
683 |
TInt32 v;
|
sl@0
|
684 |
TInt r=BoundedVal(v,0x7fu);
|
sl@0
|
685 |
if (r==KErrNone)
|
sl@0
|
686 |
aVal=(TInt8)v;
|
sl@0
|
687 |
return(r);
|
sl@0
|
688 |
}
|
sl@0
|
689 |
|
sl@0
|
690 |
|
sl@0
|
691 |
|
sl@0
|
692 |
|
sl@0
|
693 |
EXPORT_C TInt TLex16::Val(TInt16 &aVal)
|
sl@0
|
694 |
/**
|
sl@0
|
695 |
Parses the string to extract a signed 16-bit integer.
|
sl@0
|
696 |
|
sl@0
|
697 |
@param aVal On return, contains the extracted integer.
|
sl@0
|
698 |
|
sl@0
|
699 |
@return KErrNone if successful.
|
sl@0
|
700 |
KErrGeneral if the next character position is initially at the end of the string
|
sl@0
|
701 |
or no valid characters found initially.
|
sl@0
|
702 |
KErrOverflow if there is sign overflow, i.e. converted value greater than limit.
|
sl@0
|
703 |
If error codes KErrGeneral or KErrOverflow are returned, the object's
|
sl@0
|
704 |
members are left unaltered.
|
sl@0
|
705 |
*/
|
sl@0
|
706 |
{
|
sl@0
|
707 |
|
sl@0
|
708 |
TInt32 v;
|
sl@0
|
709 |
TInt r=BoundedVal(v,0x7fffu);
|
sl@0
|
710 |
if (r==KErrNone)
|
sl@0
|
711 |
aVal=(TInt16)v;
|
sl@0
|
712 |
return(r);
|
sl@0
|
713 |
}
|
sl@0
|
714 |
|
sl@0
|
715 |
|
sl@0
|
716 |
|
sl@0
|
717 |
|
sl@0
|
718 |
EXPORT_C TInt TLex16::Val(TInt32 &aVal)
|
sl@0
|
719 |
/**
|
sl@0
|
720 |
Parses the string to extract a signed 32-bit integer.
|
sl@0
|
721 |
|
sl@0
|
722 |
@param aVal On return, contains the extracted integer.
|
sl@0
|
723 |
|
sl@0
|
724 |
@return KErrNone if successful.
|
sl@0
|
725 |
KErrGeneral if the next character position is initially at the end of the string
|
sl@0
|
726 |
or no valid characters found initially.
|
sl@0
|
727 |
KErrOverflow if there is sign overflow, i.e. converted value greater than limit.
|
sl@0
|
728 |
If error codes KErrGeneral or KErrOverflow are returned, the object's
|
sl@0
|
729 |
members are left unaltered.
|
sl@0
|
730 |
*/
|
sl@0
|
731 |
{
|
sl@0
|
732 |
|
sl@0
|
733 |
TInt32 v;
|
sl@0
|
734 |
TInt r=BoundedVal(v,0x7fffffffu);
|
sl@0
|
735 |
if (r==KErrNone)
|
sl@0
|
736 |
aVal=v;
|
sl@0
|
737 |
return(r);
|
sl@0
|
738 |
}
|
sl@0
|
739 |
|
sl@0
|
740 |
|
sl@0
|
741 |
|
sl@0
|
742 |
|
sl@0
|
743 |
EXPORT_C TInt TLex16::Val(TInt64& aVal)
|
sl@0
|
744 |
/**
|
sl@0
|
745 |
Parses the string to extract a signed 64-bit integer.
|
sl@0
|
746 |
|
sl@0
|
747 |
@param aVal On return, contains the extracted integer.
|
sl@0
|
748 |
|
sl@0
|
749 |
@return KErrNone if successful.
|
sl@0
|
750 |
KErrGeneral if the next character position is initially at the end of the string
|
sl@0
|
751 |
or no valid characters found initially.
|
sl@0
|
752 |
KErrOverflow if there is sign overflow, i.e. converted value greater than limit.
|
sl@0
|
753 |
If error codes KErrGeneral or KErrOverflow are returned, the object's
|
sl@0
|
754 |
members are left unaltered.
|
sl@0
|
755 |
*/
|
sl@0
|
756 |
{
|
sl@0
|
757 |
|
sl@0
|
758 |
TChar c=Peek();
|
sl@0
|
759 |
if (c=='-' || c=='+')
|
sl@0
|
760 |
Inc();
|
sl@0
|
761 |
TInt r;
|
sl@0
|
762 |
if (c=='-')
|
sl@0
|
763 |
{
|
sl@0
|
764 |
r=BoundedVal(aVal, EDecimal, UI64LIT(0x8000000000000000));
|
sl@0
|
765 |
if (r==KErrNone)
|
sl@0
|
766 |
aVal=-aVal;
|
sl@0
|
767 |
}
|
sl@0
|
768 |
else
|
sl@0
|
769 |
r=BoundedVal(aVal, UI64LIT(0x7fffffffffffffff));
|
sl@0
|
770 |
return(r);
|
sl@0
|
771 |
}
|
sl@0
|
772 |
|
sl@0
|
773 |
|
sl@0
|
774 |
|
sl@0
|
775 |
|
sl@0
|
776 |
EXPORT_C TInt TLex16::Val(TUint8 &aVal,TRadix aRadix)
|
sl@0
|
777 |
/**
|
sl@0
|
778 |
Parses the string to extract an 8-bit unsigned integer, using the
|
sl@0
|
779 |
specified radix.
|
sl@0
|
780 |
|
sl@0
|
781 |
The specified radix is one of binary, octal, decimal, or hexadecimal.
|
sl@0
|
782 |
|
sl@0
|
783 |
@param aVal On return, contains the extracted integer.
|
sl@0
|
784 |
@param aRadix The radix to use when converting the number.
|
sl@0
|
785 |
|
sl@0
|
786 |
@return KErrNone if successful.
|
sl@0
|
787 |
KErrGeneral if the next character position is initially at the end of the string
|
sl@0
|
788 |
or no valid characters found initially.
|
sl@0
|
789 |
KErrOverflow if there is sign overflow, i.e. converted value greater than limit.
|
sl@0
|
790 |
If error codes KErrGeneral or KErrOverflow are returned, the object's
|
sl@0
|
791 |
members are left unaltered.
|
sl@0
|
792 |
*/
|
sl@0
|
793 |
{
|
sl@0
|
794 |
|
sl@0
|
795 |
TUint32 v;
|
sl@0
|
796 |
TInt r=BoundedVal(v,aRadix,0xffu);
|
sl@0
|
797 |
if (r==KErrNone)
|
sl@0
|
798 |
aVal=(TUint8)v;
|
sl@0
|
799 |
return(r);
|
sl@0
|
800 |
}
|
sl@0
|
801 |
|
sl@0
|
802 |
|
sl@0
|
803 |
|
sl@0
|
804 |
|
sl@0
|
805 |
EXPORT_C TInt TLex16::Val(TUint16 &aVal,TRadix aRadix)
|
sl@0
|
806 |
/**
|
sl@0
|
807 |
Parses the string to extract a 16-bit unsigned integer, using the
|
sl@0
|
808 |
specified radix.
|
sl@0
|
809 |
|
sl@0
|
810 |
The specified radix is one of binary, octal, decimal, or hexadecimal.
|
sl@0
|
811 |
|
sl@0
|
812 |
@param aVal On return, contains the extracted integer.
|
sl@0
|
813 |
@param aRadix The radix to use when converting the number.
|
sl@0
|
814 |
|
sl@0
|
815 |
@return KErrNone if successful.
|
sl@0
|
816 |
KErrGeneral if the next character position is initially at the end of the string
|
sl@0
|
817 |
or no valid characters found initially.
|
sl@0
|
818 |
KErrOverflow if there is sign overflow, i.e. converted value greater than limit.
|
sl@0
|
819 |
If error codes KErrGeneral or KErrOverflow are returned, the object's
|
sl@0
|
820 |
members are left unaltered.
|
sl@0
|
821 |
*/
|
sl@0
|
822 |
{
|
sl@0
|
823 |
|
sl@0
|
824 |
TUint32 v;
|
sl@0
|
825 |
TInt r=BoundedVal(v,aRadix,0xffffu);
|
sl@0
|
826 |
if (r==KErrNone)
|
sl@0
|
827 |
aVal=(TUint16)v;
|
sl@0
|
828 |
return(r);
|
sl@0
|
829 |
}
|
sl@0
|
830 |
|
sl@0
|
831 |
|
sl@0
|
832 |
|
sl@0
|
833 |
|
sl@0
|
834 |
EXPORT_C TInt TLex16::Val(TUint32 &aVal,TRadix aRadix)
|
sl@0
|
835 |
/**
|
sl@0
|
836 |
Parses the string to extract a 32-bit unsigned integer, using the
|
sl@0
|
837 |
specified radix.
|
sl@0
|
838 |
|
sl@0
|
839 |
The specified radix is one of binary, octal, decimal, or hexadecimal.
|
sl@0
|
840 |
|
sl@0
|
841 |
@param aVal On return, contains the extracted integer.
|
sl@0
|
842 |
@param aRadix The radix to use when converting the number.
|
sl@0
|
843 |
|
sl@0
|
844 |
@return KErrNone if successful.
|
sl@0
|
845 |
KErrGeneral if the next character position is initially at the end of the string
|
sl@0
|
846 |
or no valid characters found initially.
|
sl@0
|
847 |
KErrOverflow if there is sign overflow, i.e. converted value greater than limit.
|
sl@0
|
848 |
If error codes KErrGeneral or KErrOverflow are returned, the object's
|
sl@0
|
849 |
members are left unaltered.
|
sl@0
|
850 |
*/
|
sl@0
|
851 |
{
|
sl@0
|
852 |
|
sl@0
|
853 |
TUint32 v;
|
sl@0
|
854 |
TInt r=BoundedVal(v,aRadix,0xffffffffu);
|
sl@0
|
855 |
if (r==KErrNone)
|
sl@0
|
856 |
aVal=v;
|
sl@0
|
857 |
return(r);
|
sl@0
|
858 |
}
|
sl@0
|
859 |
|
sl@0
|
860 |
|
sl@0
|
861 |
|
sl@0
|
862 |
|
sl@0
|
863 |
EXPORT_C TInt TLex16::Val(TInt64& aVal, TRadix aRadix)
|
sl@0
|
864 |
/**
|
sl@0
|
865 |
Parses the string to extract a 64-bit integer (treated as unsigned), using the
|
sl@0
|
866 |
specified radix.
|
sl@0
|
867 |
|
sl@0
|
868 |
The specified radix is one of binary, octal, decimal, or hexadecimal.
|
sl@0
|
869 |
|
sl@0
|
870 |
@param aVal On return, contains the extracted integer.
|
sl@0
|
871 |
@param aRadix The radix to use when converting the number.
|
sl@0
|
872 |
|
sl@0
|
873 |
@return KErrNone if successful.
|
sl@0
|
874 |
KErrGeneral if the next character position is initially at the end of the string
|
sl@0
|
875 |
or no valid characters found initially.
|
sl@0
|
876 |
KErrOverflow if there is sign overflow, i.e. converted value greater than limit.
|
sl@0
|
877 |
If error codes KErrGeneral or KErrOverflow are returned, the object's
|
sl@0
|
878 |
members are left unaltered.
|
sl@0
|
879 |
*/
|
sl@0
|
880 |
{
|
sl@0
|
881 |
|
sl@0
|
882 |
return BoundedVal(aVal,aRadix,TInt64(UI64LIT(0xffffffffffffffff)));
|
sl@0
|
883 |
}
|
sl@0
|
884 |
|
sl@0
|
885 |
|
sl@0
|
886 |
|
sl@0
|
887 |
|
sl@0
|
888 |
void TLex16::ValidateMark(const TLexMark16 aMark) const
|
sl@0
|
889 |
//
|
sl@0
|
890 |
// Asserts that the mark is valid for this lex
|
sl@0
|
891 |
//
|
sl@0
|
892 |
{
|
sl@0
|
893 |
__ASSERT_ALWAYS(aMark.iPtr>=iBuf && aMark.iPtr<=iEnd,Panic(ETLex16MarkOutOfRange));
|
sl@0
|
894 |
}
|
sl@0
|
895 |
|
sl@0
|
896 |
|