説明を見る。00001 #include "osl/misc/eucToLang.h"
00002
00003 #ifdef _WIN32
00004 #include <windows.h>
00005 #include <cassert>
00006 #define CP_EUCJP 20932
00007
00008 #define CP_SJIS 932
00009 #else
00010 #include "osl/misc/iconvConvert.h"
00011 #endif
00012
00013 std::string osl::misc::
00014 eucToLang(const std::string& src) {
00015 #ifdef _WIN32
00016 const int wlen = MultiByteToWideChar(CP_EUCJP, 0,
00017 src.c_str(), src.size(),
00018 NULL, 0);
00019 assert(wlen>0);
00020 wchar_t wbuf[wlen];
00021 const int wret = MultiByteToWideChar(CP_EUCJP, 0,
00022 src.c_str(), src.size(),
00023 wbuf, wlen);
00024 if (!wret || wlen != wret) {
00025 return "";
00026 }
00027
00028 const int len = WideCharToMultiByte(CP_SJIS, 0,
00029 wbuf, wret,
00030 NULL, 0,
00031 NULL, NULL);
00032 assert(len>0);
00033 char buf[len];
00034 const int ret = WideCharToMultiByte(CP_SJIS, 0,
00035 wbuf, wret,
00036 buf, len,
00037 NULL, NULL);
00038 if (!ret || len != ret) {
00039 return "";
00040 }
00041
00042 return std::string(buf, ret);
00043 #else
00044 return IconvConvert::eucToLang(src);
00045 #endif
00046 }
00047
00048
00049
00050
00051