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_PATH_OUTPUT_H_ | 5 #ifndef TOOLS_GN_PATH_OUTPUT_H_ |
6 #define TOOLS_GN_PATH_OUTPUT_H_ | 6 #define TOOLS_GN_PATH_OUTPUT_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 public: | 26 public: |
27 // Controls whether writing directory names include the trailing slash. | 27 // Controls whether writing directory names include the trailing slash. |
28 // Often we don't want the trailing slash when writing out to a command line, | 28 // Often we don't want the trailing slash when writing out to a command line, |
29 // especially on Windows where it's a backslash and might be interpreted as | 29 // especially on Windows where it's a backslash and might be interpreted as |
30 // escaping the thing following it. | 30 // escaping the thing following it. |
31 enum DirSlashEnding { | 31 enum DirSlashEnding { |
32 DIR_INCLUDE_LAST_SLASH, | 32 DIR_INCLUDE_LAST_SLASH, |
33 DIR_NO_LAST_SLASH, | 33 DIR_NO_LAST_SLASH, |
34 }; | 34 }; |
35 | 35 |
36 PathOutput(const SourceDir& current_dir, | 36 PathOutput(const SourceDir& current_dir, EscapingMode escaping); |
37 EscapingMode escaping, | |
38 bool convert_slashes); | |
39 ~PathOutput(); | 37 ~PathOutput(); |
40 | 38 |
41 // Read-only since inverse_current_dir_ is computed depending on this. | 39 // Read-only since inverse_current_dir_ is computed depending on this. |
42 EscapingMode escaping_mode() const { return options_.mode; } | 40 EscapingMode escaping_mode() const { return options_.mode; } |
43 | 41 |
44 const SourceDir& current_dir() const { return current_dir_; } | 42 const SourceDir& current_dir() const { return current_dir_; } |
45 | 43 |
46 // When true, converts slashes to the system-type path separators (on | 44 // Getter/setters for flags inside the escape options. |
47 // Windows, this is a backslash, this is a NOP otherwise). | |
48 // | |
49 // Read-only since inverse_current_dir_ is computed depending on this. | |
50 bool convert_slashes_to_system() const { return options_.convert_slashes; } | |
51 | |
52 // When the output escaping is ESCAPE_SHELL, the escaper will normally put | |
53 // quotes around suspect things. If this value is set to true, we'll disable | |
54 // the quoting feature. This means that in ESCAPE_SHELL mode, strings with | |
55 // spaces in them qon't be quoted. This mode is for when quoting is done at | |
56 // some higher-level. Defaults to false. | |
57 bool inhibit_quoting() const { return options_.inhibit_quoting; } | 45 bool inhibit_quoting() const { return options_.inhibit_quoting; } |
58 void set_inhibit_quoting(bool iq) { options_.inhibit_quoting = iq; } | 46 void set_inhibit_quoting(bool iq) { options_.inhibit_quoting = iq; } |
| 47 void set_escape_platform(EscapingPlatform p) { options_.platform = p; } |
59 | 48 |
60 void WriteFile(std::ostream& out, const SourceFile& file) const; | 49 void WriteFile(std::ostream& out, const SourceFile& file) const; |
61 void WriteFile(std::ostream& out, const OutputFile& file) const; | 50 void WriteFile(std::ostream& out, const OutputFile& file) const; |
62 void WriteFile(std::ostream& out, const base::FilePath& file) const; | 51 void WriteFile(std::ostream& out, const base::FilePath& file) const; |
63 void WriteDir(std::ostream& out, | 52 void WriteDir(std::ostream& out, |
64 const SourceDir& dir, | 53 const SourceDir& dir, |
65 DirSlashEnding slash_ending) const; | 54 DirSlashEnding slash_ending) const; |
66 | 55 |
67 // Backend for WriteFile and WriteDir. This appends the given file or | 56 // Backend for WriteFile and WriteDir. This appends the given file or |
68 // directory string to the file. | 57 // directory string to the file. |
69 void WritePathStr(std::ostream& out, const base::StringPiece& str) const; | 58 void WritePathStr(std::ostream& out, const base::StringPiece& str) const; |
70 | 59 |
71 private: | 60 private: |
72 // Takes the given string and writes it out, appending to the inverse | 61 // Takes the given string and writes it out, appending to the inverse |
73 // current dir. This assumes leading slashes have been trimmed. | 62 // current dir. This assumes leading slashes have been trimmed. |
74 void WriteSourceRelativeString(std::ostream& out, | 63 void WriteSourceRelativeString(std::ostream& out, |
75 const base::StringPiece& str) const; | 64 const base::StringPiece& str) const; |
76 | 65 |
77 SourceDir current_dir_; | 66 SourceDir current_dir_; |
78 | 67 |
79 // Uses system slashes if convert_slashes_to_system_. | 68 // Uses system slashes if convert_slashes_to_system_. |
80 std::string inverse_current_dir_; | 69 std::string inverse_current_dir_; |
81 | 70 |
82 // Since the inverse_current_dir_ depends on some of these, we don't expose | 71 // Since the inverse_current_dir_ depends on some of these, we don't expose |
83 // this directly to modification. | 72 // this directly to modification. |
84 EscapeOptions options_; | 73 EscapeOptions options_; |
85 }; | 74 }; |
86 | 75 |
87 #endif // TOOLS_GN_PATH_OUTPUT_H_ | 76 #endif // TOOLS_GN_PATH_OUTPUT_H_ |
OLD | NEW |