Chromium Code Reviews| Index: tools/gn/value.cc |
| diff --git a/tools/gn/value.cc b/tools/gn/value.cc |
| index 6dfe23417a4a4d6ee3183e613561bc7f434b1c18..687c0396db325e551edb43781efe9ae1ff5cf185 100644 |
| --- a/tools/gn/value.cc |
| +++ b/tools/gn/value.cc |
| @@ -124,15 +124,20 @@ std::string Value::ToString(bool quote_string) const { |
| return base::Int64ToString(int_value_); |
| case STRING: |
| 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 + "\""; |
| + std::string result = "\""; |
| + bool escaped = false; |
|
brettw
2015/03/31 23:01:51
The goal of tracking this should be documented, it
mdempsky
2015/03/31 23:14:47
Done, PTAL.
|
| + for (char ch : string_value_) { |
| + if (escaped && (ch == '$' || ch == '"' || ch == '\\')) |
| + result += '\\'; |
| + if (ch == '$' || ch == '"') |
| + result += '\\'; |
| + result += ch; |
| + escaped = (ch == '\\'); |
| + } |
| + if (escaped) |
| + result += '\\'; |
| + result += '"'; |
| + return result; |
| } |
| return string_value_; |
| case LIST: { |