Wxstring string encoding and conversion

Source: Internet
Author: User

After installing Ubuntu on powerpc, I also found some problems, the main problem is: the system installed zh_CN.UTF-8 as locale by default, and cannot be changed (should be I have no way to find it? However, Debian does a good job at this point. You can use base-config to change locale, which is very convenient. In ubuntu, is the dpkg-reconfigure wireless space F? W. L/L p
Localeconf. You can only select the language for the result, but not the encoding ). But that's right. You can try me.WxWidgetsThe Unicode version of the project. Directly compile the Wx library, compile the relevant project, and run it. Of course, there is an error, garbled! The reason is that the string encoding used in the Code is incorrect. After carefully reading the relevant content in the document, I finally ruled out this error. The relevant records are as follows. Wireless space 3n6i M: M $ R p

I18n procedures include the following steps: wireless space 7 s y n L * l W0? ~ $ ~ * B
1. Use wxgettranslation () or _ () to process text in the program; wireless space E] d $ C5? L |
2. Wireless space G + v3e K ['w
The xgettext program extracts the text to be translated from the source code. xgettext can automatically identify two types of strings: wxgettranslation () and _ (), and can also automatically extract all strings, but this is not necessary; wireless space 0a} d | I $ V N. q1b?
3.
! E0f s3n A a9w j1a0 translates strings that have been saved in the. Po file into other required languages;
Z m p f h p04. use msgfmt tool to compile the. Po file into a binary. Mo file; wireless space-z I k _) B3G y l: H % t
5. Wireless space 0 [P (k t [| u
Set the corresponding locale in the program to enable the strings of the corresponding language.
H (N, n a n3j Z-Q0

The wxmbconv class and its derived subclasses are used for string encoding and conversion, including wxmbconvutf7, wxmbconvutf8, wxcsconv, wxmbconvutf16, and wxmbconvutf32.
L9n & J h4j W: ^, A @/E0

The mb2wc and wc2mb functions in wxmbconv are pure virtual functions. Therefore, the subclass must implement this function and wxmbconv instances cannot be created. Note the definition and use of the following functions: wireless space 5/x a; s )? V1o. f

Size_t mb2wc (wchar_t * outbuf, const char * inbuf, size_t outsize) wireless space: ', V "[] ^/
Const;
S1b, e w l z0 converts the multi-byte encoded string in inbuf into a unicode string of the wchar_t type and saves it to outbuf. The output buffer outbuf size is outsize, the function returns the length of the converted string. If the output buffer outbuf is null, only the length of the Conversion Result is returned.
$ L: g B n3j0

Size_t wx2mb (char * outbuf, const wchar_t * inbuf, size_t outsize) wireless space d' P l5c
Const; wireless space * q /? K # M * e.s S/3 @ f o
This function is similar to mb2wc. It converts a unicode string of the wchar_t type into a string of the Multi-byte encoding type.
Q? C u m, R. C P0

Const wxwcharbuffer cmb2wc (const char * psz) const;
J. a A: t "F'] V: G0 converts a multi-byte string to a unicode string. Wireless space s * k + t7v} n j5o E

Const wxcharbuffer cwc2mb (const wchar_t * psz) const;
, S z w v0g & D0 conversion from Unicode string to multi-byte string. Wireless Space Y + J a "u h q c4k G" v "R

Const char * cmb2wx (const char * psz) const; // ANSI
M s p B a3c + r) | 4E e0const wxwcharbuffer cmb2wx (const char * psz) const; // Unicode
E7l u] P x0 converts a multi-byte encoded string to the current encoding type of the system. In the ANSI version, input parameters are directly returned and nothing is done. In the Unicode version, the cmb2wc () function is used for encoding and conversion.
7d6f s w! U f p y0

Const char * cwx2mb (const wxchar * psz) const; // ANSI wireless space 'M $ U: y w, H.] h t
Const wxcharbuffer cwx2mb (const wxchar * psz) const; // Unicode wireless space P w6m [L}
Converts a string of the current encoding type to a multi-byte encoding string. In the ANSI version, input parameters are directly returned and nothing is done. In the Unicode version, the conversion is performed using the cwc2mb () function. Wireless space N d o y f'1e & Q

Const wchar_t * cwc2wx (const wchar_t * psz) const; // Unicode
4Y v s + L w8' I B m0const wxcharbuffer cwc2wx (const char_t * psz) const; // ANSI wireless space u y # t7r rh + x0 {* y
Converts a unicode string to a string of the current encoding type. In the ANSI version, the function cwc2mb () is used for encoding conversion. In the Unicode version, the input parameters are directly returned and nothing is done. Wireless Space & B %} % f8p l g7b

Const wchar_t * cwx2wc (const wxchar * psz) const; // wireless space s g-F; f g "g; I ~ L B
Const wxwcharbuffer cwx2wc (const wxchar * psz) const ;//
2f d v y f C0 converts a string of the current encoding type into a unicode encoded string. In the ANSI version, the cmb2wc () function is used for encoding conversion. In the Unicode version, the input parameters are directly returned and nothing is done.
W} l g L | [* C'} 0

Based on the above knowledge, we define the ANSI string types of STL and wxWidgetsWxstringThe conversion functions of string types are defined and implemented as follows:
1g u (y7s I @ & Z (r) _ 0

Inline string wxstring2string (in const wxstring & SRC) wireless space Q H5] V 'q9w: l i8l, e n % G
{
! R RR o p | * P ^ 1B P M0 wxcsconv cvgb2312 (wxt ("gb2312 "));
E % s] 'd # B & t7x0 return string (cvgb2312.cwx2mb (SRC. c_str (); wireless space + w l] | V H) Q v/hn4i

 

}
9i, S-K branch] y0 wireless space L + B: T n. I

InlineWxstringString2wxstring (in const string & SRC)
L s t "@ Z l0 {wireless space (x2b" S % T * s d
Wxcsconv cvgb2312 (wxt ("gb2312"); wireless space/Q & | # a0t $ @ F Q
ReturnWxstring(Cvgb2312.cmb2wx (SRC. c_str (); wireless space S-N-E} A-C ^ 2o4.7: x

 

}
-_ 9 t p6to B6 ^] 0
N4t $ q4n t0

It has been successfully tested on multiple platforms.
G p5k & M _-A; E0

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.