]> granicus.if.org Git - clang/commitdiff
When writing YAML in libclang, use yaml::escape instead of write_escaped
authorBen Langmuir <blangmuir@apple.com>
Thu, 17 Apr 2014 03:31:02 +0000 (03:31 +0000)
committerBen Langmuir <blangmuir@apple.com>
Thu, 17 Apr 2014 03:31:02 +0000 (03:31 +0000)
The YAMLParser has its own escaped string representation, and does not
handle octal escape sequences. When writing the virtual file system to a
YAML file, use yaml::escape().

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206443 91177308-0d34-0410-b5e6-96231b3b80d8

tools/libclang/BuildSystem.cpp
unittests/libclang/LibclangTest.cpp

index 89c6e91d23c27332adafada41b404b361baee364..c9d3c553273bd1ebb850ebf80b7f72e562a82042 100644 (file)
@@ -19,6 +19,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TimeValue.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/YAMLParser.h"
 
 using namespace clang;
 using namespace llvm::sys;
@@ -147,10 +148,9 @@ private:
       OS.indent(Indent) << "{\n";
       Indent += 2;
       OS.indent(Indent) << "'type': 'file',\n";
-      OS.indent(Indent) << "'name': \"";
-      OS.write_escaped(VName) << "\",\n";
-      OS.indent(Indent) << "'external-contents': \"";
-      OS.write_escaped(Entry.RPath) << "\"\n";
+      OS.indent(Indent) << "'name': \"" << llvm::yaml::escape(VName) << "\",\n";
+      OS.indent(Indent) << "'external-contents': \""
+                        << llvm::yaml::escape(Entry.RPath) << "\"\n";
       Indent -= 2;
       OS.indent(Indent) << '}';
       if (Entries.empty()) {
index 64128f158f2e8aa5db8e1a0364a62ede259dd32d..e6b32b001db69c7b712a55a41b52d465b8910fea 100644 (file)
@@ -84,6 +84,27 @@ TEST(libclang, VirtualFileOverlay) {
     TestVFO T(contents);
     T.map("/path/virtual/foo.h", "/real/foo.h");
   }
+  {
+    const char *contents =
+    "{\n"
+    "  'version': 0,\n"
+    "  'roots': [\n"
+    "    {\n"
+    "      'type': 'directory',\n"
+    "      'name': \"/path/virtual\",\n"
+    "      'contents': [\n"
+    "        {\n"
+    "          'type': 'file',\n"
+    "          'name': \"\\u2602.h\",\n"
+    "          'external-contents': \"/real/\\u2602.h\"\n"
+    "        }\n"
+    "      ]\n"
+    "    }\n"
+    "  ]\n"
+    "}\n";
+    TestVFO T(contents);
+    T.map("/path/virtual/☂.h", "/real/☂.h");
+  }
   {
     TestVFO T(NULL);
     T.mapError("/path/./virtual/../foo.h", "/real/foo.h",