From: Rui Ueyama Date: Wed, 11 Sep 2013 04:00:35 +0000 (+0000) Subject: Do not quote YAML plain string myself. Let YAMLIO do that. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f365bb2896bf9ea7813cb608186d2d6017d658a3;p=clang Do not quote YAML plain string myself. Let YAMLIO do that. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190486 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Tooling/ReplacementsYaml.h b/include/clang/Tooling/ReplacementsYaml.h index 0bef5ed982..18d3259d70 100644 --- a/include/clang/Tooling/ReplacementsYaml.h +++ b/include/clang/Tooling/ReplacementsYaml.h @@ -29,10 +29,7 @@ namespace yaml { /// \brief ScalarTraits to read/write std::string objects. template <> struct ScalarTraits { static void output(const std::string &Val, void *, llvm::raw_ostream &Out) { - // We need to put quotes around the string to make sure special characters - // in the string is not treated as YAML tokens. - std::string NormalizedVal = std::string("\"") + Val + std::string("\""); - Out << NormalizedVal; + Out << Val; } static StringRef input(StringRef Scalar, void *, std::string &Val) { diff --git a/unittests/Tooling/ReplacementsYamlTest.cpp b/unittests/Tooling/ReplacementsYamlTest.cpp index 627002a74e..a20dde7614 100644 --- a/unittests/Tooling/ReplacementsYamlTest.cpp +++ b/unittests/Tooling/ReplacementsYamlTest.cpp @@ -36,34 +36,34 @@ TEST(ReplacementsYamlTest, serializesReplacements) { // NOTE: If this test starts to fail for no obvious reason, check whitespace. ASSERT_STREQ("---\n" - "MainSourceFile: \"/path/to/source.cpp\"\n" - "Context: \"some context\"\n" + "MainSourceFile: /path/to/source.cpp\n" + "Context: some context\n" "Replacements: \n" // Extra whitespace here! - " - FilePath: \"/path/to/file1.h\"\n" + " - FilePath: /path/to/file1.h\n" " Offset: 232\n" " Length: 56\n" - " ReplacementText: \"replacement #1\"\n" - " - FilePath: \"/path/to/file2.h\"\n" + " ReplacementText: 'replacement #1'\n" + " - FilePath: /path/to/file2.h\n" " Offset: 301\n" " Length: 2\n" - " ReplacementText: \"replacement #2\"\n" + " ReplacementText: 'replacement #2'\n" "...\n", YamlContentStream.str().c_str()); } TEST(ReplacementsYamlTest, deserializesReplacements) { std::string YamlContent = "---\n" - "MainSourceFile: \"/path/to/source.cpp\"\n" - "Context: \"some context\"\n" + "MainSourceFile: /path/to/source.cpp\n" + "Context: some context\n" "Replacements:\n" - " - FilePath: \"/path/to/file1.h\"\n" + " - FilePath: /path/to/file1.h\n" " Offset: 232\n" " Length: 56\n" - " ReplacementText: \"replacement #1\"\n" - " - FilePath: \"/path/to/file2.h\"\n" + " ReplacementText: 'replacement #1'\n" + " - FilePath: /path/to/file2.h\n" " Offset: 301\n" " Length: 2\n" - " ReplacementText: \"replacement #2\"\n" + " ReplacementText: 'replacement #2'\n" "...\n"; TranslationUnitReplacements DocActual; yaml::Input YAML(YamlContent); @@ -85,12 +85,12 @@ TEST(ReplacementsYamlTest, deserializesReplacements) { TEST(ReplacementsYamlTest, deserializesWithoutContext) { // Make sure a doc can be read without the context field. std::string YamlContent = "---\n" - "MainSourceFile: \"/path/to/source.cpp\"\n" + "MainSourceFile: /path/to/source.cpp\n" "Replacements:\n" - " - FilePath: \"target_file.h\"\n" + " - FilePath: target_file.h\n" " Offset: 1\n" " Length: 10\n" - " ReplacementText: \"replacement\"\n" + " ReplacementText: replacement\n" "...\n"; TranslationUnitReplacements DocActual; yaml::Input YAML(YamlContent);