Taken from https://stackoverflow.com/questions/215963/ Convert a wide Unicode string to an UTF8 string
| 7 | // Taken from https://stackoverflow.com/questions/215963/ |
| 8 | // Convert a wide Unicode string to an UTF8 string |
| 9 | std::string utf8_encode(const std::wstring& wstr) |
| 10 | { |
| 11 | if (wstr.empty()) return std::string(); |
| 12 | |
| 13 | int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int) wstr.size(), nullptr, 0, nullptr, nullptr); |
| 14 | std::string strTo(size_needed, 0); |
| 15 | WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int) wstr.size(), &strTo[0], size_needed, nullptr, nullptr); |
| 16 | |
| 17 | return strTo; |
| 18 | } |
| 19 | |
| 20 | // Convert an UTF8 string to a wide Unicode String |
| 21 | std::wstring utf8_decode(const std::string& str) |