| 28 | } |
| 29 | |
| 30 | vector<uchar> wideToBytes(const wstring &text, UINT cp, bool nullTerminated) { |
| 31 | const int len = ::WideCharToMultiByte(cp, 0, text.c_str(), -1, nullptr, 0, nullptr, nullptr); |
| 32 | if (len <= 0) |
| 33 | return {}; |
| 34 | vector<uchar> bin(static_cast<size_t>(len)); |
| 35 | ::WideCharToMultiByte(cp, 0, text.c_str(), -1, reinterpret_cast<LPSTR>(bin.data()), len, nullptr, nullptr); |
| 36 | if (!nullTerminated && !bin.empty() && bin.back() == 0) |
| 37 | bin.pop_back(); |
| 38 | return bin; |
| 39 | } |
| 40 | |
| 41 | wstring decodeUnicodeBytes(const vector<uchar> &bin) { |
| 42 | if (bin.size() < sizeof(wchar_t)) |
no test coverage detected