| 216 | } |
| 217 | |
| 218 | string mb_to_utf8(const char *s) |
| 219 | { |
| 220 | #ifdef __ANDROID__ |
| 221 | // Paranoia; all consumers already use the same code so this won't do |
| 222 | // anything new. |
| 223 | return utf8_validate(s); |
| 224 | #else |
| 225 | string d; |
| 226 | wchar_t c; |
| 227 | int l; |
| 228 | mbstate_t ps; |
| 229 | |
| 230 | memset(&ps, 0, sizeof(ps)); |
| 231 | // the input is zero-terminated, so third argument doesn't matter |
| 232 | while ((l = mbrtowc(&c, s, MB_LEN_MAX, &ps))) |
| 233 | { |
| 234 | if (l > 0) |
| 235 | s += l; |
| 236 | else |
| 237 | { // invalid input, mark it and try to recover |
| 238 | s++; |
| 239 | c = 0xFFFD; |
| 240 | } |
| 241 | |
| 242 | char buf[4]; |
| 243 | int r = wctoutf8(buf, c); |
| 244 | for (int i = 0; i < r; i++) |
| 245 | d.push_back(buf[i]); |
| 246 | } |
| 247 | return d; |
| 248 | #endif |
| 249 | } |
| 250 | |
| 251 | static bool _check_trail(FILE *f, const char* bytes, int len) |
| 252 | { |
no test coverage detected