[PATCH] D41490: [YAML] Fix UTF-8 handling
Francis Visoiu Mistrih via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 21 09:15:13 PST 2017
This revision was automatically updated to reflect the committed changes.
thegameg marked 2 inline comments as done.
Closed by commit rL321283: [YAML] Fix UTF-8 handling (authored by thegameg, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D41490?vs=127880&id=127901#toc
Repository:
rL LLVM
https://reviews.llvm.org/D41490
Files:
llvm/trunk/lib/Support/YAMLTraits.cpp
llvm/trunk/unittests/Support/YAMLIOTest.cpp
Index: llvm/trunk/lib/Support/YAMLTraits.cpp
===================================================================
--- llvm/trunk/lib/Support/YAMLTraits.cpp
+++ llvm/trunk/lib/Support/YAMLTraits.cpp
@@ -657,7 +657,12 @@
}
i = j + 1;
} else if (MustQuote == QuotingType::Double &&
- !sys::unicode::isPrintable(S[j])) {
+ !sys::unicode::isPrintable(S[j]) && (S[j] & 0x80) == 0) {
+ // If we're double quoting non-printable characters, we prefer printing
+ // them as "\x" + their hex representation. Note that special casing is
+ // needed for UTF-8, where a byte may be part of a UTF-8 sequence and
+ // appear as non-printable, in which case we want to print the correct
+ // unicode character and not its hex representation.
output(StringRef(&Base[i], j - i)); // "flush"
output(StringLiteral("\\x"));
Index: llvm/trunk/unittests/Support/YAMLIOTest.cpp
===================================================================
--- llvm/trunk/unittests/Support/YAMLIOTest.cpp
+++ llvm/trunk/unittests/Support/YAMLIOTest.cpp
@@ -2541,3 +2541,31 @@
ostr.flush();
EXPECT_EQ("'abc''fdf'", out);
}
+
+TEST(YAMLIO, TestEscapedUTF8SingleQuoteInsideDoubleQuote) {
+ std::string Id = "parameter 'параметр' is unused";
+
+ std::string out;
+ llvm::raw_string_ostream ostr(out);
+ Output xout(ostr, nullptr, 0);
+
+ llvm::yaml::EmptyContext Ctx;
+ yamlize(xout, Id, true, Ctx);
+
+ ostr.flush();
+ EXPECT_EQ("\"parameter 'параметр' is unused\"", out);
+}
+
+TEST(YAMLIO, TestEscapedUTF8) {
+ std::string Id = "/*параметр*/";
+
+ std::string out;
+ llvm::raw_string_ostream ostr(out);
+ Output xout(ostr, nullptr, 0);
+
+ llvm::yaml::EmptyContext Ctx;
+ yamlize(xout, Id, true, Ctx);
+
+ ostr.flush();
+ EXPECT_EQ("\"/*параметр*/\"", out);
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41490.127901.patch
Type: text/x-patch
Size: 1866 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171221/8b930571/attachment.bin>
More information about the llvm-commits
mailing list