| 159 | } |
| 160 | |
| 161 | astr_t wstr_to_utf8(const wstr_t &aWstr) |
| 162 | { |
| 163 | #if defined(_MSC_VER) |
| 164 | int size = ::WideCharToMultiByte( |
| 165 | CP_UTF8, 0, &aWstr[0], (int)aWstr.size(), nullptr, 0, nullptr, nullptr); |
| 166 | astr_t result = ""; |
| 167 | |
| 168 | if (size > 0) |
| 169 | { |
| 170 | result.resize(size + 1); |
| 171 | ::WideCharToMultiByte( |
| 172 | CP_UTF8, 0, &aWstr[0], (int)aWstr.size(), &result[0], size, nullptr, nullptr); |
| 173 | result.resize(size); // result[size] = 0; |
| 174 | } |
| 175 | #else |
| 176 | mbstate_t state{}; |
| 177 | astr_t result{}; |
| 178 | auto p = aWstr.data(); |
| 179 | const auto size = wcsrtombs(nullptr, &p, 0, &state); |
| 180 | if (size > 0) |
| 181 | { |
| 182 | result.resize(size + 1); |
| 183 | wcsrtombs(&result[0], &p, size, &state); |
| 184 | result.resize(size); |
| 185 | } |
| 186 | #endif |
| 187 | |
| 188 | return result; |
| 189 | } |
| 190 | |
| 191 | wstr_t wstr_from_utf8(const astr_t &aStr) |
| 192 | { |
no test coverage detected