OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This class works with command lines: building and parsing. | 5 // This class works with command lines: building and parsing. |
6 // Arguments with prefixes ('--', '-', and on Windows, '/') are switches. | 6 // Arguments with prefixes ('--', '-', and on Windows, '/') are switches. |
7 // Switches will precede all other arguments without switch prefixes. | 7 // Switches will precede all other arguments without switch prefixes. |
8 // Switches can optionally have values, delimited by '=', e.g., "-switch=value". | 8 // Switches can optionally have values, delimited by '=', e.g., "-switch=value". |
9 // An argument of "--" will terminate switch parsing during initialization, | 9 // An argument of "--" will terminate switch parsing during initialization, |
10 // interpreting subsequent tokens as non-switch arguments, regardless of prefix. | 10 // interpreting subsequent tokens as non-switch arguments, regardless of prefix. |
11 | 11 |
12 // There is a singleton read-only CommandLine that represents the command line | 12 // There is a singleton read-only CommandLine that represents the command line |
13 // that the current process was started with. It must be initialized in main(). | 13 // that the current process was started with. It must be initialized in main(). |
14 | 14 |
15 #ifndef BASE_COMMAND_LINE_H_ | 15 #ifndef BASE_COMMAND_LINE_H_ |
16 #define BASE_COMMAND_LINE_H_ | 16 #define BASE_COMMAND_LINE_H_ |
17 | 17 |
18 #include <stddef.h> | 18 #include <stddef.h> |
19 #include <map> | 19 #include <map> |
20 #include <string> | 20 #include <string> |
21 #include <vector> | 21 #include <vector> |
22 | 22 |
23 #include "base/base_export.h" | 23 #include "base/base_export.h" |
24 #include "base/strings/string16.h" | 24 #include "base/strings/string16.h" |
| 25 #include "base/strings/string_piece.h" |
25 #include "build/build_config.h" | 26 #include "build/build_config.h" |
26 | 27 |
27 namespace base { | 28 namespace base { |
28 | 29 |
29 class FilePath; | 30 class FilePath; |
30 | 31 |
31 class BASE_EXPORT CommandLine { | 32 class BASE_EXPORT CommandLine { |
32 public: | 33 public: |
33 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
34 // The native command line string type. | 35 // The native command line string type. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 137 |
137 // Returns the original command line string as a vector of strings. | 138 // Returns the original command line string as a vector of strings. |
138 const StringVector& argv() const { return argv_; } | 139 const StringVector& argv() const { return argv_; } |
139 | 140 |
140 // Get and Set the program part of the command line string (the first item). | 141 // Get and Set the program part of the command line string (the first item). |
141 FilePath GetProgram() const; | 142 FilePath GetProgram() const; |
142 void SetProgram(const FilePath& program); | 143 void SetProgram(const FilePath& program); |
143 | 144 |
144 // Returns true if this command line contains the given switch. | 145 // Returns true if this command line contains the given switch. |
145 // (Switch names are case-insensitive). | 146 // (Switch names are case-insensitive). |
146 bool HasSwitch(const std::string& switch_string) const; | 147 // The second override provides an optimized version to avoid inlining the |
| 148 // codegen for the string allocation. |
| 149 bool HasSwitch(const base::StringPiece& switch_string) const; |
147 | 150 |
148 // Returns the value associated with the given switch. If the switch has no | 151 // Returns the value associated with the given switch. If the switch has no |
149 // value or isn't present, this method returns the empty string. | 152 // value or isn't present, this method returns the empty string. |
150 std::string GetSwitchValueASCII(const std::string& switch_string) const; | 153 std::string GetSwitchValueASCII(const std::string& switch_string) const; |
151 FilePath GetSwitchValuePath(const std::string& switch_string) const; | 154 FilePath GetSwitchValuePath(const std::string& switch_string) const; |
152 StringType GetSwitchValueNative(const std::string& switch_string) const; | 155 StringType GetSwitchValueNative(const std::string& switch_string) const; |
153 | 156 |
154 // Get a copy of all switches, along with their values. | 157 // Get a copy of all switches, along with their values. |
155 const SwitchMap& GetSwitches() const { return switches_; } | 158 const SwitchMap& GetSwitches() const { return switches_; } |
156 | 159 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 // Parsed-out switch keys and values. | 223 // Parsed-out switch keys and values. |
221 SwitchMap switches_; | 224 SwitchMap switches_; |
222 | 225 |
223 // The index after the program and switches, any arguments start here. | 226 // The index after the program and switches, any arguments start here. |
224 size_t begin_args_; | 227 size_t begin_args_; |
225 }; | 228 }; |
226 | 229 |
227 } // namespace base | 230 } // namespace base |
228 | 231 |
229 #endif // BASE_COMMAND_LINE_H_ | 232 #endif // BASE_COMMAND_LINE_H_ |
OLD | NEW |