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