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

Unified Diff: tools/gn/visual_studio_writer.cc

Issue 2803613003: "Escape" certain characters (Closed)
Patch Set: 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..f8021753247b7adcda50809e0f03fe682792cf38 100644
--- a/tools/gn/visual_studio_writer.cc
+++ b/tools/gn/visual_studio_writer.cc
@@ -37,9 +37,32 @@
namespace {
+std::string EscapeString(const std::string& value) {
+ std::string result;
+ if (value.find_first_of("<>&\"\t\r\n") != std::string::npos) {
brettw 2017/04/07 18:16:43 I'd delete this check and always do the loop below
kylix_rd 2017/04/07 19:18:53 Done.
+ for (std::string::const_iterator it = value.cbegin();
brettw 2017/04/07 18:16:43 I would have used a range-based for loop here whic
kylix_rd 2017/04/07 19:18:53 Yes, that's better. Done.
+ it != value.cend();
+ ++it) {
+ switch (*it) {
+ case '\n': result += "&#10;"; break;
brucedawson 2017/04/05 18:51:39 Do you have references for the \n, \r, and \t sequ
kylix_rd 2017/04/05 18:55:02 I based it off the code in libxml here: https://cs
+ case '\r': result += "&#13;"; break;
+ case '\t': result += "&#9;"; break;
+ case '"': result += "&quot;"; break;
+ case '<': result += "&lt;"; break;
+ case '>': result += "&gt;"; break;
+ case '&': result += "&amp;"; break;
+ default:
+ result += *it;
+ }
+ }
+ } else
brettw 2017/04/07 18:16:43 Google style says all arms in an if statement shou
+ result = value;
+ 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