characterEncodingConvertWin32.cc
Go to the documentation of this file.
00001 #include "osl/misc/characterEncodingConvertWin32.h"
00002 #ifdef _WIN32
00003 #include <windows.h>
00004 #include <cassert>
00005 
00006 #define CP_EUCJP 20932
00007 //#define CP_EUCJP 51932 not supported by MultiByteToWideChar
00008 #define CP_SJIS  932
00009 
00010 std::string osl::misc::
00011 eucToLang(const std::string& src) {
00012   const int wlen = MultiByteToWideChar(CP_EUCJP, 0,
00013                                        src.c_str(), src.size(),
00014                                        NULL, 0);
00015   assert(wlen>0);
00016   wchar_t wbuf[wlen];
00017   const int wret = MultiByteToWideChar(CP_EUCJP, 0,
00018                                        src.c_str(), src.size(),
00019                                        wbuf, wlen);
00020   if (!wret || wlen != wret) {
00021     return "";
00022   }
00023 
00024   const int len = WideCharToMultiByte(CP_SJIS, 0,
00025                                       wbuf, wret,
00026                                       NULL, 0,
00027                                       NULL, NULL);
00028   assert(len>0);
00029   char buf[len];
00030   const int ret = WideCharToMultiByte(CP_SJIS, 0,
00031                                       wbuf, wret,
00032                                       buf, len,
00033                                       NULL, NULL);
00034   if (!ret || len != ret) {
00035     return "";
00036   }
00037 
00038   return std::string(buf, ret);
00039 }
00040 
00041 #endif
00042 // ;;; Local Variables:
00043 // ;;; mode:c++
00044 // ;;; c-basic-offset:2
00045 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines