| 137 | #ifdef _WIN32 |
| 138 | |
| 139 | std::string CodePageToUTF8Win(const std::string& str, unsigned int code_page) { |
| 140 | int wide_len = MultiByteToWideChar(code_page, 0, str.c_str(), -1, nullptr, 0); |
| 141 | if (wide_len <= 0) return ""; |
| 142 | |
| 143 | std::wstring wide_str(wide_len, L'\0'); |
| 144 | MultiByteToWideChar(code_page, 0, str.c_str(), -1, &wide_str[0], wide_len); |
| 145 | |
| 146 | int utf8_len = WideCharToMultiByte( |
| 147 | CP_UTF8, 0, wide_str.c_str(), -1, nullptr, 0, nullptr, nullptr); |
| 148 | if (utf8_len <= 0) return ""; |
| 149 | |
| 150 | std::string utf8_str(utf8_len, '\0'); |
| 151 | WideCharToMultiByte(CP_UTF8, |
| 152 | 0, |
| 153 | wide_str.c_str(), |
| 154 | -1, |
| 155 | &utf8_str[0], |
| 156 | utf8_len, |
| 157 | nullptr, |
| 158 | nullptr); |
| 159 | |
| 160 | if (!utf8_str.empty() && utf8_str.back() == '\0') { |
| 161 | utf8_str.pop_back(); |
| 162 | } |
| 163 | |
| 164 | return utf8_str; |
| 165 | }; |
| 166 | |
| 167 | std::string UTF8ToCodePageWin(const std::string& str, unsigned int code_page) { |
| 168 | int wide_len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0); |