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 #ifndef TOOLS_GN_ESCAPE_H_ | 5 #ifndef TOOLS_GN_ESCAPE_H_ |
| 6 #define TOOLS_GN_ESCAPE_H_ | 6 #define TOOLS_GN_ESCAPE_H_ |
| 7 | 7 |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 | 9 |
| 10 #include "base/containers/stack_container.h" | |
|
scottmg
2014/06/04 21:21:27
seems unnecessary here
| |
| 10 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
| 11 | 12 |
| 12 enum EscapingMode { | 13 enum EscapingMode { |
| 13 // No escaping. | 14 // No escaping. |
| 14 ESCAPE_NONE, | 15 ESCAPE_NONE, |
| 15 | 16 |
| 16 // Ninja string escaping. | 17 // Ninja string escaping. |
| 17 ESCAPE_NINJA = 1, | 18 ESCAPE_NINJA, |
| 18 | 19 |
| 19 // Shell string escaping. | 20 // For writing commands to ninja files. |
| 20 ESCAPE_SHELL = 2, | 21 ESCAPE_NINJA_FORK, |
|
scottmg
2014/06/04 21:21:27
_FORK seems odd, maybe _COMMAND?
| |
| 22 }; | |
| 21 | 23 |
| 22 // For writing shell commands to ninja files. | 24 enum EscapingPlatform { |
| 23 ESCAPE_NINJA_SHELL = ESCAPE_NINJA | ESCAPE_SHELL, | 25 // Do escaping for the current platform. |
| 26 ESCAPE_PLATFORM_CURRENT, | |
| 24 | 27 |
| 25 ESCAPE_JSON = 4, | 28 // Force escaping for the given platform. |
| 29 ESCAPE_PLATFORM_POSIX, | |
| 30 ESCAPE_PLATFORM_WIN, | |
| 26 }; | 31 }; |
| 27 | 32 |
| 28 struct EscapeOptions { | 33 struct EscapeOptions { |
| 29 EscapeOptions() | 34 EscapeOptions() |
| 30 : mode(ESCAPE_NONE), | 35 : mode(ESCAPE_NONE), |
| 31 convert_slashes(false), | 36 platform(ESCAPE_PLATFORM_CURRENT), |
| 32 inhibit_quoting(false) { | 37 inhibit_quoting(false) { |
| 33 } | 38 } |
| 34 | 39 |
| 35 EscapingMode mode; | 40 EscapingMode mode; |
| 36 | 41 |
| 37 // When set, converts forward-slashes to system-specific path separators. | 42 // Controls how "fork" escaping is done. You will generally want to keep the |
| 38 bool convert_slashes; | 43 // default "current" platform. |
| 44 EscapingPlatform platform; | |
| 39 | 45 |
| 40 // When the escaping mode is ESCAPE_SHELL, the escaper will normally put | 46 // When the escaping mode is ESCAPE_SHELL, the escaper will normally put |
| 41 // quotes around things with spaces. If this value is set to true, we'll | 47 // quotes around things with spaces. If this value is set to true, we'll |
| 42 // disable the quoting feature and just add the spaces. | 48 // disable the quoting feature and just add the spaces. |
| 43 // | 49 // |
| 44 // This mode is for when quoting is done at some higher-level. Defaults to | 50 // This mode is for when quoting is done at some higher-level. Defaults to |
| 45 // false. | 51 // false. Note that Windows has strange behavior where the meaning of the |
| 52 // backslashes changes according to if it is followed by a quote. The | |
| 53 // escaping rules assume that a double-quote will be appended to the result. | |
| 46 bool inhibit_quoting; | 54 bool inhibit_quoting; |
| 47 }; | 55 }; |
| 48 | 56 |
| 49 // Escapes the given input, returnining the result. | 57 // Escapes the given input, returnining the result. |
| 50 // | 58 // |
| 51 // If needed_quoting is non-null, whether the string was or should have been | 59 // If needed_quoting is non-null, whether the string was or should have been |
| 52 // (if inhibit_quoting was set) quoted will be written to it. This value should | 60 // (if inhibit_quoting was set) quoted will be written to it. This value should |
| 53 // be initialized to false by the caller and will be written to only if it's | 61 // be initialized to false by the caller and will be written to only if it's |
| 54 // true (the common use-case is for chaining calls). | 62 // true (the common use-case is for chaining calls). |
| 55 std::string EscapeString(const base::StringPiece& str, | 63 std::string EscapeString(const base::StringPiece& str, |
| 56 const EscapeOptions& options, | 64 const EscapeOptions& options, |
| 57 bool* needed_quoting); | 65 bool* needed_quoting); |
| 58 | 66 |
| 59 // Same as EscapeString but writes the results to the given stream, saving a | 67 // Same as EscapeString but writes the results to the given stream, saving a |
| 60 // copy. | 68 // copy. |
| 61 void EscapeStringToStream(std::ostream& out, | 69 void EscapeStringToStream(std::ostream& out, |
| 62 const base::StringPiece& str, | 70 const base::StringPiece& str, |
| 63 const EscapeOptions& options); | 71 const EscapeOptions& options); |
| 64 | 72 |
| 65 #endif // TOOLS_GN_ESCAPE_H_ | 73 #endif // TOOLS_GN_ESCAPE_H_ |
| OLD | NEW |