Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/containers/stack_container.h" | |
| 10 #include "base/logging.h" | 9 #include "base/logging.h" |
| 11 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 12 | 11 |
| 13 namespace { | 12 namespace { |
| 14 | 13 |
| 15 // A "1" in this lookup table means that char is valid in the Posix shell. | 14 // A "1" in this lookup table means that char is valid in the Posix shell. |
| 16 const char kShellValid[0x80] = { | 15 const char kShellValid[0x80] = { |
| 17 // 00-1f: all are invalid | 16 // 00-1f: all are invalid |
| 18 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 17 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 19 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 18 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 bool* needed_quoting) { | 194 bool* needed_quoting) { |
| 196 std::string result; | 195 std::string result; |
| 197 result.reserve(str.size() + 4); // Guess we'll add a couple of extra chars. | 196 result.reserve(str.size() + 4); // Guess we'll add a couple of extra chars. |
| 198 EscapeStringToString(str, options, &result, needed_quoting); | 197 EscapeStringToString(str, options, &result, needed_quoting); |
| 199 return result; | 198 return result; |
| 200 } | 199 } |
| 201 | 200 |
| 202 void EscapeStringToStream(std::ostream& out, | 201 void EscapeStringToStream(std::ostream& out, |
| 203 const base::StringPiece& str, | 202 const base::StringPiece& str, |
| 204 const EscapeOptions& options) { | 203 const EscapeOptions& options) { |
| 205 base::StackString<256> escaped; | 204 std::string escaped; |
| 206 EscapeStringToString(str, options, &escaped.container(), nullptr); | 205 EscapeStringToString(str, options, &escaped, nullptr); |
|
sunnyps
2017/04/14 17:27:54
EscapeStringToString and other methods don't need
| |
| 207 if (!escaped->empty()) | 206 if (!escaped.empty()) |
| 208 out.write(escaped->data(), escaped->size()); | 207 out.write(escaped.data(), escaped.size()); |
| 209 } | 208 } |
| OLD | NEW |