OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 file contains a class that can be used to extract the salient | 5 // This file contains a class that can be used to extract the salient |
6 // elements of a command line in a relatively lightweight manner. | 6 // elements of a command line in a relatively lightweight manner. |
7 // Switches can optionally have a value attached using an equals sign, | 7 // Switches can optionally have a value attached using an equals sign, |
8 // as in "-switch=value". Arguments that aren't prefixed with a | 8 // as in "-switch=value". Arguments that aren't prefixed with a |
9 // switch prefix are considered "loose parameters". Switch names | 9 // switch prefix are considered "loose parameters". Switch names |
10 // are case-insensitive. | 10 // are case-insensitive. An argument of "--" will terminate switch parsing, |
| 11 // causing everything after to be considered as loose parameters. |
11 | 12 |
12 #ifndef BASE_COMMAND_LINE_H__ | 13 #ifndef BASE_COMMAND_LINE_H_ |
13 #define BASE_COMMAND_LINE_H__ | 14 #define BASE_COMMAND_LINE_H_ |
14 | 15 |
15 #include <map> | 16 #include <map> |
16 #include <string> | 17 #include <string> |
17 #include <vector> | 18 #include <vector> |
18 | 19 |
19 #include "base/basictypes.h" | 20 #include "base/basictypes.h" |
20 #include "base/scoped_ptr.h" | 21 #include "base/scoped_ptr.h" |
21 | 22 |
22 class CommandLine { | 23 class CommandLine { |
23 public: | 24 public: |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // Returns the program part of the command line string (the first item). | 70 // Returns the program part of the command line string (the first item). |
70 std::wstring program() const; | 71 std::wstring program() const; |
71 | 72 |
72 // An array containing the prefixes that identify an argument as | 73 // An array containing the prefixes that identify an argument as |
73 // a switch. | 74 // a switch. |
74 static const wchar_t* const kSwitchPrefixes[]; | 75 static const wchar_t* const kSwitchPrefixes[]; |
75 | 76 |
76 // The string that's used to separate switches from their values. | 77 // The string that's used to separate switches from their values. |
77 static const wchar_t kSwitchValueSeparator[]; | 78 static const wchar_t kSwitchValueSeparator[]; |
78 | 79 |
| 80 // Treat everything after this argument as loose parameters. |
| 81 static const wchar_t kSwitchTerminator[]; |
| 82 |
79 // Appends the given switch string (preceded by a space and a switch | 83 // Appends the given switch string (preceded by a space and a switch |
80 // prefix) to the given string. | 84 // prefix) to the given string. |
81 static void AppendSwitch(std::wstring* command_line_string, | 85 static void AppendSwitch(std::wstring* command_line_string, |
82 const std::wstring& switch_string); | 86 const std::wstring& switch_string); |
83 | 87 |
84 // Appends the given switch string (preceded by a space and a switch | 88 // Appends the given switch string (preceded by a space and a switch |
85 // prefix) to the given string, with the given value attached. | 89 // prefix) to the given string, with the given value attached. |
86 static void AppendSwitchWithValue(std::wstring* command_line_string, | 90 static void AppendSwitchWithValue(std::wstring* command_line_string, |
87 const std::wstring& switch_string, | 91 const std::wstring& switch_string, |
88 const std::wstring& value_string); | 92 const std::wstring& value_string); |
89 | 93 |
90 private: | 94 private: |
91 class Data; | 95 class Data; |
92 | 96 |
93 // True if we are responsible for deleting our |data_| pointer. In some cases | 97 // True if we are responsible for deleting our |data_| pointer. In some cases |
94 // we cache the result of parsing the command line and |data_|'s lifetime is | 98 // we cache the result of parsing the command line and |data_|'s lifetime is |
95 // managed by someone else (e.g., the |Singleton| class). | 99 // managed by someone else (e.g., the |Singleton| class). |
96 bool we_own_data_; | 100 bool we_own_data_; |
97 | 101 |
98 // A pointer to the parsed version of the command line. | 102 // A pointer to the parsed version of the command line. |
99 Data* data_; | 103 Data* data_; |
100 | 104 |
101 DISALLOW_EVIL_CONSTRUCTORS(CommandLine); | 105 DISALLOW_EVIL_CONSTRUCTORS(CommandLine); |
102 }; | 106 }; |
103 | 107 |
104 #endif // BASE_COMMAND_LINE_H__ | 108 #endif // BASE_COMMAND_LINE_H_ |
105 | |
OLD | NEW |