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

Unified Diff: tools/gn/value.cc

Issue 265693003: Redo GN "args" command (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
« tools/gn/command_args.cc ('K') | « tools/gn/value.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/value.cc
diff --git a/tools/gn/value.cc b/tools/gn/value.cc
index 1fb7155dc1b609d410f884d5f3163b7b016ca760..3632ddf4a80c5b1cfaab255c00b2467ca92d2cd5 100644
--- a/tools/gn/value.cc
+++ b/tools/gn/value.cc
@@ -5,6 +5,7 @@
#include "tools/gn/value.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_util.h"
#include "tools/gn/scope.h"
Value::Value()
@@ -130,8 +131,17 @@ std::string Value::ToString(bool quote_string) const {
case INTEGER:
return base::Int64ToString(int_value_);
case STRING:
- if (quote_string)
- return "\"" + string_value_ + "\"";
+ if (quote_string) {
+ std::string escaped = string_value_;
+ // First escape all special uses of a backslash.
+ ReplaceSubstringsAfterOffset(&escaped, 0, "\\$", "\\\\$");
+ ReplaceSubstringsAfterOffset(&escaped, 0, "\\\"", "\\\\\"");
+
+ // Now escape special chars.
+ ReplaceSubstringsAfterOffset(&escaped, 0, "$", "\\$");
+ ReplaceSubstringsAfterOffset(&escaped, 0, "\"", "\\\"");
+ return "\"" + escaped + "\"";
+ }
return string_value_;
case LIST: {
std::string result = "[";
« tools/gn/command_args.cc ('K') | « tools/gn/value.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698