| 398 | } |
| 399 | |
| 400 | [[gnu::pure]] |
| 401 | static AllocatedString |
| 402 | Windows1252ToUTF8(const char *s) noexcept |
| 403 | { |
| 404 | #ifdef HAVE_ICU_CONVERTER |
| 405 | try { |
| 406 | return IcuConverter::Create("windows-1252")->ToUTF8(s); |
| 407 | } catch (...) { } |
| 408 | #endif |
| 409 | |
| 410 | /* |
| 411 | * Fallback to not transcoding windows-1252 to utf-8, that may result |
| 412 | * in invalid utf-8 unless nonprintable characters are replaced. |
| 413 | */ |
| 414 | AllocatedString t(s); |
| 415 | |
| 416 | for (size_t i = 0; t[i] != AllocatedString::SENTINEL; i++) |
| 417 | if (!IsPrintableASCII(t[i])) |
| 418 | t[i] = '?'; |
| 419 | |
| 420 | return t; |
| 421 | } |
| 422 | |
| 423 | [[gnu::pure]] |
| 424 | static AllocatedString |