| OLD | NEW |
| 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/escape.h" | 5 #include "tools/gn/escape.h" |
| 6 | 6 |
| 7 #include "base/containers/stack_container.h" | 7 #include "base/containers/stack_container.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 dest->push_back(ch); | 39 dest->push_back(ch); |
| 40 } | 40 } |
| 41 | 41 |
| 42 template<typename DestString> | 42 template<typename DestString> |
| 43 void EscapeStringToString_Ninja(const base::StringPiece& str, | 43 void EscapeStringToString_Ninja(const base::StringPiece& str, |
| 44 const EscapeOptions& options, | 44 const EscapeOptions& options, |
| 45 DestString* dest, | 45 DestString* dest, |
| 46 bool* needed_quoting) { | 46 bool* needed_quoting) { |
| 47 for (size_t i = 0; i < str.size(); i++) | 47 for (size_t i = 0; i < str.size(); i++) |
| 48 NinjaEscapeChar(str[i], dest); | 48 NinjaEscapeChar(str[i], dest); |
| 49 if (needed_quoting) | |
| 50 *needed_quoting = false; | |
| 51 } | 49 } |
| 52 | 50 |
| 53 // Escape for CommandLineToArgvW and additionally escape Ninja characters. | 51 // Escape for CommandLineToArgvW and additionally escape Ninja characters. |
| 54 // | 52 // |
| 55 // The basic algorithm is if the string doesn't contain any parse-affecting | 53 // The basic algorithm is if the string doesn't contain any parse-affecting |
| 56 // characters, don't do anything (other than the Ninja processing). If it does, | 54 // characters, don't do anything (other than the Ninja processing). If it does, |
| 57 // quote the string, and backslash-escape all quotes and backslashes. | 55 // quote the string, and backslash-escape all quotes and backslashes. |
| 58 // See: | 56 // See: |
| 59 // http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/eve
ryone-quotes-arguments-the-wrong-way.aspx | 57 // http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/eve
ryone-quotes-arguments-the-wrong-way.aspx |
| 60 // http://blogs.msdn.com/b/oldnewthing/archive/2010/09/17/10063629.aspx | 58 // http://blogs.msdn.com/b/oldnewthing/archive/2010/09/17/10063629.aspx |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 } | 183 } |
| 186 | 184 |
| 187 void EscapeStringToStream(std::ostream& out, | 185 void EscapeStringToStream(std::ostream& out, |
| 188 const base::StringPiece& str, | 186 const base::StringPiece& str, |
| 189 const EscapeOptions& options) { | 187 const EscapeOptions& options) { |
| 190 base::StackString<256> escaped; | 188 base::StackString<256> escaped; |
| 191 EscapeStringToString(str, options, &escaped.container(), NULL); | 189 EscapeStringToString(str, options, &escaped.container(), NULL); |
| 192 if (!escaped->empty()) | 190 if (!escaped->empty()) |
| 193 out.write(escaped->data(), escaped->size()); | 191 out.write(escaped->data(), escaped->size()); |
| 194 } | 192 } |
| OLD | NEW |