[PATCH] D33961: encode YAML scalars using double quotes so all values can be expressed

Zachary Turner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 7 15:52:50 PDT 2017


zturner added inline comments.


================
Comment at: llvm/lib/Support/YAMLTraits.cpp:623
+    char C = Base[i];
+    if (C < 32 || C > 126) {
+      static const char hexits[17] = "0123456789abcdef";
----------------
Is there any reason not to use `isprint` here (the semantics of `isprint` are slightly different than your if-case, btw)


================
Comment at: llvm/lib/Support/YAMLTraits.cpp:624-627
+      static const char hexits[17] = "0123456789abcdef";
+      Encoded += "\\x";
+      Encoded += hexits[(C >> 4) & 0xf];
+      Encoded += hexits[C & 0xf];
----------------
You could use `Encoded += "\\x" + toHex(StringRef(&C, 1));` here.


================
Comment at: llvm/lib/Support/YAMLTraits.cpp:629
+    } else {
+      if (C == '\"' || C == '\\') {
+        Encoded += '\\';
----------------
It looks like the previous code did not escape backslashes.  Was this a bug in the previous code?  If so we should add a test for it.


https://reviews.llvm.org/D33961





More information about the llvm-commits mailing list