summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-cov/CoverageExporterJson.cpp
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2016-07-27 04:08:32 +0000
committerVedant Kumar <vsk@apple.com>2016-07-27 04:08:32 +0000
commit90be9db7d96a109c7f9f52d311681e13d7247e0b (patch)
tree687fff4c26f248770cb32ca08539a727f08f2175 /llvm/tools/llvm-cov/CoverageExporterJson.cpp
parentae7e39a6e441cd6c129e0531d86a9834ca4bbe86 (diff)
downloadbcm5719-llvm-90be9db7d96a109c7f9f52d311681e13d7247e0b.tar.gz
bcm5719-llvm-90be9db7d96a109c7f9f52d311681e13d7247e0b.zip
[llvm-cov] Escape '\' in strings when emitting JSON
Test that Windows path separators are escaped properly. Add a round-trip test to verify the JSON produced by the exporter. llvm-svn: 276832
Diffstat (limited to 'llvm/tools/llvm-cov/CoverageExporterJson.cpp')
-rw-r--r--llvm/tools/llvm-cov/CoverageExporterJson.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/llvm/tools/llvm-cov/CoverageExporterJson.cpp b/llvm/tools/llvm-cov/CoverageExporterJson.cpp
index 4ce07b59f0f..7941f288597 100644
--- a/llvm/tools/llvm-cov/CoverageExporterJson.cpp
+++ b/llvm/tools/llvm-cov/CoverageExporterJson.cpp
@@ -86,7 +86,16 @@ class CoverageExporterJson {
void emitSerialized(const int64_t Value) { OS << Value; }
/// \brief Emit a serialized string.
- void emitSerialized(const std::string &Value) { OS << "\"" << Value << "\""; }
+ void emitSerialized(const std::string &Value) {
+ OS << "\"";
+ for (char C : Value) {
+ if (C != '\\')
+ OS << C;
+ else
+ OS << "\\\\";
+ }
+ OS << "\"";
+ }
/// \brief Emit a comma if there is a previous element to delimit.
void emitComma() {
@@ -109,7 +118,8 @@ class CoverageExporterJson {
/// \brief Emit a dictionary/object key but no value.
void emitDictKey(const std::string &Key) {
emitComma();
- OS << "\"" << Key << "\":";
+ emitSerialized(Key);
+ OS << ":";
State.pop();
assert((State.size() >= 1) && "Closed too many JSON elements");
OpenPOWER on IntegriCloud