sl@0: // Copyright (c) 2001-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 "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: // sl@0: sl@0: #include sl@0: sl@0: #include sl@0: sl@0: #include "EscapeUtilsInternal.h" sl@0: sl@0: // Constants sl@0: // sl@0: _LIT(KHexDigit, "0123456789ABCDEF"); sl@0: _LIT(KExcludedData, "{}|\\^`<>#%\""); sl@0: _LIT8(KQueryData8, ";/?:@&=+$,[]"); sl@0: _LIT8(KPathData8, "/;=?[]"); sl@0: _LIT8(KAuthData8, ";:@?/[]"); sl@0: _LIT8(KUrlEncoded8, ";/?:@&=+$[]!\'()~*"); sl@0: _LIT16(KQueryData16, ";/?:@&=+$,[]"); sl@0: _LIT16(KPathData16, "/;=?[]"); sl@0: _LIT16(KAuthData16, ";:@?/[]"); sl@0: _LIT16(KUrlEncoded16, ";/?:@&=+$[]!\'()~"); sl@0: const TInt KEscapeUtilsConversionBufferSize = 50; sl@0: const TInt KEscapeIndicator = '%'; sl@0: const TInt KEscapeTripleLength = 3; sl@0: const TInt KEscDelimiterPos = 0; sl@0: const TInt KMostSignificantNibblePos = 1; sl@0: const TInt KLeastSignificantNibblePos = 2; sl@0: sl@0: // Panic category sl@0: // sl@0: #ifdef _DEBUG sl@0: _LIT(KEscapeUtilsPanicCategory, "ESC-UTILS"); sl@0: #endif sl@0: sl@0: // sl@0: // sl@0: // Implementation of EscapeUtils sl@0: // sl@0: // sl@0: sl@0: /** sl@0: Escape encodes excluded and reserved characters in the data as escape triples. sl@0: The reserved characters are defined by the escape mode. These characters and the sl@0: set of excluded characters specified by RFC2396 form the entire set of excluded data. sl@0: sl@0: @since 6.0 sl@0: @leave KUriUtilsErr16BitChar. A 16-Bit character was found in the data to be escape encoded. sl@0: @param aData A descriptor with the data to encode. sl@0: @param aEscapeMode An enum specifying the escape mode. sl@0: @return A pointer to a descriptor buffer which contains the escape encoded data. sl@0: */ sl@0: EXPORT_C HBufC8* EscapeUtils::EscapeEncodeL(const TDesC8& aData, TEscapeMode aEscapeMode) sl@0: { sl@0: // Need descriptor pointer to reserved characters... sl@0: TPtrC8 reserved; sl@0: sl@0: switch (aEscapeMode) sl@0: { sl@0: case EEscapeNormal: sl@0: { sl@0: // This is normal operation - no reserved chars sl@0: reserved.Set(KNullDesC8); sl@0: } break; sl@0: case EEscapeQuery: sl@0: { sl@0: // Reserved data in a URI query - ; / ? : @ & = + $ , sl@0: reserved.Set(KQueryData8()); sl@0: } break; sl@0: case EEscapePath: sl@0: { sl@0: // Reserved data in a URI path segment - / ; = ? sl@0: reserved.Set(KPathData8()); sl@0: } break; sl@0: case EEscapeAuth: sl@0: { sl@0: // Reserved data in a URI authority - ; : @ ? / sl@0: reserved.Set(KAuthData8()); sl@0: } break; sl@0: case EEscapeUrlEncoded: sl@0: { sl@0: // Reserved data in Url Encoded data - ; / ? : @ & = + $ [ ] ! ' ( ) ~ * sl@0: reserved.Set(KUrlEncoded8()); sl@0: } break; sl@0: default: sl@0: // Not supported return NULL sl@0: __ASSERT_DEBUG(EFalse, User::Panic(KEscapeUtilsPanicCategory, KUriUtilsErrBadEscapeMode)); sl@0: return NULL; sl@0: } sl@0: return EscapeEncodeL(aData, reserved); sl@0: } sl@0: sl@0: /** sl@0: Escape encodes excluded and reserved characters in the data as escape triples. The sl@0: reserved characters are defined by the escape mode. These characters and the set of sl@0: excluded characters specified by RFC2396 form the entire set of excluded data. sl@0: sl@0: @since 6.0 sl@0: @leave KUriUtilsErr16BitChar. A 16-Bit character was found in the data to be escape encoded. sl@0: @param aData A descriptor with the data to encode. sl@0: @param aEscapeMode An enum specifying the escape mode. sl@0: @return A pointer to a descriptor buffer which contains the escape encoded data. sl@0: */ sl@0: EXPORT_C HBufC16* EscapeUtils::EscapeEncodeL(const TDesC16& aData, TEscapeMode aEscapeMode) sl@0: { sl@0: // Need to descriptor pointer to reserved chars sl@0: TPtrC16 reserved; sl@0: sl@0: switch (aEscapeMode) sl@0: { sl@0: case EEscapeNormal: sl@0: { sl@0: // This is normal operation - no reserved chars sl@0: reserved.Set(KNullDesC16); sl@0: } break; sl@0: case EEscapeQuery: sl@0: { sl@0: // Reserved data in a URI query - ; / ? : @ & = + $ [], sl@0: reserved.Set(KQueryData16()); sl@0: } break; sl@0: case EEscapePath: sl@0: { sl@0: // Reserved data in a URI path segment - / ; = ? [] sl@0: reserved.Set(KPathData16()); sl@0: } break; sl@0: case EEscapeAuth: sl@0: { sl@0: // Reserved data in a URI authority - ; : @ ? / [] sl@0: reserved.Set(KAuthData16()); sl@0: } break; sl@0: case EEscapeUrlEncoded: sl@0: { sl@0: // Reserved data in Url Encoded data - ; / ? : @ & = + $ [ ] ! ' ( ) ~ sl@0: reserved.Set(KUrlEncoded16()); sl@0: } break; sl@0: default: sl@0: // Not supported return NULL sl@0: __ASSERT_DEBUG(EFalse, User::Panic(KEscapeUtilsPanicCategory, KUriUtilsErrBadEscapeMode)); sl@0: return NULL; sl@0: } sl@0: return EscapeEncodeL(aData, reserved); sl@0: } sl@0: sl@0: /** sl@0: Escape encodes excluded and reserved characters in the data as escape triples. These sl@0: characters and the set of excluded characters specified by RFC2396 form the entire set sl@0: of excluded data. sl@0: sl@0: @since 6.0 sl@0: @leave KUriUtilsErr16BitChar. A 16-Bit character was found in the data to be escape encoded. sl@0: @param aData A descriptor with the data to encode. sl@0: @param aReservedChars A descriptor with the reserved characters. sl@0: @return A pointer to a descriptor buffer which contains the escape encoded data. sl@0: */ sl@0: EXPORT_C HBufC8* EscapeUtils::EscapeEncodeL(const TDesC8& aData, const TDesC8& aReservedChars) sl@0: { sl@0: // Allocate space to build escaped url - consider worse case; all characters are excluded => length x 3 sl@0: HBufC8* buf = HBufC8::NewLC(aData.Length()*3); sl@0: TPtr8 escaped = buf->Des(); sl@0: sl@0: User::LeaveIfError(EscapeEncodeData(aData, aReservedChars, escaped)); sl@0: HBufC8* encoded = escaped.AllocL(); sl@0: sl@0: CleanupStack::PopAndDestroy(buf); sl@0: return encoded; sl@0: } sl@0: sl@0: /** sl@0: Escape encodes excluded and reserved characters in the data as escape triples. These characters sl@0: and the set of excluded characters specified by RFC2396 form the entire set of excluded data. sl@0: sl@0: @since 6.0 sl@0: @leave KUriUtilsErr16BitChar. A 16-Bit character was found in the data to be escape encoded. sl@0: @param aData A descriptor with the data to encode. sl@0: @param aReservedChars A descriptor with the reserved characters. sl@0: @return A pointer to a descriptor buffer which contains the escape encoded data. sl@0: */ sl@0: EXPORT_C HBufC16* EscapeUtils::EscapeEncodeL(const TDesC16& aData, const TDesC16& aReservedChars) sl@0: { sl@0: // Allocate space to build escaped url - consider worse case; all characters are excluded => length x 3 sl@0: HBufC16* buf = HBufC16::NewLC(aData.Length()*3); sl@0: TPtr16 escaped = buf->Des(); sl@0: sl@0: User::LeaveIfError(EscapeEncodeData(aData, aReservedChars, escaped)); sl@0: HBufC16* encoded = escaped.AllocL(); sl@0: sl@0: CleanupStack::PopAndDestroy(buf); sl@0: return encoded; sl@0: } sl@0: sl@0: /** sl@0: Escape decodes the data. sl@0: sl@0: @since 6.0 sl@0: @param aData A descriptor with the data to decode. sl@0: @return A pointer to a descriptor buffer which contains the escape decoded data. sl@0: */ sl@0: EXPORT_C HBufC8* EscapeUtils::EscapeDecodeL(const TDesC8& aData) sl@0: { sl@0: // Allocate space to build unescaped data sl@0: HBufC8* buf = HBufC8::NewLC(aData.Length()); sl@0: TPtr8 unescaped = buf->Des(); sl@0: sl@0: User::LeaveIfError(EscapeDecodeData(aData, unescaped)); sl@0: HBufC8* decoded = unescaped.AllocL(); sl@0: sl@0: CleanupStack::PopAndDestroy(buf); sl@0: return decoded; sl@0: } sl@0: sl@0: /** sl@0: Escape decodes the data. sl@0: sl@0: @since 6.0 sl@0: @param aData A descriptor with the data to decode. sl@0: @return A pointer to a descriptor buffer which contains the escape decoded data. sl@0: */ sl@0: EXPORT_C HBufC16* EscapeUtils::EscapeDecodeL(const TDesC16& aData) sl@0: { sl@0: // Allocate space to build unescaped data sl@0: HBufC16* buf = HBufC16::NewLC(aData.Length()); sl@0: TPtr16 unescaped = buf->Des(); sl@0: sl@0: User::LeaveIfError(EscapeDecodeData(aData, unescaped)); sl@0: HBufC16* decoded = unescaped.AllocL(); sl@0: sl@0: CleanupStack::PopAndDestroy(buf); sl@0: return decoded; sl@0: } sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: escape encode only those characters that cannot be in a URI. assume all %hh are %encoded already. sl@0: sl@0: @param aData The descriptor buffer to be escape encoded. sl@0: @return A pointer to a descriptor buffer which contains the escape encoded data. sl@0: */ sl@0: HBufC8* EscapeUtils::ReEscapeEncodeL(const TDesC8& aData) sl@0: { sl@0: // Descriptor to hex digits and excluded chars sl@0: const TDesC& KHexChars = KHexDigit; sl@0: sl@0: const TInt length = aData.Length(); sl@0: sl@0: // find out how many characters need escape encoding sl@0: TInt count = 0; sl@0: for( TInt i=0; iDes(); sl@0: sl@0: for( TInt i=0; i> 4; // Get msNibble by masking against 11110000 and dividing by 16 (>>4) sl@0: escaped.Append(KHexChars[mostSignificantNibble]); sl@0: const TInt leastSignificantNibble = (current & 0x0f); // Get lsNibble by masking against 00001111 sl@0: escaped.Append(KHexChars[leastSignificantNibble]); sl@0: } sl@0: else sl@0: { sl@0: // Not an excluded char - just append sl@0: escaped.Append(current); sl@0: } sl@0: } sl@0: CleanupStack::Pop(buf); sl@0: return buf; sl@0: } sl@0: sl@0: sl@0: /** sl@0: sl@0: Converts UNICODE data into UTF8 format. sl@0: sl@0: @since 6.0 sl@0: @leave KUriUtilsCannotConvert. When the input data cannot be converted. sl@0: @param aString A descriptor with the data to convert. sl@0: @return A pointer to an 8-bit descriptor buffer which contains UTF8 data. sl@0: */ sl@0: EXPORT_C HBufC8* EscapeUtils::ConvertFromUnicodeToUtf8L(const TDesC& aString) sl@0: { sl@0: // Return an empty buffer straight-away sl@0: if( aString.Compare(KNullDesC) == 0 ) sl@0: return KNullDesC8().AllocL(); sl@0: sl@0: // Convert from Unicode to UTF8 sl@0: TPtrC unicode = aString; sl@0: TBuf8 buf; sl@0: HBufC8* utf8Buffer = HBufC8::NewLC(unicode.Length()); sl@0: TPtr8 utf8 = utf8Buffer->Des(); sl@0: sl@0: // Loop until all of the filename is converted sl@0: FOREVER sl@0: { sl@0: const TInt returnValue = CnvUtfConverter::ConvertFromUnicodeToUtf8(buf, unicode); sl@0: if( returnValue == CnvUtfConverter::EErrorIllFormedInput || returnValue < 0) sl@0: User::Leave(KUriUtilsCannotConvert); sl@0: sl@0: // Is escapedFullPath too small? sl@0: if( utf8.Length() + buf.Length() > utf8.MaxLength() ) sl@0: { sl@0: utf8Buffer = utf8Buffer->ReAllocL(utf8.Length() + buf.Length()); sl@0: CleanupStack::Pop(); // utf8Buffer (old version) sl@0: CleanupStack::PushL(utf8Buffer); // new version sl@0: utf8.Set(utf8Buffer->Des()); sl@0: } sl@0: // Copy converted characters sl@0: utf8.Append(buf); sl@0: sl@0: if( returnValue == KErrNone ) sl@0: break; // All of aUnicodeText has been converted and handled sl@0: sl@0: // Set input descriptor to remaining characters sl@0: unicode.Set(unicode.Right(returnValue)); sl@0: } sl@0: CleanupStack::Pop(utf8Buffer); sl@0: return utf8Buffer; // Ownership transfered to caller sl@0: } sl@0: sl@0: /** sl@0: Converts UTF8 format into UNICODE data. sl@0: sl@0: @since 6.0 sl@0: @leave KUriUtilsCannotConvert. When the input data cannot be converted. sl@0: @param aString A descriptor with the data to convert. sl@0: @return A pointer to a 16-bit descriptor buffer which contains UNICODE data. sl@0: */ sl@0: EXPORT_C HBufC* EscapeUtils::ConvertToUnicodeFromUtf8L(const TDesC8& aString) sl@0: { sl@0: // Return an empty buffer straight-away sl@0: if( aString.Compare(KNullDesC8) == 0 ) sl@0: return KNullDesC().AllocL(); sl@0: sl@0: // Convert from Unicode to UTF8 sl@0: TPtrC8 utf8 = aString; sl@0: TBuf buf; sl@0: HBufC* unicodeBuffer = HBufC::NewLC(utf8.Length()); sl@0: TPtr unicode = unicodeBuffer->Des(); sl@0: sl@0: // Loop until all of the filename is converted sl@0: FOREVER sl@0: { sl@0: const TInt returnValue = CnvUtfConverter::ConvertToUnicodeFromUtf8(buf, utf8); sl@0: if( returnValue == CnvUtfConverter::EErrorIllFormedInput || returnValue < 0) sl@0: User::Leave(KUriUtilsCannotConvert); sl@0: sl@0: // Is escapedFullPath too small? sl@0: if( unicode.Length() + buf.Length() > unicode.MaxLength() ) sl@0: { sl@0: unicodeBuffer = unicodeBuffer->ReAllocL(unicode.Length() + buf.Length()); sl@0: CleanupStack::Pop(); // unicodeBuffer (old version) sl@0: CleanupStack::PushL(unicodeBuffer); // new version sl@0: unicode.Set(unicodeBuffer->Des()); sl@0: } sl@0: // Copy converted characters sl@0: unicode.Append(buf); sl@0: sl@0: if( returnValue==0 ) sl@0: break; // All of utf8 has been converted and handled sl@0: sl@0: // Set input descriptor to remaining characters sl@0: utf8.Set(utf8.Right(returnValue)); sl@0: } sl@0: CleanupStack::Pop(unicodeBuffer); sl@0: return unicodeBuffer; // Ownership transfered to caller sl@0: } sl@0: sl@0: /** sl@0: Checks to see if the input argument is excluded. sl@0: sl@0: @since 6.0 sl@0: @param aChar The character to be checked. sl@0: @return A boolean value of ETrue if the character is an excluded one, or sl@0: EFalse if it is not. sl@0: */ sl@0: EXPORT_C TBool EscapeUtils::IsExcludedChar(TChar aChar) sl@0: { sl@0: const TDesC& KExcludedChars = KExcludedData; sl@0: TBool excluded = KExcludedChars.Locate(aChar) != KErrNotFound || aChar <= 0x1F || aChar == ' ' || aChar > 0x7E; sl@0: return excluded; sl@0: } sl@0: sl@0: /** sl@0: Checks for an escape triple at the start of the input descriptor. If there is a triple sl@0: its value is calculated and returned through the output argument aHexValue. If there is sl@0: no escape triple then this argument is left unchanged. sl@0: sl@0: @since 6.0 sl@0: @param aData The descriptor to be checked for an escape triple. sl@0: @param aHexValue The output argument with the value of the escape triple sl@0: if it exists. sl@0: @return A boolean value of ETrue if there is an escape triple at the start of sl@0: the input descriptor, EFalse otherwise. sl@0: */ sl@0: EXPORT_C TBool EscapeUtils::IsEscapeTriple(const TDesC8& aData, TInt& aHexValue) sl@0: { sl@0: return CheckAndConvertEscapeTriple(aData, aHexValue); sl@0: } sl@0: sl@0: /** sl@0: Checks for an escape triple at the start of the input descriptor. If there is a triple sl@0: its value is calculated and returned through the output argument aHexValue. If there is sl@0: no escape triple then this argument is left unchanged. sl@0: sl@0: @since 6.0 sl@0: @param aData The descriptor to be checked for an escape triple. sl@0: @param aHexValue The output argument with the value of the escape triple sl@0: if it exists. sl@0: @return A boolean value of ETrue if there is an escape triple at the start of sl@0: the input descriptor, EFalse otherwise. sl@0: */ sl@0: EXPORT_C TBool EscapeUtils::IsEscapeTriple(const TDesC16& aData, TInt& aHexValue) sl@0: { sl@0: return CheckAndConvertEscapeTriple(aData, aHexValue); sl@0: } sl@0: sl@0: /** sl@0: returns the escape encoded descriptor output. This checks the every character of aData sl@0: against aCharsToEscape and if it exist then it escape encodes that character. sl@0: sl@0: @param aData The descriptor to be checked against escaping set of characters. sl@0: @param aCharsToEscape The set of escape characters. sl@0: @return A pointer to the escape encoded descriptor. sl@0: */ sl@0: EXPORT_C HBufC8* EscapeUtils::SpecificEscapeEncodeL ( const TDesC8& aData, const TDesC8& aCharsToEscape ) sl@0: { sl@0: // Descriptor to hex digits and excluded chars sl@0: const TDesC& KHexChars = KHexDigit; sl@0: sl@0: const TInt length = aData.Length(); sl@0: sl@0: // find out how many characters need escape encoding sl@0: TInt count = 0; sl@0: for( TInt i=0; i 0x7E ) sl@0: { sl@0: count++; sl@0: } sl@0: } sl@0: if( count == 0) // no encoding needed, just allocate and return the whole string sl@0: { sl@0: return aData.AllocL(); sl@0: } sl@0: sl@0: // pre-allocate space for the descriptor sl@0: HBufC8* buf = HBufC8::NewLC( length + count*2 ); // two extra chars for each escaped sl@0: TPtr8 escaped = buf->Des(); sl@0: sl@0: for( TInt i=0; i 0x7E; sl@0: sl@0: if( excluded ) sl@0: { sl@0: // Excluded char - escape encode sl@0: escaped.Append(KEscapeIndicator); sl@0: const TInt mostSignificantNibble = (current & 0xf0) >> 4; // Get msNibble by masking against 11110000 and dividing by 16 (>>4) sl@0: escaped.Append(KHexChars[mostSignificantNibble]); sl@0: const TInt leastSignificantNibble = (current & 0x0f); // Get lsNibble by masking against 00001111 sl@0: escaped.Append(KHexChars[leastSignificantNibble]); sl@0: } sl@0: else sl@0: { sl@0: // Not an excluded char - just append sl@0: escaped.Append(current); sl@0: } sl@0: } sl@0: CleanupStack::Pop(buf); sl@0: return buf; sl@0: } sl@0: sl@0: /** sl@0: The Dummy API is used to redirect to SpecificEscapeEncodeL() API in order to preserve BC and is made private sl@0: to ensure no-one else starts using it. sl@0: */ sl@0: EXPORT_C HBufC8* EscapeUtils::DummyForwardingFunctionForCompatibility( const TDesC8& aData, const TDesC8& aCharsToEscape ) sl@0: { sl@0: return EscapeUtils::SpecificEscapeEncodeL ( aData, aCharsToEscape ); sl@0: } sl@0: sl@0: sl@0: // sl@0: // sl@0: // Implementation of LOCAL functions sl@0: // sl@0: // sl@0: /** sl@0: Escape encodes the data, converting the reserved characters and excluded characters defined by sl@0: RFC2396 as escape triples. sl@0: sl@0: @since 6.0 sl@0: @warning This function will panic if the output descriptor aEncodedData is sl@0: not big enough to append all the data. sl@0: @param aData A descriptor with the data to encode. sl@0: @param aReservedChars Reserved characters set. sl@0: @param aEncodedData The output descriptor pointer where the escaped encoded sl@0: data is placed. sl@0: @return An error code of KUriUtilsErr16BitChar if the data contains a 16-bit sl@0: character. KErrNone if the data was successfully encoded. sl@0: */ sl@0: template sl@0: TInt EscapeEncodeData(const TDesCType& aData, const TDesCType& aReservedChars, TPtrType& aEncodedData) sl@0: { sl@0: // Descriptor to hex digits and excluded chars sl@0: const TDesC& KHexChars = KHexDigit; sl@0: sl@0: const TInt length = aData.Length(); sl@0: for( TInt i=0; i 0xff ) sl@0: { sl@0: __ASSERT_DEBUG(EFalse, User::Panic(KEscapeUtilsPanicCategory, KUriUtilsErr16BitChar)); sl@0: return (KUriUtilsErr16BitChar); sl@0: } sl@0: // Check if current character is excluded, a control character or a space sl@0: TBool excluded = EscapeUtils::IsExcludedChar(current) || aReservedChars.Locate(current) != KErrNotFound; sl@0: if ( excluded ) sl@0: { sl@0: // Excluded char - escape encode sl@0: aEncodedData.Append(KEscapeIndicator); sl@0: const TInt mostSignificantNibble = (current & 0xf0) >> 4; // Get msNibble by masking against 11110000 and dividing by 16 (>>4) sl@0: aEncodedData.Append(KHexChars[mostSignificantNibble]); sl@0: const TInt leastSignificantNibble = (current & 0x0f); // Get lsNibble by masking against 00001111 sl@0: aEncodedData.Append(KHexChars[leastSignificantNibble]); sl@0: } sl@0: else sl@0: { sl@0: // Not an excluded char or It's already Escape encode - just append sl@0: aEncodedData.Append(current); sl@0: } sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Escape decodes the data, converting escape triples back to their single character value. sl@0: sl@0: @since 6.0 sl@0: @warning This function will panic if the output descriptor aDecodedData is not big sl@0: enough to append all the data. sl@0: @param aData A descriptor with the data to decode. sl@0: @param aDecodedData The output descriptor pointer where the escaped decoded data sl@0: is placed. sl@0: @return An error code of KUriUtilsErr16BitChar if the data contains a 16-bit character. sl@0: KErrNone if the data was successfully encoded. sl@0: */ sl@0: template sl@0: TInt EscapeDecodeData(const TDesCType& aData, TPtrType& aDecodedData) sl@0: { sl@0: // Go through the descriptor sl@0: const TInt length = aData.Length(); sl@0: for( TInt i=0; i sl@0: TBool CheckAndConvertEscapeTriple(const TDesCType& aData, TInt& aHexValue) sl@0: { sl@0: // See if the descriptor is actually long enough sl@0: if( aData.Length() < KEscapeTripleLength ) sl@0: { sl@0: return EFalse; sl@0: } sl@0: // Check that the three characters form an escape triple - first char is '%' sl@0: if( aData[KEscDelimiterPos] != KEscapeIndicator ) sl@0: { sl@0: return EFalse; sl@0: } sl@0: // Descriptor to hex digits and excluded chars sl@0: const TDesC& KHexChars = KHexDigit; sl@0: sl@0: // Check that next two characters are valid sl@0: TChar mostSignificantNibble = aData[KMostSignificantNibblePos]; sl@0: TChar leastSignificantNibble = aData[KLeastSignificantNibblePos]; sl@0: sl@0: TInt mostSignificantNibbleValue = KHexChars.LocateF(mostSignificantNibble); sl@0: TInt leastSignificantNibbleValue = KHexChars.LocateF(leastSignificantNibble); sl@0: sl@0: if( mostSignificantNibbleValue == KErrNotFound || leastSignificantNibbleValue == KErrNotFound ) sl@0: { sl@0: // Either of the nibbles were not a valid hex character sl@0: return EFalse; sl@0: } sl@0: // Convert characters into hex value and return sl@0: aHexValue = 0x10*mostSignificantNibbleValue + 0x01*leastSignificantNibbleValue; sl@0: return ETrue; sl@0: }