02 | #define
_SUPPORT_TOOL_H_ |
03 | ////////////////////////////////////////////////////////////////////////// |
07 | ////////////////////////////////////////////////////////////////////////// |
09 | #define
A2U(varString) wSupportTool::AStrToUTF8(varString).c_str() //用于显示中文(窄字符) |
10 | #define
W2U(varString) wSupportTool::WStrToUTF8(varString).c_str() //用于显示中文(宽字符) |
12 | ////////////////////////////////////////////////////////////////////////// |
18 | static std::string
AStrToUTF8( const string&
src) |
20 | std::string
curLocale= setlocale (LC_ALL,NULL); |
22 | int len=src.length()+1; |
23 | wchar_t *str
= new wchar_t [len]; |
24 | int total= mbstowcs (str,src.c_str(),len); |
28 | setlocale (LC_ALL, curLocale.c_str()); |
29 | return WStrToUTF8(wstr); |
33 | static std::string
WStrToUTF8( const wstring&
src) |
37 | for ( size_t i = 0; i < src.size();i++){ |
40 | dest.push_back(( char )w); |
42 | dest.push_back(0xc0 | ((w >> 6)& 0x1f)); |
43 | dest.push_back(0x80|
(w & 0x3f)); |
46 | dest.push_back(0xe0 | ((w >> 12)& 0x0f)); |
47 | dest.push_back(0x80|
((w >> 6) & 0x3f)); |
48 | dest.push_back(0x80|
(w & 0x3f)); |
50 | /*else
if (sizeof(wchar_t) > 2 && w <= 0x10ffff){ |
51 | dest.push_back(0xf0 | ((w >> 18)& 0x07));//wchar_t 4-bytes situation |
52 | dest.push_back(0x80|
((w >> 12) & 0x3f)); |
53 | dest.push_back(0x80|
((w >> 6) & 0x3f)); |
54 | dest.push_back(0x80|
(w & 0x3f)); |
65 | 加入这个类后,只要在使用中文的时候,加上A2U或W2U宏就好了 |
68 | LabelTTF::create(A2U( "这是一个Label!" ), "Arial" ,
14); |
71 | string
Astr=A2U( "欢迎来到这个世界!" ); |
73 | LabelTTF::create(Astr, "Arial" ,
14); |
76 | LabelTTF::create(W2U(L "这是一个Label!" ), "Arial" ,
14); |
79 | string
Wstr=W2U(L "欢迎来到这个世界!" ); |
81 | LabelTTF::create(Wstr, "Arial" ,
14); |
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理