-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringCoding.cpp
More file actions
21 lines (19 loc) · 791 Bytes
/
StringCoding.cpp
File metadata and controls
21 lines (19 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "StringCoding.h"
std::string convertUTF8(std::string source) {
std::wstring wResult;
int wLength = MultiByteToWideChar(CP_UTF8, 0, source.c_str(), source.size(), NULL, 0);
wResult.resize(wLength);
MultiByteToWideChar(CP_ACP, 0, source.c_str(), -1, &wResult[0], wLength);
std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8Conv;
return utf8Conv.to_bytes(wResult);
}
std::string unconvertUTF8(std::string source) {
std::wstring wTemp;
int wLength = MultiByteToWideChar(CP_UTF8, 0, source.c_str(), source.size(), NULL, 0);
wTemp.resize(wLength);
MultiByteToWideChar(CP_UTF8, 0, source.c_str(), source.size(), &wTemp[0], wLength);
std::string result;
result.resize(wLength);
WideCharToMultiByte(1251, 0, &wTemp[0], wLength, &result[0], wLength, 0, 0);
return result;
}