mirror of
https://github.com/staxrip/staxrip.git
synced 2026-10-24 10:11:17 +08:00
37 lines
1.2 KiB
C++
37 lines
1.2 KiB
C++
|
|
#include "Common.h"
|
|
|
|
///////////////////// convert strings
|
|
|
|
std::string ConvertWideToANSI(const std::wstring& wstr)
|
|
{
|
|
int count = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.length(), NULL, 0, NULL, NULL);
|
|
std::string str(count, 0);
|
|
WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, &str[0], count, NULL, NULL);
|
|
return str;
|
|
}
|
|
|
|
std::wstring ConvertAnsiToWide(const std::string& str)
|
|
{
|
|
int count = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), NULL, 0);
|
|
std::wstring wstr(count, 0);
|
|
MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), &wstr[0], count);
|
|
return wstr;
|
|
}
|
|
|
|
std::string ConvertWideToUtf8(const std::wstring& wstr)
|
|
{
|
|
int count = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), wstr.length(), NULL, 0, NULL, NULL);
|
|
std::string str(count, 0);
|
|
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &str[0], count, NULL, NULL);
|
|
return str;
|
|
}
|
|
|
|
std::wstring ConvertUtf8ToWide(const std::string& str)
|
|
{
|
|
int count = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), NULL, 0);
|
|
std::wstring wstr(count, 0);
|
|
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), &wstr[0], count);
|
|
return wstr;
|
|
}
|