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

Side by Side Diff: tools/gn/value.cc

Issue 265693003: Redo GN "args" command (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: windows Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "tools/gn/value.h" 5 #include "tools/gn/value.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_util.h"
8 #include "tools/gn/scope.h" 9 #include "tools/gn/scope.h"
9 10
10 Value::Value() 11 Value::Value()
11 : type_(NONE), 12 : type_(NONE),
12 boolean_value_(false), 13 boolean_value_(false),
13 int_value_(0), 14 int_value_(0),
14 origin_(NULL) { 15 origin_(NULL) {
15 } 16 }
16 17
17 Value::Value(const ParseNode* origin, Type t) 18 Value::Value(const ParseNode* origin, Type t)
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 124
124 std::string Value::ToString(bool quote_string) const { 125 std::string Value::ToString(bool quote_string) const {
125 switch (type_) { 126 switch (type_) {
126 case NONE: 127 case NONE:
127 return "<void>"; 128 return "<void>";
128 case BOOLEAN: 129 case BOOLEAN:
129 return boolean_value_ ? "true" : "false"; 130 return boolean_value_ ? "true" : "false";
130 case INTEGER: 131 case INTEGER:
131 return base::Int64ToString(int_value_); 132 return base::Int64ToString(int_value_);
132 case STRING: 133 case STRING:
133 if (quote_string) 134 if (quote_string) {
134 return "\"" + string_value_ + "\""; 135 std::string escaped = string_value_;
136 // First escape all special uses of a backslash.
137 ReplaceSubstringsAfterOffset(&escaped, 0, "\\$", "\\\\$");
138 ReplaceSubstringsAfterOffset(&escaped, 0, "\\\"", "\\\\\"");
139
140 // Now escape special chars.
141 ReplaceSubstringsAfterOffset(&escaped, 0, "$", "\\$");
142 ReplaceSubstringsAfterOffset(&escaped, 0, "\"", "\\\"");
143 return "\"" + escaped + "\"";
144 }
135 return string_value_; 145 return string_value_;
136 case LIST: { 146 case LIST: {
137 std::string result = "["; 147 std::string result = "[";
138 for (size_t i = 0; i < list_value_.size(); i++) { 148 for (size_t i = 0; i < list_value_.size(); i++) {
139 if (i > 0) 149 if (i > 0)
140 result += ", "; 150 result += ", ";
141 result += list_value_[i].ToString(true); 151 result += list_value_[i].ToString(true);
142 } 152 }
143 result.push_back(']'); 153 result.push_back(']');
144 return result; 154 return result;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // iteration code. 192 // iteration code.
183 return false; 193 return false;
184 default: 194 default:
185 return false; 195 return false;
186 } 196 }
187 } 197 }
188 198
189 bool Value::operator!=(const Value& other) const { 199 bool Value::operator!=(const Value& other) const {
190 return !operator==(other); 200 return !operator==(other);
191 } 201 }
OLDNEW
« tools/gn/args.cc ('K') | « tools/gn/value.h ('k') | tools/gn/value_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698