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.
5 #ifndef TOOLS_GN_ESCAPE_H_
6 #define TOOLS_GN_ESCAPE_H_
10 #include "base/strings/string_piece.h"
16 // Ninja string escaping.
19 // Shell string escaping.
22 // For writing shell commands to ninja files.
23 ESCAPE_NINJA_SHELL
= ESCAPE_NINJA
| ESCAPE_SHELL
,
28 struct EscapeOptions
{
31 convert_slashes(false),
32 inhibit_quoting(false) {
37 // When set, converts forward-slashes to system-specific path separators.
40 // 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
42 // disable the quoting feature and just add the spaces.
44 // This mode is for when quoting is done at some higher-level. Defaults to
49 // Escapes the given input, returnining the result.
51 // 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
53 // 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).
55 std::string
EscapeString(const base::StringPiece
& str
,
56 const EscapeOptions
& options
,
57 bool* needed_quoting
);
59 // Same as EscapeString but writes the results to the given stream, saving a
61 void EscapeStringToStream(std::ostream
& out
,
62 const base::StringPiece
& str
,
63 const EscapeOptions
& options
);
65 #endif // TOOLS_GN_ESCAPE_H_