llvm.org GIT mirror llvm / dd3d1e9
[YAML] Fix UTF-8 handling Previous YAML quoting patches broke UTF-8 printing in YAML: see https://reviews.llvm.org/D41290#961801. Differential Revision: https://reviews.llvm.org/D41490 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321283 91177308-0d34-0410-b5e6-96231b3b80d8 Francis Visoiu Mistrih 2 years ago
2 changed file(s) with 34 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
656656 }
657657 i = j + 1;
658658 } else if (MustQuote == QuotingType::Double &&
659 !sys::unicode::isPrintable(S[j])) {
659 !sys::unicode::isPrintable(S[j]) && (S[j] & 0x80) == 0) {
660 // If we're double quoting non-printable characters, we prefer printing
661 // them as "\x" + their hex representation. Note that special casing is
662 // needed for UTF-8, where a byte may be part of a UTF-8 sequence and
663 // appear as non-printable, in which case we want to print the correct
664 // unicode character and not its hex representation.
660665 output(StringRef(&Base[i], j - i)); // "flush"
661666 output(StringLiteral("\\x"));
662667
25402540 ostr.flush();
25412541 EXPECT_EQ("'abc''fdf'", out);
25422542 }
2543
2544 TEST(YAMLIO, TestEscapedUTF8SingleQuoteInsideDoubleQuote) {
2545 std::string Id = "parameter 'параметр' is unused";
2546
2547 std::string out;
2548 llvm::raw_string_ostream ostr(out);
2549 Output xout(ostr, nullptr, 0);
2550
2551 llvm::yaml::EmptyContext Ctx;
2552 yamlize(xout, Id, true, Ctx);
2553
2554 ostr.flush();
2555 EXPECT_EQ("\"parameter 'параметр' is unused\"", out);
2556 }
2557
2558 TEST(YAMLIO, TestEscapedUTF8) {
2559 std::string Id = "/*параметр*/";
2560
2561 std::string out;
2562 llvm::raw_string_ostream ostr(out);
2563 Output xout(ostr, nullptr, 0);
2564
2565 llvm::yaml::EmptyContext Ctx;
2566 yamlize(xout, Id, true, Ctx);
2567
2568 ostr.flush();
2569 EXPECT_EQ("\"/*параметр*/\"", out);
2570 }