Home  >  Article  >  Backend Development  >  Symbian About character encoding conversion

Symbian About character encoding conversion

巴扎黑
巴扎黑Original
2016-12-20 14:51:451269browse

Commonly used string encoding Chinese representations are: GB2312, GBK, Unicode, UTF-8
GBK is a superset of GB2312, which means it covers all the contents of GB2312 encoding,
UTF-8 is Unicode in network transmission An encoding format,
If we use vc as a development tool and develop under win, then the default character set of win
is GBK, while the default encoding method of the symbian system is
Unicode, which means that it is written directly in When the Chinese characters in the program are displayed on the mobile phone,
will become garbled characters.
There are usually two ways to solve this problem:
(1) Static resource file solution
(2) Dynamically calling character set conversion function solution

Yes, for the first solution, you need to manually edit the rss file , change the Chinese character content part to UTF-8 format,
Add: CHARACTER_SET UTF8 at the end or beginning of the rss file
The disadvantage is that this kind of string is generally for static resources, if it is the kind of situation where Chinese characters are updated at any time according to data changes
You need to consider the second case

The method of dynamically converting the character set in the second case

CCnvCharacterSetConverter and CnvUtfConverter are often used to convert into Unicode encoding recognized by the Symbian system.

CCnvCharacterSetConverter class can be used for Symbian supported All encoding conversions

CnvUtfConverter is a class that converts between UTF-8 and Unicode and UTF-7 and Unicode


Add header file
#include // for char set convert GBK - Unicode
Add
LIBRARY in mmp charconv.lib // for GBK to Unicode converter

After these two steps are completed, recompile; the following two functions can be used.
void CMcAppUi::ConvGbk2Uni(TDesC8& original, TDes& res) {
#ifndef __WINS__
RFs aFileServerSession;
aFileServerSession.Connect();
CCnvCharacterSetConverter * converter=CCnvCharacterSetConverter::NewLC();
                                                                                 (KCharacterSetIdentifierGbk,aFileServerSession)!=CCnvCharacterSetConverter::EAvailable)
                   User::Leave(KErrNotSupported); ault; .Length() );
TPtr16 ptr = iInfoText->Des();

if(CCnvCharacterSetConverter::EErrorIllFormedInput == converter->ConvertToUnicode(ptr, str, state))
              User::Leave(KErrArgument);
                                                                res.Zero()                                                                         ext;
#else
res.Format(_L("wayne len %d "), original.Length()) ;
#endif
}

void CMcAppUi::ConvUni2Gbk(TDesC& original, TDes8& res) {
#ifndef __WINS__
    CCnvCharacterSetConverter* iConv ;
iConv = CCNVCHARACTERSETCONVERTER :: NewLC ();
IF (iconv-& GT; PreparetoconvertoorFroml (Kcharactersetablentifiergbk,













CNVCHARACTERSETCONVARTER :: Eavailable)
user :: leave (kelrnotsupported);
iconv-& gt; convertFromunicode (res, original, state) ; 🎜CleanupStack::PopAndDestroy() ;
#else
res.Format(_L8("wayne chen %s"), original) ;
#endif
}

Specific usage:
TBuf8<20> title8 ;
TBuf< 20 & gt; title16;
tbuf8 & lt; 20 & gt; msg8;
tbuf & lt; 20 & gt; msg16;
title8.Format (_L8 ("Friendship Tips"); Ormsg8.Format (_L8 ("Thank you Use ")) ;
ConvGbk2Uni(msg8, msg16) ;
ShowInfoDialog(title16, msg16) ;
That's it. Now title16 and msg16 both store 16-bit unicode Chinese strings,
can be displayed directly.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn