All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
characterEncodingConvertWin32.cc
Go to the documentation of this file.
2 #ifdef _WIN32
3 #include <windows.h>
4 #include <cassert>
5 
6 #define CP_EUCJP 20932
7 //#define CP_EUCJP 51932 not supported by MultiByteToWideChar
8 #define CP_SJIS 932
9 
10 std::string osl::misc::
11 eucToLang(const std::string& src) {
12  const int wlen = MultiByteToWideChar(CP_EUCJP, 0,
13  src.c_str(), src.size(),
14  NULL, 0);
15  assert(wlen>0);
16  wchar_t wbuf[wlen];
17  const int wret = MultiByteToWideChar(CP_EUCJP, 0,
18  src.c_str(), src.size(),
19  wbuf, wlen);
20  if (!wret || wlen != wret) {
21  return "";
22  }
23 
24  const int len = WideCharToMultiByte(CP_SJIS, 0,
25  wbuf, wret,
26  NULL, 0,
27  NULL, NULL);
28  assert(len>0);
29  char buf[len];
30  const int ret = WideCharToMultiByte(CP_SJIS, 0,
31  wbuf, wret,
32  buf, len,
33  NULL, NULL);
34  if (!ret || len != ret) {
35  return "";
36  }
37 
38  return std::string(buf, ret);
39 }
40 
41 #endif
42 // ;;; Local Variables:
43 // ;;; mode:c++
44 // ;;; c-basic-offset:2
45 // ;;; End: