Commit 5c344193 authored by captainwong's avatar captainwong

mv win32 used mbcs to utf functions from utf8.h to win32.h

parent 7f8fb838
......@@ -45,15 +45,6 @@ namespace utf8 {
utf8::utf8to16(a.begin(), a.end(), std::back_inserter(w));
return w;
}
inline bool mbcs_to_u16(const char* mbcs, wchar_t* u16buffer, size_t u16size) {
size_t request_size = MultiByteToWideChar(CP_ACP, 0, mbcs, -1, NULL, 0);
if (1 < request_size && request_size < u16size) {
MultiByteToWideChar(CP_ACP, 0, mbcs, -1, u16buffer, request_size);
return true;
}
return false;
};
}
#endif // header guard
......@@ -2,6 +2,48 @@
#include <windows.h>
#include <string>
#include "utf8.h"
namespace utf8 {
inline bool mbcs_to_u16(const char* mbcs, wchar_t* u16buffer, size_t u16size) {
size_t request_size = MultiByteToWideChar(CP_ACP, 0, mbcs, -1, NULL, 0);
if (0 < request_size && request_size < u16size) {
MultiByteToWideChar(CP_ACP, 0, mbcs, -1, u16buffer, request_size);
return true;
}
return false;
};
inline std::wstring mbcs_to_u16(const std::string& mbcs) {
std::wstring res = L"";
size_t request_size = MultiByteToWideChar(CP_ACP, 0, mbcs.c_str(), -1, NULL, 0);
if (0 < request_size) {
auto u16buffer = new wchar_t[request_size];
MultiByteToWideChar(CP_ACP, 0, mbcs.c_str(), -1, u16buffer, request_size);
res = u16buffer;
delete[] u16buffer;
}
return res;
}
inline std::string u16_to_mbcs(const std::wstring& u16) {
std::string res = "";
size_t request_size = WideCharToMultiByte(CP_ACP, 0, u16.c_str(), -1, 0, 0, 0, 0);
if (0 < request_size) {
auto mbcs_buffer = new char[request_size];
WideCharToMultiByte(CP_ACP, 0, u16.c_str(), -1, mbcs_buffer, request_size, 0, 0);
res = mbcs_buffer;
delete[] mbcs_buffer;
}
return res;
}
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
namespace jlib {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment