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_lex16.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include "us_std.h"
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
EXPORT_C TLex16::TLex16()
|
|
24 |
: iNext(NULL),iBuf(NULL),iEnd(NULL),iMark(NULL)
|
|
25 |
/**
|
|
26 |
Default cosntructor.
|
|
27 |
|
|
28 |
Constructs a TLex16, initialising its members to NULL.
|
|
29 |
*/
|
|
30 |
{}
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
EXPORT_C void TLex16::Assign(const TUint16 *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 TLex16::Assign(const TDesC16 &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 TLex16::UnGet()
|
|
66 |
/**
|
|
67 |
Decrements the next character position, allowing the previously "got" character
|
|
68 |
to be re-read.
|
|
69 |
|
|
70 |
@panic USER 64, if the previous character is before the start of the string.
|
|
71 |
*/
|
|
72 |
{
|
|
73 |
|
|
74 |
__ASSERT_ALWAYS(iNext>iBuf,Panic(ETLex16UnGetUnderflow));
|
|
75 |
iNext--;
|
|
76 |
}
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
EXPORT_C void TLex16::UnGetToMark(const TLexMark16 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 68, 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 TLex16::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
|
|
104 |
position by.
|
|
105 |
|
|
106 |
@panic USER 65, 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(ETLex16IncOutOfRange));
|
|
113 |
}
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
EXPORT_C void TLex16::Inc()
|
|
119 |
/**
|
|
120 |
Increments to the next character position.
|
|
121 |
|
|
122 |
@panic USER 65, if the increment puts the next character position before the
|
|
123 |
start or beyond the end of the string.
|
|
124 |
*/
|
|
125 |
{
|
|
126 |
|
|
127 |
if (!Eos())
|
|
128 |
iNext++;
|
|
129 |
__ASSERT_ALWAYS(iNext<=iEnd,Panic(ETLex16IncOutOfRange));
|
|
130 |
}
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
EXPORT_C TChar TLex16::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 TLex16::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 end of the
|
|
157 |
string.
|
|
158 |
|
|
159 |
@see TLex16::Get
|
|
160 |
*/
|
|
161 |
{
|
|
162 |
|
|
163 |
if (Eos())
|
|
164 |
return(0);
|
|
165 |
return(*iNext);
|
|
166 |
}
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
EXPORT_C void TLex16::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 TLex16::SkipAndMark(TInt aNumber,TLexMark16& 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 66, 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(ETLex16SkipOutOfRange));
|
|
201 |
Mark(aMark);
|
|
202 |
}
|
|
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
EXPORT_C void TLex16::SkipSpaceAndMark(TLexMark16& 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 TLex16::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 TLex16::TokenLength(const TLexMark16 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 68, 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 TPtrC16 TLex16::MarkedToken(const TLexMark16 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 68, if the specified mark is before the start or beyond the end
|
|
269 |
of the string.
|
|
270 |
*/
|
|
271 |
{
|
|
272 |
|
|
273 |
return(TPtrC16(aMark.iPtr,TokenLength(aMark)));
|
|
274 |
}
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
|
279 |
EXPORT_C TPtrC16 TLex16::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 68, if the specified mark is before the start or beyond the end
|
|
291 |
of the string.
|
|
292 |
*/
|
|
293 |
{
|
|
294 |
|
|
295 |
return(TPtrC16(iMark.iPtr,TokenLength()));
|
|
296 |
}
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
EXPORT_C TPtrC16 TLex16::NextToken()
|
|
302 |
/**
|
|
303 |
Strips any white space and extracts the next token.
|
|
304 |
|
|
305 |
@return Extracted token.
|
|
306 |
*/
|
|
307 |
{
|
|
308 |
TLexMark16 mark;
|
|
309 |
|
|
310 |
SkipSpaceAndMark(mark);
|
|
311 |
SkipCharacters();
|
|
312 |
return(TPtrC16(mark.iPtr,iNext-mark.iPtr));
|
|
313 |
}
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
EXPORT_C TPtrC16 TLex16::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 17, if the value of (next character position - extraction mark) is
|
|
326 |
negative.
|
|
327 |
*/
|
|
328 |
{
|
|
329 |
|
|
330 |
return(TPtrC16(iNext,iEnd-iNext));
|
|
331 |
}
|
|
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
|
336 |
EXPORT_C TPtrC16 TLex16::RemainderFromMark(const TLexMark16 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 17, if the value of (next character position - extraction mark) is
|
|
346 |
negative.
|
|
347 |
@panic USER 68, if the specified mark is before the start or beyond the end
|
|
348 |
of the string.
|
|
349 |
*/
|
|
350 |
{
|
|
351 |
|
|
352 |
ValidateMark(aMark);
|
|
353 |
return(TPtrC16(aMark.iPtr,iEnd-aMark.iPtr));
|
|
354 |
}
|
|
355 |
|
|
356 |
|
|
357 |
|
|
358 |
|
|
359 |
EXPORT_C TPtrC16 TLex16::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 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(TPtrC16(iMark.iPtr,iEnd-iMark.iPtr));
|
|
375 |
}
|
|
376 |
|
|
377 |
|
|
378 |
|
|
379 |
|
|
380 |
EXPORT_C TInt TLex16::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 TLex16::MarkedOffset(const TLexMark16 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 68, 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 TLex16::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 |
TLexMark16 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 TLex16::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 |
TLexMark16 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 TLex16::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 |
TLexMark16 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 TLex16::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 |
TLexMark16 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 TLex16::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 TLex16::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 TLex16::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 |
|
|
743 |
EXPORT_C TInt TLex16::Val(TInt64& aVal)
|
|
744 |
/**
|
|
745 |
Parses the string to extract a signed 64-bit integer.
|
|
746 |
|
|
747 |
@param aVal On return, contains the extracted integer.
|
|
748 |
|
|
749 |
@return KErrNone if successful.
|
|
750 |
KErrGeneral if the next character position is initially at the end of the string
|
|
751 |
or no valid characters found initially.
|
|
752 |
KErrOverflow if there is sign overflow, i.e. converted value greater than limit.
|
|
753 |
If error codes KErrGeneral or KErrOverflow are returned, the object's
|
|
754 |
members are left unaltered.
|
|
755 |
*/
|
|
756 |
{
|
|
757 |
|
|
758 |
TChar c=Peek();
|
|
759 |
if (c=='-' || c=='+')
|
|
760 |
Inc();
|
|
761 |
TInt r;
|
|
762 |
if (c=='-')
|
|
763 |
{
|
|
764 |
r=BoundedVal(aVal, EDecimal, UI64LIT(0x8000000000000000));
|
|
765 |
if (r==KErrNone)
|
|
766 |
aVal=-aVal;
|
|
767 |
}
|
|
768 |
else
|
|
769 |
r=BoundedVal(aVal, UI64LIT(0x7fffffffffffffff));
|
|
770 |
return(r);
|
|
771 |
}
|
|
772 |
|
|
773 |
|
|
774 |
|
|
775 |
|
|
776 |
EXPORT_C TInt TLex16::Val(TUint8 &aVal,TRadix aRadix)
|
|
777 |
/**
|
|
778 |
Parses the string to extract an 8-bit unsigned integer, using the
|
|
779 |
specified radix.
|
|
780 |
|
|
781 |
The specified radix is one of binary, octal, decimal, or hexadecimal.
|
|
782 |
|
|
783 |
@param aVal On return, contains the extracted integer.
|
|
784 |
@param aRadix The radix to use when converting the number.
|
|
785 |
|
|
786 |
@return KErrNone if successful.
|
|
787 |
KErrGeneral if the next character position is initially at the end of the string
|
|
788 |
or no valid characters found initially.
|
|
789 |
KErrOverflow if there is sign overflow, i.e. converted value greater than limit.
|
|
790 |
If error codes KErrGeneral or KErrOverflow are returned, the object's
|
|
791 |
members are left unaltered.
|
|
792 |
*/
|
|
793 |
{
|
|
794 |
|
|
795 |
TUint32 v;
|
|
796 |
TInt r=BoundedVal(v,aRadix,0xffu);
|
|
797 |
if (r==KErrNone)
|
|
798 |
aVal=(TUint8)v;
|
|
799 |
return(r);
|
|
800 |
}
|
|
801 |
|
|
802 |
|
|
803 |
|
|
804 |
|
|
805 |
EXPORT_C TInt TLex16::Val(TUint16 &aVal,TRadix aRadix)
|
|
806 |
/**
|
|
807 |
Parses the string to extract a 16-bit unsigned integer, using the
|
|
808 |
specified radix.
|
|
809 |
|
|
810 |
The specified radix is one of binary, octal, decimal, or hexadecimal.
|
|
811 |
|
|
812 |
@param aVal On return, contains the extracted integer.
|
|
813 |
@param aRadix The radix to use when converting the number.
|
|
814 |
|
|
815 |
@return KErrNone if successful.
|
|
816 |
KErrGeneral if the next character position is initially at the end of the string
|
|
817 |
or no valid characters found initially.
|
|
818 |
KErrOverflow if there is sign overflow, i.e. converted value greater than limit.
|
|
819 |
If error codes KErrGeneral or KErrOverflow are returned, the object's
|
|
820 |
members are left unaltered.
|
|
821 |
*/
|
|
822 |
{
|
|
823 |
|
|
824 |
TUint32 v;
|
|
825 |
TInt r=BoundedVal(v,aRadix,0xffffu);
|
|
826 |
if (r==KErrNone)
|
|
827 |
aVal=(TUint16)v;
|
|
828 |
return(r);
|
|
829 |
}
|
|
830 |
|
|
831 |
|
|
832 |
|
|
833 |
|
|
834 |
EXPORT_C TInt TLex16::Val(TUint32 &aVal,TRadix aRadix)
|
|
835 |
/**
|
|
836 |
Parses the string to extract a 32-bit unsigned integer, using the
|
|
837 |
specified radix.
|
|
838 |
|
|
839 |
The specified radix is one of binary, octal, decimal, or hexadecimal.
|
|
840 |
|
|
841 |
@param aVal On return, contains the extracted integer.
|
|
842 |
@param aRadix The radix to use when converting the number.
|
|
843 |
|
|
844 |
@return KErrNone if successful.
|
|
845 |
KErrGeneral if the next character position is initially at the end of the string
|
|
846 |
or no valid characters found initially.
|
|
847 |
KErrOverflow if there is sign overflow, i.e. converted value greater than limit.
|
|
848 |
If error codes KErrGeneral or KErrOverflow are returned, the object's
|
|
849 |
members are left unaltered.
|
|
850 |
*/
|
|
851 |
{
|
|
852 |
|
|
853 |
TUint32 v;
|
|
854 |
TInt r=BoundedVal(v,aRadix,0xffffffffu);
|
|
855 |
if (r==KErrNone)
|
|
856 |
aVal=v;
|
|
857 |
return(r);
|
|
858 |
}
|
|
859 |
|
|
860 |
|
|
861 |
|
|
862 |
|
|
863 |
EXPORT_C TInt TLex16::Val(TInt64& aVal, TRadix aRadix)
|
|
864 |
/**
|
|
865 |
Parses the string to extract a 64-bit integer (treated as unsigned), using the
|
|
866 |
specified radix.
|
|
867 |
|
|
868 |
The specified radix is one of binary, octal, decimal, or hexadecimal.
|
|
869 |
|
|
870 |
@param aVal On return, contains the extracted integer.
|
|
871 |
@param aRadix The radix to use when converting the number.
|
|
872 |
|
|
873 |
@return KErrNone if successful.
|
|
874 |
KErrGeneral if the next character position is initially at the end of the string
|
|
875 |
or no valid characters found initially.
|
|
876 |
KErrOverflow if there is sign overflow, i.e. converted value greater than limit.
|
|
877 |
If error codes KErrGeneral or KErrOverflow are returned, the object's
|
|
878 |
members are left unaltered.
|
|
879 |
*/
|
|
880 |
{
|
|
881 |
|
|
882 |
return BoundedVal(aVal,aRadix,TInt64(UI64LIT(0xffffffffffffffff)));
|
|
883 |
}
|
|
884 |
|
|
885 |
|
|
886 |
|
|
887 |
|
|
888 |
void TLex16::ValidateMark(const TLexMark16 aMark) const
|
|
889 |
//
|
|
890 |
// Asserts that the mark is valid for this lex
|
|
891 |
//
|
|
892 |
{
|
|
893 |
__ASSERT_ALWAYS(aMark.iPtr>=iBuf && aMark.iPtr<=iEnd,Panic(ETLex16MarkOutOfRange));
|
|
894 |
}
|
|
895 |
|
|
896 |
|