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

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

Issue 311733002: Redo escaping in GN (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 6 years, 6 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/file_template.h" 5 #include "tools/gn/file_template.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iostream> 8 #include <iostream>
9 9
10 #include "tools/gn/escape.h" 10 #include "tools/gn/escape.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 if (t[subrange_i].type == Subrange::LITERAL) 159 if (t[subrange_i].type == Subrange::LITERAL)
160 cur_output.append(t[subrange_i].literal); 160 cur_output.append(t[subrange_i].literal);
161 else 161 else
162 cur_output.append(subst[t[subrange_i].type]); 162 cur_output.append(subst[t[subrange_i].type]);
163 } 163 }
164 } 164 }
165 } 165 }
166 166
167 void FileTemplate::WriteWithNinjaExpansions(std::ostream& out) const { 167 void FileTemplate::WriteWithNinjaExpansions(std::ostream& out) const {
168 EscapeOptions escape_options; 168 EscapeOptions escape_options;
169 escape_options.mode = ESCAPE_NINJA_SHELL; 169 escape_options.mode = ESCAPE_NINJA_COMMAND;
170 escape_options.inhibit_quoting = true; 170 escape_options.inhibit_quoting = true;
171 171
172 for (size_t template_i = 0; 172 for (size_t template_i = 0;
173 template_i < templates_.container().size(); template_i++) { 173 template_i < templates_.container().size(); template_i++) {
174 out << " "; // Separate args with spaces. 174 out << " "; // Separate args with spaces.
175 175
176 const Template& t = templates_[template_i]; 176 const Template& t = templates_[template_i];
177 177
178 // Escape each subrange into a string. Since we're writing out Ninja 178 // Escape each subrange into a string. Since we're writing out Ninja
179 // variables, we can't quote the whole thing, so we write in pieces, only 179 // variables, we can't quote the whole thing, so we write in pieces, only
180 // escaping the literals, and then quoting the whole thing at the end if 180 // escaping the literals, and then quoting the whole thing at the end if
181 // necessary. 181 // necessary.
182 bool needs_quoting = false; 182 bool needs_quoting = false;
183 std::string item_str; 183 std::string item_str;
184 for (size_t subrange_i = 0; subrange_i < t.container().size(); 184 for (size_t subrange_i = 0; subrange_i < t.container().size();
185 subrange_i++) { 185 subrange_i++) {
186 if (t[subrange_i].type == Subrange::LITERAL) { 186 if (t[subrange_i].type == Subrange::LITERAL) {
187 bool cur_needs_quoting = false;
187 item_str.append(EscapeString(t[subrange_i].literal, escape_options, 188 item_str.append(EscapeString(t[subrange_i].literal, escape_options,
188 &needs_quoting)); 189 &cur_needs_quoting));
190 needs_quoting |= cur_needs_quoting;
189 } else { 191 } else {
190 // Don't escape this since we need to preserve the $. 192 // Don't escape this since we need to preserve the $.
191 item_str.append("${"); 193 item_str.append("${");
192 item_str.append(GetNinjaVariableNameForType(t[subrange_i].type)); 194 item_str.append(GetNinjaVariableNameForType(t[subrange_i].type));
193 item_str.append("}"); 195 item_str.append("}");
194 } 196 }
195 } 197 }
196 198
197 if (needs_quoting || item_str.empty()) { 199 if (needs_quoting || item_str.empty()) {
198 // Need to shell quote the whole string. We also need to quote empty 200 // Need to shell quote the whole string. We also need to quote empty
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 cur = next + arraysize(kSourceFilePart) - 1; 308 cur = next + arraysize(kSourceFilePart) - 1;
307 } else { 309 } else {
308 // If it's not a match, treat it like a one-char literal (this will be 310 // If it's not a match, treat it like a one-char literal (this will be
309 // rare, so it's not worth the bother to add to the previous literal) so 311 // rare, so it's not worth the bother to add to the previous literal) so
310 // we can keep going. 312 // we can keep going.
311 t.container().push_back(Subrange(Subrange::LITERAL, "{")); 313 t.container().push_back(Subrange(Subrange::LITERAL, "{"));
312 cur = next + 1; 314 cur = next + 1;
313 } 315 }
314 } 316 }
315 } 317 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698