| 167 | } |
| 168 | |
| 169 | std::string WideToUtf8String(const std::wstring& wStr) |
| 170 | { |
| 171 | std::string ret; |
| 172 | const int length = WideCharToMultiByte( |
| 173 | CP_UTF8, |
| 174 | WC_ERR_INVALID_CHARS, |
| 175 | wStr.c_str(), |
| 176 | static_cast<int>(wStr.size()), |
| 177 | nullptr, |
| 178 | 0, |
| 179 | nullptr, |
| 180 | nullptr); |
| 181 | if (length <= 0) |
| 182 | throw std::runtime_error("WideCharToMultiByte failed"); |
| 183 | ret.resize(length); |
| 184 | WideCharToMultiByte( |
| 185 | CP_UTF8, |
| 186 | WC_ERR_INVALID_CHARS, |
| 187 | wStr.c_str(), |
| 188 | static_cast<int>(wStr.size()), |
| 189 | ret.data(), |
| 190 | length, |
| 191 | nullptr, |
| 192 | nullptr); |
| 193 | return ret; |
| 194 | } |
| 195 | |
| 196 | std::wstring Utf8ToWideString(const std::string& str) |
| 197 | { |
no outgoing calls
no test coverage detected