Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static std::string utf16ToUTF8(const std::wstring &s)
- {
- const int size = ::WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, NULL, 0, 0, NULL);
- std::vector<char> buf(size);
- ::WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, &buf[0], size, 0, NULL);
- return std::string(&buf[0]);
- }
- CStringW UTF8toUTF16(const CStringA& utf8)
- {
- CStringW utf16;
- int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
- if (len > 1)
- {
- wchar_t *ptr = utf16.GetBuffer(len - 1);
- if (ptr) MultiByteToWideChar(CP_UTF8, 0, utf8, -1, ptr, len);
- utf16.ReleaseBuffer();
- }
- return utf16;
- }
- LPWSTR stringToLPWSTR(const std::string& instr)
- {
- int bufferlen = ::MultiByteToWideChar(CP_ACP, 0, instr.c_str(), instr.size(), NULL, 0);
- LPWSTR widestr = new WCHAR[bufferlen + 1];
- ::MultiByteToWideChar(CP_ACP, 0, instr.c_str(), instr.size(), widestr, bufferlen);
- widestr[bufferlen] = 0;
- return widestr;
- }
- std::string ws2s(const std::wstring& wstr)
- {
- int size_needed = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), int(wstr.length() + 1), 0, 0, 0, 0);
- std::string strTo(size_needed, 0);
- WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), int(wstr.length() + 1), &strTo[0], size_needed, 0, 0);
- return strTo;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement