Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: tools/gn/visual_studio_writer.cc

Issue 2803613003: "Escape" certain characters (Closed)
Patch Set: Address feeback. Run git cl format. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 += "&lt;";
+ break;
+ case '>':
+ result += "&gt;";
+ break;
+ case '&':
+ result += "&amp;";
+ break;
+ default:
+ result += c;
+ }
+ }
+ return result;
+}
+
struct SemicolonSeparatedWriter {
void operator()(const std::string& value, std::ostream& out) const {
- out << value + ';';
+ out << EscapeString(value) + ';';
}
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698