×
Namespaces

Variants
Actions

Converting text to Unicode text

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: symbianyucca (22 Mar 2007)
Last edited: hamishwillee (20 Jul 2012)

CCnvCharacterSetConverter API is designed to be used when converting texts that is written in some other than Unicode format. Following function shows how it can be used to for text conversions:

void ConvertTextL(const TDesC8& aData,TDes& aText, TUint aConverter)
{
TInt state = CCnvCharacterSetConverter::KStateDefault;
CCnvCharacterSetConverter* CSConverter =
CCnvCharacterSetConverter::NewLC();
 
TPtrC8 Remainder(aData);
 
if (CSConverter->PrepareToConvertToOrFromL(aConverter,iFs) !=
CCnvCharacterSetConverter::EAvailable)
{
CSConverter->PrepareToConvertToOrFromL(aConverter,iFs);
}
 
for(;;)
{
const TInt returnValue =
CSConverter->ConvertToUnicode(aText,Remainder,state);
if (returnValue <= 0) // < error
{
break;
}
 
Remainder.Set(Remainder.Right(returnValue));
}
 
CleanupStack::PopAndDestroy(CSConverter);
}

aData is used to pass the text as byte buffer, you can get file read to the file buffer for example by using file reading example codes. aText is then used to store the Unicode text, note that with this example caller is responsible on allocating enough long buffer for the aText. aConverter is then character converters identifier, to get this value you could query supported character sets with following function:

CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* CharSets = 
CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(CCoeEnv::Static()->FsSession());
 
for(TInt i=0; i < CharSets->Count(); i++)
{
//CharSets->At(i).NameIsFileName()
//CharSets->At(i).Name()
//CharSets->At(i).Identifier()
}
 
CleanupStack::PopAndDestroy(); // CharSets

Which with you can get the value for aConverter from the Identifier()-function. The Name()-function has the name associated with the converter, this could be the full name for the converters file, or character sets name (like windows-874), to check which one the Name()-function returns, you could use NameIsFileName() function.

Note that supported character sets depends on the device’s model and can vary significantly between different devices. Also TIS-620, is named TIS_620 quite often, thus if you require some specific character converter to be present, you should check it manually from all target devices.

This page was last modified on 20 July 2012, at 10:20.
39 page views in the last 30 days.
×