Index: tools/gn/visual_studio_writer.cc |
diff --git a/tools/gn/visual_studio_writer.cc b/tools/gn/visual_studio_writer.cc |
index 8a8cf528fc15c5ae99b1081a62b187f3c03d5ae7..76ebc5620fa39db6be2c720e848b8afd5dde3625 100644 |
--- a/tools/gn/visual_studio_writer.cc |
+++ b/tools/gn/visual_studio_writer.cc |
@@ -37,9 +37,41 @@ |
namespace { |
+std::string EscapeString(const std::string& value) { |
+ std::string result; |
+ for (char c : value) { |
+ switch (c) { |
+ case '\n': |
+ result += " "; |
+ break; |
+ case '\r': |
+ result += " "; |
+ break; |
+ case '\t': |
+ result += "	"; |
+ break; |
+ case '"': |
+ result += """; |
+ break; |
+ case '<': |
+ result += "<"; |
+ break; |
+ case '>': |
+ result += ">"; |
+ break; |
+ case '&': |
+ result += "&"; |
+ break; |
+ default: |
+ result += c; |
+ } |
+ } |
+ return result; |
+} |
+ |
struct SemicolonSeparatedWriter { |
void operator()(const std::string& value, std::ostream& out) const { |
- out << value + ';'; |
+ out << EscapeString(value) + ';'; |
} |
}; |