Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 13:18, 8 December 2007.

Converting text to Unicode text

From Forum Nokia Wiki

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 thevalue 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.

Related Discussions
Thread Thread Starter Forum Replies Last Post
Converting TTime data to text ashbhatia Symbian User Interface 1 2002-09-26 05:50
Get the code mode of text file abolfoooud General Symbian C++ 8 2008-02-19 16:12
CAknSingleHeadingPopupMenuS tyleListBox some Q? Jeepy General Symbian C++ 0 1970-01-01 02:00
Read Chinese Text file and Display Chinese on Canvas Problem? goeast Mobile Java General 4 2002-09-18 03:28
Read file Unicode Nokia_Archive General Symbian C++ 1 2002-05-29 13:34
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX