sl@0: // Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32\euser\us_lex16.cpp sl@0: // sl@0: // sl@0: sl@0: #include "us_std.h" sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TLex16::TLex16() sl@0: : iNext(NULL),iBuf(NULL),iEnd(NULL),iMark(NULL) sl@0: /** sl@0: Default cosntructor. sl@0: sl@0: Constructs a TLex16, initialising its members to NULL. sl@0: */ sl@0: {} sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C void TLex16::Assign(const TUint16 *aString) sl@0: /** sl@0: Assigns a string to this object from another string. sl@0: sl@0: @param aString A pointer to a string to be assigned. sl@0: */ sl@0: { sl@0: sl@0: iMark.iPtr=iNext=iBuf=aString; sl@0: iEnd=iBuf+User::StringLength(aString); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C void TLex16::Assign(const TDesC16 &aDes) sl@0: /** sl@0: Assigns a string to this object from a descriptor. sl@0: sl@0: @param aDes The descriptor to be assigned. sl@0: */ sl@0: { sl@0: sl@0: iMark.iPtr=iNext=iBuf=aDes.Ptr(); sl@0: iEnd=iBuf+aDes.Length(); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C void TLex16::UnGet() sl@0: /** sl@0: Decrements the next character position, allowing the previously "got" character sl@0: to be re-read. sl@0: sl@0: @panic USER 64, if the previous character is before the start of the string. sl@0: */ sl@0: { sl@0: sl@0: __ASSERT_ALWAYS(iNext>iBuf,Panic(ETLex16UnGetUnderflow)); sl@0: iNext--; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C void TLex16::UnGetToMark(const TLexMark16 aMark) sl@0: /** sl@0: Sets the next character position to the supplied extraction mark position. sl@0: sl@0: @param aMark Mark to copy to the next character position. sl@0: sl@0: @panic USER 68, if the extraction mark is before the start or beyond the end sl@0: of the string. sl@0: */ sl@0: { sl@0: sl@0: ValidateMark(aMark); sl@0: iNext=aMark.iPtr; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C void TLex16::Inc(TInt aNumber) sl@0: /** sl@0: Increments the next character position by aNumber. sl@0: sl@0: @param aNumber The number of characters to increment the next character sl@0: position by. sl@0: sl@0: @panic USER 65, if the increment puts the next character position before the sl@0: start or beyond the end of the string. sl@0: */ sl@0: { sl@0: sl@0: iNext+=aNumber; sl@0: __ASSERT_ALWAYS(iNext>=iBuf && iNext<=iEnd,Panic(ETLex16IncOutOfRange)); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C void TLex16::Inc() sl@0: /** sl@0: Increments to the next character position. sl@0: sl@0: @panic USER 65, if the increment puts the next character position before the sl@0: start or beyond the end of the string. sl@0: */ sl@0: { sl@0: sl@0: if (!Eos()) sl@0: iNext++; sl@0: __ASSERT_ALWAYS(iNext<=iEnd,Panic(ETLex16IncOutOfRange)); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TChar TLex16::Get() sl@0: /** sl@0: Gets the next character in the string and increments the next sl@0: character position. sl@0: sl@0: @return Next character to be read. 0 if at the end of the string. sl@0: */ sl@0: { sl@0: sl@0: if (Eos()) sl@0: return(0); sl@0: return(*iNext++); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TChar TLex16::Peek() const sl@0: /** sl@0: Shows the next character to be returned by Get(). sl@0: sl@0: @return Character to be returned by the next call to Get(). 0 if at the end of the sl@0: string. sl@0: sl@0: @see TLex16::Get sl@0: */ sl@0: { sl@0: sl@0: if (Eos()) sl@0: return(0); sl@0: return(*iNext); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C void TLex16::SkipSpace() sl@0: /** sl@0: Moves the next character position past any white space (space or separator). sl@0: sl@0: Stops if at the end of string. sl@0: */ sl@0: { sl@0: sl@0: while (!Eos() && Peek().IsSpace()) sl@0: iNext++; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C void TLex16::SkipAndMark(TInt aNumber,TLexMark16& aMark) sl@0: /** sl@0: Moves the next character position a specified number of characters and copies sl@0: it to the specified extraction mark. sl@0: sl@0: @param aNumber Number of characters to skip. sl@0: @param aMark On return, set to the next character position. sl@0: sl@0: @panic USER 66, if the skip moves the next character position either to before sl@0: the start or beyond the end of the string. sl@0: */ sl@0: { sl@0: sl@0: iNext+=aNumber; sl@0: __ASSERT_ALWAYS(iNext>=iBuf && iNext<=iEnd,Panic(ETLex16SkipOutOfRange)); sl@0: Mark(aMark); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C void TLex16::SkipSpaceAndMark(TLexMark16& aMark) sl@0: /** sl@0: Moves the next character position past any white space and copies it to the sl@0: specified extraction mark. sl@0: sl@0: Stops if at the end of the string. sl@0: sl@0: @param aMark On return, contains a reference to the next character position. sl@0: */ sl@0: { sl@0: sl@0: SkipSpace(); sl@0: Mark(aMark); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C void TLex16::SkipCharacters() sl@0: /** sl@0: Moves the next character position to the next white space (space or separator). sl@0: sl@0: Stops if at the end of the string. sl@0: */ sl@0: { sl@0: sl@0: while (!Eos() && !Peek().IsSpace()) sl@0: iNext++; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TInt TLex16::TokenLength(const TLexMark16 aMark) const sl@0: /** sl@0: Gets the length of the token starting at the specified extraction mark. sl@0: sl@0: @param aMark Extraction mark indicating the start of the token. sl@0: sl@0: @return Length of the token. sl@0: sl@0: @panic USER 68, if the specified mark is before the start or beyond the end sl@0: of the string. sl@0: */ sl@0: { sl@0: sl@0: ValidateMark(aMark); sl@0: return (iNext-aMark.iPtr); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TPtrC16 TLex16::MarkedToken(const TLexMark16 aMark) const sl@0: /** sl@0: Extracts the token, starting at the specified mark sl@0: sl@0: @param aMark Extraction mark indicating the start of the token. sl@0: sl@0: @return Extracted token. sl@0: sl@0: @panic USER 68, if the specified mark is before the start or beyond the end sl@0: of the string. sl@0: */ sl@0: { sl@0: sl@0: return(TPtrC16(aMark.iPtr,TokenLength(aMark))); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TPtrC16 TLex16::MarkedToken() const sl@0: // sl@0: // Extract the internally marked token sl@0: // there is the assumption here that iMark is always valid sl@0: /** sl@0: Extracts the marked token. sl@0: sl@0: Note that the function assumes that the current extraction mark is valid. sl@0: sl@0: @return Extracted token. sl@0: sl@0: @panic USER 68, if the specified mark is before the start or beyond the end sl@0: of the string. sl@0: */ sl@0: { sl@0: sl@0: return(TPtrC16(iMark.iPtr,TokenLength())); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TPtrC16 TLex16::NextToken() sl@0: /** sl@0: Strips any white space and extracts the next token. sl@0: sl@0: @return Extracted token. sl@0: */ sl@0: { sl@0: TLexMark16 mark; sl@0: sl@0: SkipSpaceAndMark(mark); sl@0: SkipCharacters(); sl@0: return(TPtrC16(mark.iPtr,iNext-mark.iPtr)); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TPtrC16 TLex16::Remainder() const sl@0: /** sl@0: Gets a descriptor containing all the text from the next character position sl@0: to the end of the string. sl@0: sl@0: @return Text from the next character position onwards. sl@0: sl@0: @panic USER 17, if the value of (next character position - extraction mark) is sl@0: negative. sl@0: */ sl@0: { sl@0: sl@0: return(TPtrC16(iNext,iEnd-iNext)); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TPtrC16 TLex16::RemainderFromMark(const TLexMark16 aMark) const sl@0: /** sl@0: Gets a descriptor containing all the text from the specified extraction mark sl@0: to the end of the string. sl@0: sl@0: @param aMark Extraction mark indicating where remaining text starts. sl@0: sl@0: @return Text from the specified extraction mark onwards. sl@0: sl@0: @panic USER 17, if the value of (next character position - extraction mark) is sl@0: negative. sl@0: @panic USER 68, if the specified mark is before the start or beyond the end sl@0: of the string. sl@0: */ sl@0: { sl@0: sl@0: ValidateMark(aMark); sl@0: return(TPtrC16(aMark.iPtr,iEnd-aMark.iPtr)); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TPtrC16 TLex16::RemainderFromMark() const sl@0: // sl@0: // Return the remainder from iMark sl@0: // There is an assumption here that the internal mark will always be valid sl@0: // sl@0: /** sl@0: Gets a descriptor containing all the text from the extraction mark to the end sl@0: of the string. sl@0: sl@0: The function assumes that the current extraction mark is valid. sl@0: sl@0: @return Text from the extraction mark onwards. sl@0: */ sl@0: { sl@0: sl@0: return(TPtrC16(iMark.iPtr,iEnd-iMark.iPtr)); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TInt TLex16::Offset() const sl@0: // sl@0: // Return the offset from iNext to the lex start. sl@0: // sl@0: /** sl@0: Gets the offset of the next character position from the start of the string. sl@0: sl@0: @return Offset of next character position. sl@0: */ sl@0: { sl@0: sl@0: return((TUint)(iNext-iBuf)); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TInt TLex16::MarkedOffset(const TLexMark16 aMark) const sl@0: /** sl@0: Gets the offset of the specified extraction mark from the start of the string. sl@0: sl@0: @param aMark Extraction mark. sl@0: sl@0: @return The offset of the extraction mark. sl@0: sl@0: @panic USER 68, if the specified mark is before the start or beyond the end sl@0: of the string. sl@0: */ sl@0: { sl@0: sl@0: ValidateMark(aMark); sl@0: return((TUint)(aMark.iPtr-iBuf)); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TInt TLex16::BoundedVal(TUint32 &aVal,TRadix aRadix,TUint aLimit) sl@0: /** sl@0: Parses the string to extract a 32-bit unsigned integer, using the sl@0: specified radix, and checks that it is within the specified limit. sl@0: sl@0: The specified radix is one of binary, octal, decimal, or hexadecimal. sl@0: sl@0: @param aVal On return, contains the extracted integer. sl@0: @param aRadix The radix to use when converting the number. sl@0: @param aLimit The upper limit. sl@0: sl@0: @return KErrNone if successful. sl@0: KErrGeneral if the next character position is initially at the end of the string sl@0: or no valid characters found initially. sl@0: KErrOverflow if there is sign overflow, i.e. converted value greater than limit. sl@0: If error codes KErrGeneral or KErrOverflow are returned, the object's sl@0: members are left unaltered. sl@0: */ sl@0: { sl@0: sl@0: TUint l=aLimit/aRadix; sl@0: TUint v=0; sl@0: TUint d=0; sl@0: TLexMark16 mark(iNext); sl@0: while (!Eos()) sl@0: { sl@0: TChar c=Peek(); sl@0: if (!c.IsHexDigit()) sl@0: break; sl@0: c=Get(); sl@0: if (c.IsAlpha()) sl@0: { sl@0: c.UpperCase(); sl@0: c-=('A'-10); sl@0: } sl@0: else sl@0: c-='0'; sl@0: if (c>=(TUint)aRadix) sl@0: { sl@0: iNext--; sl@0: break; sl@0: } sl@0: if (v>l) sl@0: { sl@0: UnGetToMark(mark); sl@0: return(KErrOverflow); sl@0: } sl@0: TUint o=v; sl@0: v*=aRadix; sl@0: v+=c; sl@0: if (o>v) sl@0: { sl@0: UnGetToMark(mark); sl@0: return(KErrOverflow); sl@0: } sl@0: d++; sl@0: } sl@0: if (d==0) sl@0: { sl@0: UnGetToMark(mark); sl@0: return(KErrGeneral); sl@0: } sl@0: if (v>aLimit) sl@0: { sl@0: UnGetToMark(mark); sl@0: return(KErrOverflow); sl@0: } sl@0: aVal=v; sl@0: return(KErrNone); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TInt TLex16::BoundedVal(TInt32 &aVal,TInt aLimit) sl@0: /** sl@0: Parses the string to extract a 32-bit signed integer, and checks that it is sl@0: within the specified limit. sl@0: sl@0: @param aVal On return, contains the extracted integer. sl@0: @param aLimit The upper limit. sl@0: sl@0: @return KErrNone if successful. sl@0: KErrGeneral if the next character position is initially at the end of the string sl@0: or no valid characters found initially. sl@0: KErrOverflow if there is sign overflow, i.e. converted value greater than limit. sl@0: If error codes KErrGeneral or KErrOverflow are returned, the object's sl@0: members are left unaltered. sl@0: */ sl@0: { sl@0: sl@0: if (Eos()) sl@0: return(KErrGeneral); sl@0: TUint lim=aLimit; sl@0: TLexMark16 mark(iNext); sl@0: TUint s=FALSE; sl@0: TChar c=Peek(); sl@0: if (c=='-') sl@0: { sl@0: lim++; sl@0: s++; sl@0: Inc(); sl@0: } sl@0: else if (c=='+') sl@0: Inc(); sl@0: TUint32 v; sl@0: TInt r=BoundedVal(v,EDecimal,lim); sl@0: if (r==KErrNone) sl@0: { sl@0: if (v>lim) sl@0: r=KErrOverflow; sl@0: else if (s) sl@0: aVal=(-((TInt32)v)); sl@0: else sl@0: aVal=v; sl@0: } sl@0: if (r!=KErrNone) sl@0: UnGetToMark(mark); sl@0: return(r); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TInt TLex16::BoundedVal(TInt64& aVal, TRadix aRadix, const TInt64& aLimit) sl@0: /** sl@0: Parses the string to extract a 64-bit signed integer, using the sl@0: specified radix, and checks that it is within the specified limit. sl@0: sl@0: The specified radix is one of binary, octal, decimal, or hexadecimal. sl@0: sl@0: @param aVal On return, contains the extracted integer. sl@0: @param aRadix The radix to use when converting the number. sl@0: @param aLimit The upper limit. sl@0: sl@0: @return KErrNone if successful. sl@0: KErrGeneral if the next character position is initially at the end of the string sl@0: or no valid characters found initially. sl@0: KErrOverflow if there is sign overflow, i.e. converted value greater than limit. sl@0: If error codes KErrGeneral or KErrOverflow are returned, the object's sl@0: members are left unaltered. sl@0: */ sl@0: { sl@0: TUint64 rad = aRadix; sl@0: TUint64 lim = static_cast(aLimit); sl@0: sl@0: lim /= rad; sl@0: sl@0: TUint64 v = 0; sl@0: TUint digit=0; sl@0: TLexMark16 mark(iNext); sl@0: while (!Eos()) sl@0: { sl@0: TChar c=Peek(); sl@0: if (!c.IsHexDigit()) sl@0: break; sl@0: c=Get(); sl@0: if (c.IsAlpha()) sl@0: { sl@0: c.UpperCase(); sl@0: c-=('A'-10); sl@0: } sl@0: else sl@0: c-='0'; sl@0: if (c >= rad) sl@0: { sl@0: iNext--; sl@0: break; sl@0: } sl@0: if (v > lim) sl@0: { sl@0: UnGetToMark(mark); sl@0: return(KErrOverflow); sl@0: } sl@0: TUint64 old = v; sl@0: v*=rad; sl@0: v+=c; sl@0: if (old > v) sl@0: { sl@0: UnGetToMark(mark); sl@0: return(KErrOverflow); sl@0: } sl@0: digit++; sl@0: } sl@0: if (digit==0) sl@0: { sl@0: UnGetToMark(mark); sl@0: return(KErrGeneral); sl@0: } sl@0: if (v > static_cast(aLimit)) sl@0: { sl@0: UnGetToMark(mark); sl@0: return(KErrOverflow); sl@0: } sl@0: aVal = static_cast(v); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TInt TLex16::BoundedVal(TInt64& aVal, const TInt64& aLimit) sl@0: /** sl@0: Parses the string to extract a 64-bit signed integer, and checks that it sl@0: is within the specified limit. sl@0: sl@0: @param aVal On return, contains the extracted integer. sl@0: @param aLimit The upper limit. sl@0: sl@0: @return KErrNone if successful. sl@0: KErrGeneral if the next character position is initially at the end of the string sl@0: or no valid characters found initially. sl@0: KErrOverflow if there is sign overflow, i.e. converted value greater than limit. sl@0: If error codes KErrGeneral or KErrOverflow are returned, the object's sl@0: members are left unaltered. sl@0: */ sl@0: { sl@0: sl@0: if (Eos()) sl@0: return(KErrGeneral); sl@0: TInt64 lim = aLimit; sl@0: TLexMark16 mark(iNext); sl@0: TBool s=EFalse; sl@0: TChar c=Peek(); sl@0: if (c=='-') sl@0: { sl@0: lim++; sl@0: s++; sl@0: Inc(); sl@0: } sl@0: else if (c=='+') sl@0: Inc(); sl@0: TInt64 v; sl@0: TInt r=BoundedVal(v,EDecimal,lim); sl@0: if (r==KErrNone) sl@0: { sl@0: if (v>lim) sl@0: r=KErrOverflow; sl@0: else if (s) sl@0: aVal=(-v); sl@0: else sl@0: aVal=v; sl@0: } sl@0: if (r!=KErrNone) sl@0: UnGetToMark(mark); sl@0: return(r); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TInt TLex16::Val(TInt8 &aVal) sl@0: /** sl@0: Parses the string to extract a signed 8-bit integer. sl@0: sl@0: @param aVal On return, contains the extracted integer. sl@0: sl@0: @return KErrNone if successful. sl@0: KErrGeneral if the next character position is initially at the end of the string sl@0: or no valid characters found initially. sl@0: KErrOverflow if there is sign overflow, i.e. converted value greater than limit. sl@0: If error codes KErrGeneral or KErrOverflow are returned, the object's sl@0: members are left unaltered. sl@0: */ sl@0: { sl@0: sl@0: TInt32 v; sl@0: TInt r=BoundedVal(v,0x7fu); sl@0: if (r==KErrNone) sl@0: aVal=(TInt8)v; sl@0: return(r); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TInt TLex16::Val(TInt16 &aVal) sl@0: /** sl@0: Parses the string to extract a signed 16-bit integer. sl@0: sl@0: @param aVal On return, contains the extracted integer. sl@0: sl@0: @return KErrNone if successful. sl@0: KErrGeneral if the next character position is initially at the end of the string sl@0: or no valid characters found initially. sl@0: KErrOverflow if there is sign overflow, i.e. converted value greater than limit. sl@0: If error codes KErrGeneral or KErrOverflow are returned, the object's sl@0: members are left unaltered. sl@0: */ sl@0: { sl@0: sl@0: TInt32 v; sl@0: TInt r=BoundedVal(v,0x7fffu); sl@0: if (r==KErrNone) sl@0: aVal=(TInt16)v; sl@0: return(r); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TInt TLex16::Val(TInt32 &aVal) sl@0: /** sl@0: Parses the string to extract a signed 32-bit integer. sl@0: sl@0: @param aVal On return, contains the extracted integer. sl@0: sl@0: @return KErrNone if successful. sl@0: KErrGeneral if the next character position is initially at the end of the string sl@0: or no valid characters found initially. sl@0: KErrOverflow if there is sign overflow, i.e. converted value greater than limit. sl@0: If error codes KErrGeneral or KErrOverflow are returned, the object's sl@0: members are left unaltered. sl@0: */ sl@0: { sl@0: sl@0: TInt32 v; sl@0: TInt r=BoundedVal(v,0x7fffffffu); sl@0: if (r==KErrNone) sl@0: aVal=v; sl@0: return(r); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TInt TLex16::Val(TInt64& aVal) sl@0: /** sl@0: Parses the string to extract a signed 64-bit integer. sl@0: sl@0: @param aVal On return, contains the extracted integer. sl@0: sl@0: @return KErrNone if successful. sl@0: KErrGeneral if the next character position is initially at the end of the string sl@0: or no valid characters found initially. sl@0: KErrOverflow if there is sign overflow, i.e. converted value greater than limit. sl@0: If error codes KErrGeneral or KErrOverflow are returned, the object's sl@0: members are left unaltered. sl@0: */ sl@0: { sl@0: sl@0: TChar c=Peek(); sl@0: if (c=='-' || c=='+') sl@0: Inc(); sl@0: TInt r; sl@0: if (c=='-') sl@0: { sl@0: r=BoundedVal(aVal, EDecimal, UI64LIT(0x8000000000000000)); sl@0: if (r==KErrNone) sl@0: aVal=-aVal; sl@0: } sl@0: else sl@0: r=BoundedVal(aVal, UI64LIT(0x7fffffffffffffff)); sl@0: return(r); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TInt TLex16::Val(TUint8 &aVal,TRadix aRadix) sl@0: /** sl@0: Parses the string to extract an 8-bit unsigned integer, using the sl@0: specified radix. sl@0: sl@0: The specified radix is one of binary, octal, decimal, or hexadecimal. sl@0: sl@0: @param aVal On return, contains the extracted integer. sl@0: @param aRadix The radix to use when converting the number. sl@0: sl@0: @return KErrNone if successful. sl@0: KErrGeneral if the next character position is initially at the end of the string sl@0: or no valid characters found initially. sl@0: KErrOverflow if there is sign overflow, i.e. converted value greater than limit. sl@0: If error codes KErrGeneral or KErrOverflow are returned, the object's sl@0: members are left unaltered. sl@0: */ sl@0: { sl@0: sl@0: TUint32 v; sl@0: TInt r=BoundedVal(v,aRadix,0xffu); sl@0: if (r==KErrNone) sl@0: aVal=(TUint8)v; sl@0: return(r); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TInt TLex16::Val(TUint16 &aVal,TRadix aRadix) sl@0: /** sl@0: Parses the string to extract a 16-bit unsigned integer, using the sl@0: specified radix. sl@0: sl@0: The specified radix is one of binary, octal, decimal, or hexadecimal. sl@0: sl@0: @param aVal On return, contains the extracted integer. sl@0: @param aRadix The radix to use when converting the number. sl@0: sl@0: @return KErrNone if successful. sl@0: KErrGeneral if the next character position is initially at the end of the string sl@0: or no valid characters found initially. sl@0: KErrOverflow if there is sign overflow, i.e. converted value greater than limit. sl@0: If error codes KErrGeneral or KErrOverflow are returned, the object's sl@0: members are left unaltered. sl@0: */ sl@0: { sl@0: sl@0: TUint32 v; sl@0: TInt r=BoundedVal(v,aRadix,0xffffu); sl@0: if (r==KErrNone) sl@0: aVal=(TUint16)v; sl@0: return(r); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TInt TLex16::Val(TUint32 &aVal,TRadix aRadix) sl@0: /** sl@0: Parses the string to extract a 32-bit unsigned integer, using the sl@0: specified radix. sl@0: sl@0: The specified radix is one of binary, octal, decimal, or hexadecimal. sl@0: sl@0: @param aVal On return, contains the extracted integer. sl@0: @param aRadix The radix to use when converting the number. sl@0: sl@0: @return KErrNone if successful. sl@0: KErrGeneral if the next character position is initially at the end of the string sl@0: or no valid characters found initially. sl@0: KErrOverflow if there is sign overflow, i.e. converted value greater than limit. sl@0: If error codes KErrGeneral or KErrOverflow are returned, the object's sl@0: members are left unaltered. sl@0: */ sl@0: { sl@0: sl@0: TUint32 v; sl@0: TInt r=BoundedVal(v,aRadix,0xffffffffu); sl@0: if (r==KErrNone) sl@0: aVal=v; sl@0: return(r); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C TInt TLex16::Val(TInt64& aVal, TRadix aRadix) sl@0: /** sl@0: Parses the string to extract a 64-bit integer (treated as unsigned), using the sl@0: specified radix. sl@0: sl@0: The specified radix is one of binary, octal, decimal, or hexadecimal. sl@0: sl@0: @param aVal On return, contains the extracted integer. sl@0: @param aRadix The radix to use when converting the number. sl@0: sl@0: @return KErrNone if successful. sl@0: KErrGeneral if the next character position is initially at the end of the string sl@0: or no valid characters found initially. sl@0: KErrOverflow if there is sign overflow, i.e. converted value greater than limit. sl@0: If error codes KErrGeneral or KErrOverflow are returned, the object's sl@0: members are left unaltered. sl@0: */ sl@0: { sl@0: sl@0: return BoundedVal(aVal,aRadix,TInt64(UI64LIT(0xffffffffffffffff))); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: void TLex16::ValidateMark(const TLexMark16 aMark) const sl@0: // sl@0: // Asserts that the mark is valid for this lex sl@0: // sl@0: { sl@0: __ASSERT_ALWAYS(aMark.iPtr>=iBuf && aMark.iPtr<=iEnd,Panic(ETLex16MarkOutOfRange)); sl@0: } sl@0: sl@0: