MCPcopy Create free account
hub / github.com/ablab/spades / fixUTF8

Function fixUTF8

ext/src/llvm/JSON.cpp:546–561  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

544}
545
546std::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
563static void quote(llvm::raw_ostream &OS, llvm::StringRef S) {
564 OS << '\"';

Callers 3

attributeBeginMethod · 0.85
ValueMethod · 0.85
ObjectKeyMethod · 0.85

Calls 5

ConvertUTF8toUTF32Function · 0.85
ConvertUTF32toUTF8Function · 0.85
sizeMethod · 0.45
dataMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected