| 544 | } |
| 545 | |
| 546 | std::string fixUTF8(llvm::StringRef S) { |
| 547 | // This isn't particularly efficient, but is only for error-recovery. |
| 548 | std::vector<UTF32> Codepoints(S.size()); // 1 codepoint per byte suffices. |
| 549 | const UTF8 *In8 = reinterpret_cast<const UTF8 *>(S.data()); |
| 550 | UTF32 *Out32 = Codepoints.data(); |
| 551 | ConvertUTF8toUTF32(&In8, In8 + S.size(), &Out32, Out32 + Codepoints.size(), |
| 552 | lenientConversion); |
| 553 | Codepoints.resize(Out32 - Codepoints.data()); |
| 554 | std::string Res(4 * Codepoints.size(), 0); // 4 bytes per codepoint suffice |
| 555 | const UTF32 *In32 = Codepoints.data(); |
| 556 | UTF8 *Out8 = reinterpret_cast<UTF8 *>(&Res[0]); |
| 557 | ConvertUTF32toUTF8(&In32, In32 + Codepoints.size(), &Out8, Out8 + Res.size(), |
| 558 | strictConversion); |
| 559 | Res.resize(reinterpret_cast<char *>(Out8) - Res.data()); |
| 560 | return Res; |
| 561 | } |
| 562 | |
| 563 | static void quote(llvm::raw_ostream &OS, llvm::StringRef S) { |
| 564 | OS << '\"'; |
no test coverage detected