Symbian about character encoding conversion

Source: Internet
Author: User
String encoding Chinese expressions commonly used are: Gb2312,gbk,unicode,utf-8
Where GBK is a superset of GB2312, which covers all GB2312 encoded content,
UTF-8 is an encoding format for Unicode in network transmission,
If we use VC as a development tool, under win to develop, then win
The default character set is GBK, and the Symbian system default encoding is
Unicode, which means that characters written directly inside the program are displayed on the phone,
It will become garbled.
There are two common ways to solve this problem:
(1) static resource file solution
(2) dynamic calling character Set conversion function solution

Yes, yes. The first solution, you need to manually edit the RSS file, the part of the Chinese character content to UTF-8 format,
Add at the end or beginning of the RSS file: Character_set UTF8
The disadvantage is that this type of string is generally targeted at static resources, and if it is the kind that updates Chinese characters based on data changes
You need to consider the second case

The second way to dynamically convert character sets

The two classes of ccnvcharactersetconverter and cnvutfconverter are often used to convert to the Unicode encoding recognized by the Symbian system.

The Ccnvcharactersetconverter class can perform all encoding conversions supported by Symbian

Cnvutfconverter This class often UTF-8 with the conversion of Unicode and UTF-7 to Unicode


Add header File
#include <charconv.h>//For char set convert Gbk-unicode
Add in MMP
LIBRARY charconv.lib//For GBK to Unicode Converter

After these two steps have been completed, the following two functions are ready to be recompiled.
void Cmcappui::convgbk2uni (tdesc8& original, tdes& res) {
#ifndef __wins__
RFs afileserversession;
Afileserversession.connect ();
ccnvcharactersetconverter* CONVERTER=CCNVCHARACTERSETCONVERTER::NEWLC ();

if (CONVERTER-&GT;PREPARETOCONVERTTOORFROML (kcharactersetidentifiergbk,afileserversession)! = ccnvcharactersetconverter::eavailable)
User::leave (kerrnotsupported);

TInt State=ccnvcharactersetconverter::kstatedefault;

TPtrC8 Str (original);
hbufc* iinfotext = HBUFC::NEWL (str. Length ());
TPtr16 ptr = Iinfotext->des ();

if (Ccnvcharactersetconverter::eerrorillformedinput = = Converter->converttounicode (ptr, str, state))
User::leave (kerrargument);

Res. Zero ();
Res. Copy (PTR);
Afileserversession.close ();
Cleanupstack::P Opanddestroy ();
Delete Iinfotext;
#else
Res. Format (_l ("Wayne Len%d"), original. Length ());
#endif
}

void Cmcappui::convuni2gbk (tdesc& original, tdes8& res) {
#ifndef __wins__
TInt State=ccnvcharactersetconverter::kstatedefault;
ccnvcharactersetconverter* IConv;
IConv = CCNVCHARACTERSETCONVERTER::NEWLC ();
if (ICONV-&GT;PREPARETOCONVERTTOORFROML (KCHARACTERSETIDENTIFIERGBK,
Ieikonenv->fssession ())!=ccnvcharactersetconverter::eavailable)
User::leave (kerrnotsupported);
Iconv->convertfromunicode (Res, original, state);
Cleanupstack::P Opanddestroy ();
#else
Res. Format (_l8 ("Wayne Chen%s"), original);
#endif
}

Specific Use methods:
Tbuf8<20> Title8;
Tbuf<20> Title16;
Tbuf8<20> Msg8;
Tbuf<20> Msg16;
Title8. Format (_L8 ("Friendship hint"));
Convgbk2uni (Title8, TITLE16);
Msg8. Format (_L8 ("Thank you for your use");
Convgbk2uni (Msg8, MSG16);
Showinfodialog (Title16, MSG16);
Now, Title16 and MSG16 are all stored in a 16-bit Unicode Chinese string,
can be displayed directly.
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.