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