Skip to content

Commit 0d1b38e

Browse files
committed
Optionally output simplified Chinese characters on the fly.
1 parent 4cbec04 commit 0d1b38e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Diff for: Utils.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "Utils.h"
2121
#include <Windows.h>
22+
#include <Winnls.h>
2223

2324
std::wstring utf8ToUtf16(const char* text) {
2425
std::wstring wtext;
@@ -41,3 +42,12 @@ std::string utf16ToUtf8(const wchar_t* wtext) {
4142
}
4243
return text;
4344
}
45+
46+
std::wstring tradToSimpChinese(const std::wstring& trad) {
47+
int len = ::LCMapStringW(0x0404, LCMAP_SIMPLIFIED_CHINESE, trad.c_str(), trad.length(), NULL, 0);
48+
std::wstring simp;
49+
simp.resize(len);
50+
if(::LCMapStringW(0x0404, LCMAP_SIMPLIFIED_CHINESE, trad.c_str(), trad.length(), &simp[0], len))
51+
return simp;
52+
return trad;
53+
}

Diff for: Utils.h

+3
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ std::wstring utf8ToUtf16(const char* text);
2727

2828
std::string utf16ToUtf8(const wchar_t* wtext);
2929

30+
// convert traditional Chinese to simplified Chinese
31+
std::wstring tradToSimpChinese(const std::wstring& trad);
32+
3033
#endif

0 commit comments

Comments
 (0)