OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef TOOLS_GN_ESCAPE_H_ | |
6 #define TOOLS_GN_ESCAPE_H_ | |
7 | |
8 #include <iosfwd> | |
9 | |
10 #include "base/strings/string_piece.h" | |
11 | |
12 // TODO(brettw) we may need to make this a bitfield. If we want to write a | |
13 // shell command in a ninja file, we need the shell characters to be escaped, | |
14 // and THEN the ninja characters. Or maybe we require the caller to do two | |
15 // passes. | |
16 enum EscapingMode { | |
17 ESCAPE_NONE, // No escaping. | |
18 ESCAPE_NINJA, // Ninja string escaping. | |
19 ESCAPE_SHELL, // Shell string escaping. | |
20 }; | |
21 | |
22 struct EscapeOptions { | |
23 EscapeOptions() | |
24 : mode(ESCAPE_NONE), | |
25 convert_slashes(false), | |
26 inhibit_quoting(false) { | |
27 } | |
28 | |
29 EscapingMode mode; | |
30 | |
31 // When set, converts forward-slashes to system-specific path separators. | |
32 bool convert_slashes; | |
33 | |
34 // When the escaping mode is ESCAPE_SHELL, the escaper will normally put | |
35 // quotes around things with spaces. If this value is set to true, we'll | |
36 // disable the quoting feature and just add the spaces. | |
37 // | |
38 // This mode is for when quoting is done at some higher-level. Defaults to | |
39 // false. | |
40 bool inhibit_quoting; | |
41 }; | |
42 | |
43 // Escapes the given input, returnining the result. | |
44 std::string EscapeString(const base::StringPiece& str, | |
45 const EscapeOptions& options); | |
46 | |
47 // Same as EscapeString but writes the results to the given stream, saving a | |
48 // copy. | |
49 void EscapeStringToStream(std::ostream& out, | |
50 const base::StringPiece& str, | |
51 const EscapeOptions& options); | |
52 | |
53 #endif // TOOLS_GN_ESCAPE_H_ | |
OLD | NEW |