Convert a wide Unicode string to an UTF8 string
| 934 | |
| 935 | // Convert a wide Unicode string to an UTF8 string |
| 936 | std::string IGFD::Utils::UTF8Encode(const std::wstring& wstr) { |
| 937 | std::string res; |
| 938 | #ifdef _IGFD_WIN_ |
| 939 | if (!wstr.empty()) { |
| 940 | int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), nullptr, 0, nullptr, nullptr); |
| 941 | if (size_needed) { |
| 942 | res = std::string(size_needed, 0); |
| 943 | WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &res[0], size_needed, nullptr, nullptr); |
| 944 | } |
| 945 | } |
| 946 | #else |
| 947 | // Suppress warnings from the compiler. |
| 948 | (void)wstr; |
| 949 | #endif // _IGFD_WIN_ |
| 950 | return res; |
| 951 | } |
| 952 | |
| 953 | // Convert an UTF8 string to a wide Unicode String |
| 954 | std::wstring IGFD::Utils::UTF8Decode(const std::string& str) { |