\brief Convert wide char to UTF-8
| 49 | |
| 50 | /// \brief Convert wide char to UTF-8 |
| 51 | std::string CLIWide::wchar_to_utf8(const std::wstring& wstr) { |
| 52 | if (wstr.empty()) return std::string(); |
| 53 | |
| 54 | int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL); |
| 55 | if (size_needed == 0) { |
| 56 | return std::string(); |
| 57 | } |
| 58 | |
| 59 | std::string strTo(size_needed, 0); |
| 60 | int result = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL); |
| 61 | if (result == 0) { |
| 62 | return std::string(); |
| 63 | } |
| 64 | |
| 65 | return strTo; |
| 66 | } |
| 67 | |
| 68 | /// \brief Convert UTF-8 to wide char |
| 69 | std::wstring CLIWide::utf8_to_wchar(const std::string& str) { |