When writing YAML in libclang, use yaml::escape instead of write_escaped

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().

llvm-svn: 206443
This commit is contained in:
Ben Langmuir 2014-04-17 03:31:02 +00:00
parent 4b55a9c841
commit a56071c5fb
2 changed files with 25 additions and 4 deletions

View 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()) {

View 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",