// ----------------------------------------------------------------------------- // UnicodeTextUtil::ConvertASCIIInPlace // Converts all ASCII *in-place* from either Half to Full-width or vice versa, // depending on the direction specified by aDirection. // Returns: The total number of characters converted. // ----------------------------------------------------------------------------- // TInt UnicodeTextUtil::ConvertASCIIInPlace( TConvDirection aDirection, TDes16& aUnicodeText ) { TInt totalConverted( 0 ); TText lowerBound( ( aDirection == EHalfToFullWidth ) ? KHalfWidthASCIILowerBound : KFullWidthASCIILowerBound ); TText upperBound( ( aDirection == EHalfToFullWidth ) ? KHalfWidthASCIIUpperBound : KFullWidthASCIIUpperBound ); TInt offset( ( aDirection == EHalfToFullWidth ) ? KHalfToFullWidthASCIIOffset : -KHalfToFullWidthASCIIOffset ); for( TInt i( 0 ); i < aUnicodeText.Length(); ++i ) { const TText uniChar( aUnicodeText[i] ); if( uniChar >= lowerBound && uniChar <= upperBound ) { TText convertedChar( static_cast<TText>( uniChar + offset ) ); aUnicodeText[i] = convertedChar; totalConverted++; } } return totalConverted; }
void CBatmonContainer::Temperature(TDes16& aValue,TUint16 aAddress) const { TRAPD(err,HWNetmon::ValueL(KPhoneEnergyUnit,aAddress,aValue,HWNetmon::EExt|HWNetmon::ERaw)); if(err==KErrNone&&aValue.Length()>2) { TInt value=aValue[1]*256+aValue[2]-273; aValue.Num(value); aValue.Append(0xb0); aValue.Append('C'); } else { aValue.Zero(); aValue.Append('?'); } }
static void Hellenize(TDes16& text) { static const TUint16* roman = (TUint16*)(L"ABGDEZJQIKLMNXOPRVSTUFHCW"); for (int i = 0; i < text.Length(); i++) for (int j = 0; j < 25; j++) if (roman[j] == text[i]) { text[i] = (TUint16)(0x391 + j); break; } else if (roman[j] + 32 == text[i]) { text[i] = (TUint16)(0x3B1 + j); break; } }
/** * Converts a descriptor of type TBuf16 to character stream * * @param aSrc is the descriptor to be converted , aDes is the * reference to the character sream where the result of conversion * is stored , n_size specifies the conversion size of the string * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, * -2 is EInvalidSize , -4 is EInvalidPointer, -8 is EInvalidWCSSequence) */ EXPORT_C int Tbuf16ToChar(TDes16& aSrc, char* aDes, int& n_size) { unsigned int ilen = aSrc.Length(); int retval = ESuccess; wchar_t *temp16String = NULL; int minusone = -1; if (0 == ilen) { return EDescriptorNoData; } else if(!aDes) { return EInvalidPointer; } else if(n_size < ilen*2+1) { n_size = ilen*2; return EInvalidSize; } temp16String = new wchar_t [ilen+1]; if (!temp16String) { return EInsufficientSystemMemory; } wmemcpy(temp16String, (const wchar_t *)aSrc.Ptr(), ilen); temp16String[ilen] = L'\0'; if(minusone != wcstombs(aDes, (const wchar_t*)temp16String, ilen*2)) { aDes[ilen*2] = '\0'; } else { retval = EInvalidWCSSequence; } delete []temp16String; return retval; }
// ----------------------------------------------------------------------------- // UnicodeTextUtil::ConvertSpecialCharactersInPlace // Converts all special characters in the aUnicodeText descriptor in-place // that have both Full and Half-width variants. // Conversion occurs in the direction specified by aDirection. // Returns: The total number of characters converted. // ----------------------------------------------------------------------------- // TInt UnicodeTextUtil::ConvertSpecialCharactersInPlace ( TConvDirection aDirection, TDes16& aUnicodeText ) { TInt totalConverted( 0 ); const TInt directionIndex( ( aDirection == EHalfToFullWidth ) ? KHalfWidthIndex : KFullWidthIndex ); for( TInt i( 0 ); i < aUnicodeText.Length(); ++i ) { const TText uniChar( aUnicodeText[i] ); for( TInt j( 0 ); j < KHalfWidthSpecialCharRange; ++j ) { if( uniChar == KHalfToFullWidthSpecialCharTable[j][directionIndex] ) { aUnicodeText[i] = KHalfToFullWidthSpecialCharTable[j][!directionIndex]; totalConverted++; break; } } } return totalConverted; }
void CBatmonContainer::Battery(TDes16& aValue,TUint16 aAddress) const { TInt value=0; TRAPD(err,HWNetmon::ValueL(KPhoneEnergyUnit,aAddress,aValue,HWNetmon::EExt|HWNetmon::ERaw)); if(err==KErrNone&&aValue.Length()>0) value=aValue[0]; aValue.Zero(); switch(value) { case 11: aValue.Append(_L("BL-4C")); break; case 12: aValue.Append(_L("BL-5C")); break; case 17: aValue.Append(_L("BL-6C")); break; default: aValue.Append('?'); break; } }
/** * Converts a descriptor of type RBuf16 to Wstring * * @param aSrc is the descriptor to be converted , aDes is the * reference to the Wstring array where the result of conversion * is stored * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, * -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData) */ EXPORT_C int Rbuf16ToWstring(TDes16& aSrc, wstring& aDes) { unsigned int ilen = aSrc.Length(); if (0 == ilen) { return EDescriptorNoData; } wchar_t* buf = new wchar_t[ilen+1]; if(!buf) { return EInsufficientSystemMemory; } wmemcpy (buf,(wchar_t *)aSrc.Ptr(), ilen); buf[ilen]=L'\0'; aDes.assign(buf); delete[] buf; return ESuccess; }
EXPORT_C int Tbuf16ToWstring(TDes16& aSrc, wstring& aDes) { unsigned int ilen = aSrc.Length(); if (0 == ilen) { return EDescriptorNoData; } wchar_t* wcharString = new wchar_t[ilen+1]; if (!wcharString) { return EInsufficientSystemMemory; } wmemcpy((wchar_t*)wcharString, (const wchar_t*)aSrc.Ptr(), ilen); wcharString[ilen] = L'\0'; aDes.assign(wcharString); delete []wcharString; return ESuccess; }
/* ------------------------------------------------------------------------------- Class: TDesLoggerOverflowHandler Method: Overflow Description: Simple overflow handling(16 bit) Parameters: TDes16 &aDes: in: Reference to over flow data Return Values: None Errors/Exceptions: None Status: Approved ------------------------------------------------------------------------------- */ void TDesLoggerOverflowHandler::Overflow( TDes16& aDes ) { __TRACE( KError, ( _L( "STIFLOGGER: Over flow" ) ) ); // If overflow TInt len( 0 ); len = aDes.Length(); // const TInt to TInt avoiding warnings TInt maxLogData = KMaxLogData; TInt maxTestFileName = KMaxFileName; // Overflow: Log() without aStyle or Log() with aStyle if ( ( iOverFlowSource == 1 || iOverFlowSource == 2 ) && maxLogData > 60 ) { // Log overflow info if info is in allowed limits aDes[len-2] = 13; // 13 or '\' in Symbian OS aDes[len-1] = 10; // 10 or 'n' in Symbian OS // ~60 iLogger->Send( 0, _L("Log() OVERFLOW: Check aLogInfo and KMaxLogData !!!") ); } // Overflow: WriteDelimiter() if ( iOverFlowSource == 3 && maxLogData > 70 ) { // Log overflow info if info is in allowed limits, ~70 iLogger->Send( 0, _L( "WriteDelimiter() OVERFLOW: Check delimiter and KMaxLogData !!!" ) ); } // Overflow: StartHtmlPage() if ( iOverFlowSource == 4 && maxTestFileName > 70 ) { // Log overflow info if info is in allowed limits, ~70 iLogger->Send( 0, _L( "aTestFile OVERFLOW: Check aTestFile and KMaxFileName !!!" ) ); } }
// ----------------------------------------------------------------------------- // JPLangUtil::ConvertFullToHalfWidthKatakana // Converts Full-width Katakana and Special Character text found in // aUnicodeSource to their Half-width counterparts and places the resulting text // into aUnicodeTarget. There will be a 2-for-1 conversion for each Full-width // Voiced and Semi-voiced Katakana character. // (detailed information about the parameters and return values can be found in // the header file) // ----------------------------------------------------------------------------- // EXPORT_C TInt JPLangUtil::ConvertFullToHalfWidthKatakana ( const TDesC16& aUnicodeSource, TDes16& aUnicodeTarget ) { TInt totalConverted( 0 ); const TInt length( aUnicodeSource.Length() ); const TInt maxLength( aUnicodeTarget.MaxLength() ); if( length > maxLength ) { return KErrTooBig; } aUnicodeTarget.Zero(); for( TInt i( 0 ); i < length; ++i ) { const TText uniChar( aUnicodeSource[i] ); // First check if this is this Full Width Katakana if( ( uniChar >= KFullWidthKatakanaLowerBound && uniChar <= KFullWidthKatakanaUpperBound ) || ( uniChar == KFullWidthKatakanaVoicedSoundMark || uniChar == KFullWidthKatakanaSemiVoicedSoundMark ) ) { // Then check if it is (Semi-)Voiced and convert it properly const TBool isVoiced( UnicodeTextUtil::IsFullWidthVoicedKatakana( uniChar ) ); const TBool isSemiVoiced( UnicodeTextUtil::IsFullWidthVoicedKatakana( uniChar, ETrue ) ); if( isVoiced || isSemiVoiced ) { if( aUnicodeTarget.Length() + 2 > maxLength ) { // This descriptor can't hold the new data aUnicodeTarget.Zero(); return KErrTooBig; } UnicodeTextUtil::ConvertVoicedKatakanaCharAndAppendToTarget( EFullToHalfWidth, uniChar, aUnicodeTarget, isSemiVoiced ); totalConverted++; } else { if( aUnicodeTarget.Length() + 1 > maxLength ) { // This descriptor can't hold the new data aUnicodeTarget.Zero(); return KErrTooBig; } aUnicodeTarget.Append( UnicodeTextUtil::ConvertKatakanaChar( EFullToHalfWidth, uniChar ) ); totalConverted++; } } // This is not Full Width Katakana, so copy directly... else { if( aUnicodeTarget.Length() + 1 > maxLength ) { // This descriptor can't hold the new data aUnicodeTarget.Zero(); return KErrTooBig; } const TChar uniCharacter( uniChar ); aUnicodeTarget.Append( uniCharacter ); } } // Now handle special characters // This logic may be moved into this function to avoid another loop over // the text totalConverted += UnicodeTextUtil::ConvertSpecialCharactersInPlace( EFullToHalfWidth, aUnicodeTarget ); return totalConverted; }