[email protected] | 72e2e242 | 2012-02-27 18:38:12 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 4 | |
[email protected] | f3adb5c | 2008-08-07 20:07:32 | [diff] [blame] | 5 | #include "base/command_line.h" |
| 6 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | 2edc286 | 2011-04-04 18:04:37 | [diff] [blame] | 8 | #include <ostream> |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 9 | |
jdoerrie | 5c4dc4e | 2019-02-01 18:02:33 | [diff] [blame] | 10 | #include "base/containers/span.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 11 | #include "base/files/file_path.h" |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 12 | #include "base/logging.h" |
Jeremy Roman | 863386d | 2017-10-31 19:25:38 | [diff] [blame] | 13 | #include "base/stl_util.h" |
[email protected] | 5ae0b763e | 2013-02-07 23:01:39 | [diff] [blame] | 14 | #include "base/strings/string_split.h" |
skyostil | d851aa1 | 2017-03-29 17:38:35 | [diff] [blame] | 15 | #include "base/strings/string_tokenizer.h" |
[email protected] | 251cd6e5 | 2013-06-11 13:36:37 | [diff] [blame] | 16 | #include "base/strings/string_util.h" |
[email protected] | a4ea1f1 | 2013-06-07 18:37:07 | [diff] [blame] | 17 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 74e9fa2 | 2010-12-29 21:06:43 | [diff] [blame] | 18 | #include "build/build_config.h" |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 19 | |
[email protected] | 74e9fa2 | 2010-12-29 21:06:43 | [diff] [blame] | 20 | #if defined(OS_WIN) |
| 21 | #include <windows.h> |
| 22 | #include <shellapi.h> |
Jan Wilken Dörrie | b630aca | 2019-12-04 10:59:11 | [diff] [blame^] | 23 | |
| 24 | #include "base/strings/string_util_win.h" |
[email protected] | 7f113f3 | 2009-09-10 18:02:17 | [diff] [blame] | 25 | #endif |
| 26 | |
[email protected] | 2f3b1cc | 2014-03-17 23:07:15 | [diff] [blame] | 27 | namespace base { |
[email protected] | 04af979a | 2013-02-16 04:12:26 | [diff] [blame] | 28 | |
Ivan Kotenkov | a16212a5 | 2017-11-08 12:37:33 | [diff] [blame] | 29 | CommandLine* CommandLine::current_process_commandline_ = nullptr; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 30 | |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 31 | namespace { |
[email protected] | 2f3b1cc | 2014-03-17 23:07:15 | [diff] [blame] | 32 | |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 33 | constexpr CommandLine::CharType kSwitchTerminator[] = FILE_PATH_LITERAL("--"); |
| 34 | constexpr CommandLine::CharType kSwitchValueSeparator[] = |
| 35 | FILE_PATH_LITERAL("="); |
[email protected] | bf98a0e1 | 2013-09-25 23:36:00 | [diff] [blame] | 36 | |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 37 | // Since we use a lazy match, make sure that longer versions (like "--") are |
| 38 | // listed before shorter versions (like "-") of similar prefixes. |
[email protected] | 5d42633 | 2008-08-08 20:46:21 | [diff] [blame] | 39 | #if defined(OS_WIN) |
[email protected] | bf98a0e1 | 2013-09-25 23:36:00 | [diff] [blame] | 40 | // By putting slash last, we can control whether it is treaded as a switch |
| 41 | // value by changing the value of switch_prefix_count to be one less than |
| 42 | // the array size. |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 43 | constexpr CommandLine::StringPieceType kSwitchPrefixes[] = {L"--", L"-", L"/"}; |
Fabrice de Gans-Riberi | 306871de | 2018-05-16 19:38:39 | [diff] [blame] | 44 | #elif defined(OS_POSIX) || defined(OS_FUCHSIA) |
[email protected] | 1a48f31 | 2008-08-12 01:14:37 | [diff] [blame] | 45 | // Unixes don't use slash as a switch. |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 46 | constexpr CommandLine::StringPieceType kSwitchPrefixes[] = {"--", "-"}; |
[email protected] | 5d42633 | 2008-08-08 20:46:21 | [diff] [blame] | 47 | #endif |
deepak1556 | bb31c18 | 2019-10-29 23:15:58 | [diff] [blame] | 48 | size_t switch_prefix_count = base::size(kSwitchPrefixes); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 49 | |
Pavol Marko | bf16b81 | 2019-06-14 00:53:12 | [diff] [blame] | 50 | size_t GetSwitchPrefixLength(CommandLine::StringPieceType string) { |
[email protected] | bf98a0e1 | 2013-09-25 23:36:00 | [diff] [blame] | 51 | for (size_t i = 0; i < switch_prefix_count; ++i) { |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 52 | CommandLine::StringType prefix(kSwitchPrefixes[i]); |
Pavol Marko | bf16b81 | 2019-06-14 00:53:12 | [diff] [blame] | 53 | if (string.substr(0, prefix.length()) == prefix) |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 54 | return prefix.length(); |
| 55 | } |
| 56 | return 0; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 57 | } |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 58 | |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 59 | // Fills in |switch_string| and |switch_value| if |string| is a switch. |
| 60 | // This will preserve the input switch prefix in the output |switch_string|. |
| 61 | bool IsSwitch(const CommandLine::StringType& string, |
| 62 | CommandLine::StringType* switch_string, |
| 63 | CommandLine::StringType* switch_value) { |
| 64 | switch_string->clear(); |
| 65 | switch_value->clear(); |
[email protected] | 21e342f | 2012-10-19 06:19:59 | [diff] [blame] | 66 | size_t prefix_length = GetSwitchPrefixLength(string); |
| 67 | if (prefix_length == 0 || prefix_length == string.length()) |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 68 | return false; |
| 69 | |
| 70 | const size_t equals_position = string.find(kSwitchValueSeparator); |
| 71 | *switch_string = string.substr(0, equals_position); |
| 72 | if (equals_position != CommandLine::StringType::npos) |
| 73 | *switch_value = string.substr(equals_position + 1); |
| 74 | return true; |
| 75 | } |
| 76 | |
Pavol Marko | bf16b81 | 2019-06-14 00:53:12 | [diff] [blame] | 77 | // Returns true iff |string| represents a switch with key |
| 78 | // |switch_key_without_prefix|, regardless of value. |
| 79 | bool IsSwitchWithKey(CommandLine::StringPieceType string, |
| 80 | CommandLine::StringPieceType switch_key_without_prefix) { |
| 81 | size_t prefix_length = GetSwitchPrefixLength(string); |
| 82 | if (prefix_length == 0 || prefix_length == string.length()) |
| 83 | return false; |
| 84 | |
| 85 | const size_t equals_position = string.find(kSwitchValueSeparator); |
| 86 | return string.substr(prefix_length, equals_position - prefix_length) == |
| 87 | switch_key_without_prefix; |
| 88 | } |
| 89 | |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 90 | // Append switches and arguments, keeping switches before arguments. |
thestig | 8badc79 | 2014-12-04 22:14:22 | [diff] [blame] | 91 | void AppendSwitchesAndArguments(CommandLine* command_line, |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 92 | const CommandLine::StringVector& argv) { |
| 93 | bool parse_switches = true; |
| 94 | for (size_t i = 1; i < argv.size(); ++i) { |
| 95 | CommandLine::StringType arg = argv[i]; |
tfarina | 023b1dcc | 2015-12-06 13:25:41 | [diff] [blame] | 96 | #if defined(OS_WIN) |
Jan Wilken Dörrie | b630aca | 2019-12-04 10:59:11 | [diff] [blame^] | 97 | arg = CommandLine::StringType(TrimWhitespace(arg, TRIM_ALL)); |
Fabrice de Gans-Riberi | 306871de | 2018-05-16 19:38:39 | [diff] [blame] | 98 | #elif defined(OS_POSIX) || defined(OS_FUCHSIA) |
tfarina | 023b1dcc | 2015-12-06 13:25:41 | [diff] [blame] | 99 | TrimWhitespaceASCII(arg, TRIM_ALL, &arg); |
| 100 | #endif |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 101 | |
| 102 | CommandLine::StringType switch_string; |
| 103 | CommandLine::StringType switch_value; |
| 104 | parse_switches &= (arg != kSwitchTerminator); |
| 105 | if (parse_switches && IsSwitch(arg, &switch_string, &switch_value)) { |
| 106 | #if defined(OS_WIN) |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 107 | command_line->AppendSwitchNative(WideToUTF8(switch_string), switch_value); |
Fabrice de Gans-Riberi | 306871de | 2018-05-16 19:38:39 | [diff] [blame] | 108 | #elif defined(OS_POSIX) || defined(OS_FUCHSIA) |
thestig | 8badc79 | 2014-12-04 22:14:22 | [diff] [blame] | 109 | command_line->AppendSwitchNative(switch_string, switch_value); |
Fabrice de Gans-Riberi | 306871de | 2018-05-16 19:38:39 | [diff] [blame] | 110 | #else |
| 111 | #error Unsupported platform |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 112 | #endif |
| 113 | } else { |
thestig | 8badc79 | 2014-12-04 22:14:22 | [diff] [blame] | 114 | command_line->AppendArgNative(arg); |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 119 | #if defined(OS_WIN) |
| 120 | // Quote a string as necessary for CommandLineToArgvW compatiblity *on Windows*. |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 121 | std::wstring QuoteForCommandLineToArgvW(const std::wstring& arg, |
| 122 | bool quote_placeholders) { |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 123 | // We follow the quoting rules of CommandLineToArgvW. |
| 124 | // http://msdn.microsoft.com/en-us/library/17w5ykft.aspx |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 125 | std::wstring quotable_chars(L" \\\""); |
mgiuca | c974d510 | 2014-10-01 09:24:51 | [diff] [blame] | 126 | // We may also be required to quote '%', which is commonly used in a command |
| 127 | // line as a placeholder. (It may be substituted for a string with spaces.) |
| 128 | if (quote_placeholders) |
jdoerrie | 5c4dc4e | 2019-02-01 18:02:33 | [diff] [blame] | 129 | quotable_chars.push_back('%'); |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 130 | if (arg.find_first_of(quotable_chars) == std::wstring::npos) { |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 131 | // No quoting necessary. |
| 132 | return arg; |
| 133 | } |
| 134 | |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 135 | std::wstring out; |
jdoerrie | 5c4dc4e | 2019-02-01 18:02:33 | [diff] [blame] | 136 | out.push_back('"'); |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 137 | for (size_t i = 0; i < arg.size(); ++i) { |
| 138 | if (arg[i] == '\\') { |
| 139 | // Find the extent of this run of backslashes. |
| 140 | size_t start = i, end = start + 1; |
thestig | 8badc79 | 2014-12-04 22:14:22 | [diff] [blame] | 141 | for (; end < arg.size() && arg[end] == '\\'; ++end) {} |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 142 | size_t backslash_count = end - start; |
| 143 | |
| 144 | // Backslashes are escapes only if the run is followed by a double quote. |
| 145 | // Since we also will end the string with a double quote, we escape for |
| 146 | // either a double quote or the end of the string. |
| 147 | if (end == arg.size() || arg[end] == '"') { |
| 148 | // To quote, we need to output 2x as many backslashes. |
| 149 | backslash_count *= 2; |
| 150 | } |
| 151 | for (size_t j = 0; j < backslash_count; ++j) |
| 152 | out.push_back('\\'); |
| 153 | |
| 154 | // Advance i to one before the end to balance i++ in loop. |
| 155 | i = end - 1; |
| 156 | } else if (arg[i] == '"') { |
| 157 | out.push_back('\\'); |
| 158 | out.push_back('"'); |
| 159 | } else { |
| 160 | out.push_back(arg[i]); |
| 161 | } |
| 162 | } |
| 163 | out.push_back('"'); |
| 164 | |
| 165 | return out; |
| 166 | } |
[email protected] | bb97536 | 2009-01-21 01:00:22 | [diff] [blame] | 167 | #endif |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 168 | |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 169 | } // namespace |
| 170 | |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 171 | CommandLine::CommandLine(NoProgram no_program) |
| 172 | : argv_(1), |
| 173 | begin_args_(1) { |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 174 | } |
| 175 | |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 176 | CommandLine::CommandLine(const FilePath& program) |
| 177 | : argv_(1), |
| 178 | begin_args_(1) { |
| 179 | SetProgram(program); |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 180 | } |
| 181 | |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 182 | CommandLine::CommandLine(int argc, const CommandLine::CharType* const* argv) |
| 183 | : argv_(1), |
| 184 | begin_args_(1) { |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 185 | InitFromArgv(argc, argv); |
| 186 | } |
| 187 | |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 188 | CommandLine::CommandLine(const StringVector& argv) |
| 189 | : argv_(1), |
| 190 | begin_args_(1) { |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 191 | InitFromArgv(argv); |
| 192 | } |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 193 | |
Chris Watkins | bb7211c | 2017-11-29 07:16:38 | [diff] [blame] | 194 | CommandLine::CommandLine(const CommandLine& other) = default; |
jackhou | 1bd9da9 | 2015-05-21 04:48:00 | [diff] [blame] | 195 | |
Chris Watkins | bb7211c | 2017-11-29 07:16:38 | [diff] [blame] | 196 | CommandLine& CommandLine::operator=(const CommandLine& other) = default; |
jackhou | 1bd9da9 | 2015-05-21 04:48:00 | [diff] [blame] | 197 | |
Chris Watkins | bb7211c | 2017-11-29 07:16:38 | [diff] [blame] | 198 | CommandLine::~CommandLine() = default; |
[email protected] | acbeb3d | 2011-03-01 20:47:58 | [diff] [blame] | 199 | |
[email protected] | bf98a0e1 | 2013-09-25 23:36:00 | [diff] [blame] | 200 | #if defined(OS_WIN) |
| 201 | // static |
| 202 | void CommandLine::set_slash_is_not_a_switch() { |
| 203 | // The last switch prefix should be slash, so adjust the size to skip it. |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 204 | static_assert(base::make_span(kSwitchPrefixes).back() == L"/", |
| 205 | "Error: Last switch prefix is not a slash."); |
deepak1556 | bb31c18 | 2019-10-29 23:15:58 | [diff] [blame] | 206 | switch_prefix_count = base::size(kSwitchPrefixes) - 1; |
[email protected] | bf98a0e1 | 2013-09-25 23:36:00 | [diff] [blame] | 207 | } |
ananta | d936bc1 | 2016-06-22 21:40:31 | [diff] [blame] | 208 | |
| 209 | // static |
| 210 | void CommandLine::InitUsingArgvForTesting(int argc, const char* const* argv) { |
| 211 | DCHECK(!current_process_commandline_); |
| 212 | current_process_commandline_ = new CommandLine(NO_PROGRAM); |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 213 | // On Windows we need to convert the command line arguments to std::wstring. |
jdoerrie | 5c4dc4e | 2019-02-01 18:02:33 | [diff] [blame] | 214 | CommandLine::StringVector argv_vector; |
ananta | d936bc1 | 2016-06-22 21:40:31 | [diff] [blame] | 215 | for (int i = 0; i < argc; ++i) |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 216 | argv_vector.push_back(UTF8ToWide(argv[i])); |
ananta | d936bc1 | 2016-06-22 21:40:31 | [diff] [blame] | 217 | current_process_commandline_->InitFromArgv(argv_vector); |
| 218 | } |
[email protected] | bf98a0e1 | 2013-09-25 23:36:00 | [diff] [blame] | 219 | #endif |
| 220 | |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 221 | // static |
[email protected] | 72e2e242 | 2012-02-27 18:38:12 | [diff] [blame] | 222 | bool CommandLine::Init(int argc, const char* const* argv) { |
[email protected] | f96fe2c4 | 2011-07-13 18:03:34 | [diff] [blame] | 223 | if (current_process_commandline_) { |
| 224 | // If this is intentional, Reset() must be called first. If we are using |
| 225 | // the shared build mode, we have to share a single object across multiple |
| 226 | // shared libraries. |
[email protected] | 72e2e242 | 2012-02-27 18:38:12 | [diff] [blame] | 227 | return false; |
[email protected] | f96fe2c4 | 2011-07-13 18:03:34 | [diff] [blame] | 228 | } |
| 229 | |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 230 | current_process_commandline_ = new CommandLine(NO_PROGRAM); |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 231 | #if defined(OS_WIN) |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 232 | current_process_commandline_->ParseFromString(::GetCommandLineW()); |
Fabrice de Gans-Riberi | 306871de | 2018-05-16 19:38:39 | [diff] [blame] | 233 | #elif defined(OS_POSIX) || defined(OS_FUCHSIA) |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 234 | current_process_commandline_->InitFromArgv(argc, argv); |
Fabrice de Gans-Riberi | 306871de | 2018-05-16 19:38:39 | [diff] [blame] | 235 | #else |
| 236 | #error Unsupported platform |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 237 | #endif |
[email protected] | 72e2e242 | 2012-02-27 18:38:12 | [diff] [blame] | 238 | |
| 239 | return true; |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | // static |
| 243 | void CommandLine::Reset() { |
| 244 | DCHECK(current_process_commandline_); |
| 245 | delete current_process_commandline_; |
Ivan Kotenkov | a16212a5 | 2017-11-08 12:37:33 | [diff] [blame] | 246 | current_process_commandline_ = nullptr; |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | // static |
| 250 | CommandLine* CommandLine::ForCurrentProcess() { |
| 251 | DCHECK(current_process_commandline_); |
| 252 | return current_process_commandline_; |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 253 | } |
| 254 | |
[email protected] | 2bf64a9 | 2013-07-11 23:10:40 | [diff] [blame] | 255 | // static |
| 256 | bool CommandLine::InitializedForCurrentProcess() { |
| 257 | return !!current_process_commandline_; |
| 258 | } |
| 259 | |
[email protected] | f3adb5c | 2008-08-07 20:07:32 | [diff] [blame] | 260 | #if defined(OS_WIN) |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 261 | // static |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 262 | CommandLine CommandLine::FromString(StringPieceType command_line) { |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 263 | CommandLine cmd(NO_PROGRAM); |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 264 | cmd.ParseFromString(command_line); |
| 265 | return cmd; |
| 266 | } |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 267 | #endif |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 268 | |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 269 | void CommandLine::InitFromArgv(int argc, |
| 270 | const CommandLine::CharType* const* argv) { |
| 271 | StringVector new_argv; |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 272 | for (int i = 0; i < argc; ++i) |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 273 | new_argv.push_back(argv[i]); |
| 274 | InitFromArgv(new_argv); |
[email protected] | 51343d5a | 2009-10-26 22:39:33 | [diff] [blame] | 275 | } |
| 276 | |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 277 | void CommandLine::InitFromArgv(const StringVector& argv) { |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 278 | argv_ = StringVector(1); |
[email protected] | 93660ab3 | 2013-06-18 08:19:18 | [diff] [blame] | 279 | switches_.clear(); |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 280 | begin_args_ = 1; |
| 281 | SetProgram(argv.empty() ? FilePath() : FilePath(argv[0])); |
thestig | 8badc79 | 2014-12-04 22:14:22 | [diff] [blame] | 282 | AppendSwitchesAndArguments(this, argv); |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 283 | } |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 284 | |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 285 | FilePath CommandLine::GetProgram() const { |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 286 | return FilePath(argv_[0]); |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | void CommandLine::SetProgram(const FilePath& program) { |
tfarina | 023b1dcc | 2015-12-06 13:25:41 | [diff] [blame] | 290 | #if defined(OS_WIN) |
Jan Wilken Dörrie | b630aca | 2019-12-04 10:59:11 | [diff] [blame^] | 291 | argv_[0] = StringType(TrimWhitespace(program.value(), TRIM_ALL)); |
Fabrice de Gans-Riberi | 306871de | 2018-05-16 19:38:39 | [diff] [blame] | 292 | #elif defined(OS_POSIX) || defined(OS_FUCHSIA) |
tfarina | 023b1dcc | 2015-12-06 13:25:41 | [diff] [blame] | 293 | TrimWhitespaceASCII(program.value(), TRIM_ALL, &argv_[0]); |
Fabrice de Gans-Riberi | 306871de | 2018-05-16 19:38:39 | [diff] [blame] | 294 | #else |
| 295 | #error Unsupported platform |
tfarina | 023b1dcc | 2015-12-06 13:25:41 | [diff] [blame] | 296 | #endif |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 297 | } |
| 298 | |
jdoerrie | 5c4dc4e | 2019-02-01 18:02:33 | [diff] [blame] | 299 | bool CommandLine::HasSwitch(const StringPiece& switch_string) const { |
brettw | fce8d19 | 2015-08-10 19:07:51 | [diff] [blame] | 300 | DCHECK_EQ(ToLowerASCII(switch_string), switch_string); |
Jan Wilken Dörrie | f61e74c | 2019-06-07 08:20:02 | [diff] [blame] | 301 | return Contains(switches_, switch_string); |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 302 | } |
| 303 | |
jackhou | 1bd9da9 | 2015-05-21 04:48:00 | [diff] [blame] | 304 | bool CommandLine::HasSwitch(const char switch_constant[]) const { |
jdoerrie | 5c4dc4e | 2019-02-01 18:02:33 | [diff] [blame] | 305 | return HasSwitch(StringPiece(switch_constant)); |
tapted | 009a1dc8 | 2015-03-30 03:57:10 | [diff] [blame] | 306 | } |
| 307 | |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 308 | std::string CommandLine::GetSwitchValueASCII( |
jdoerrie | 5c4dc4e | 2019-02-01 18:02:33 | [diff] [blame] | 309 | const StringPiece& switch_string) const { |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 310 | StringType value = GetSwitchValueNative(switch_string); |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 311 | #if defined(OS_WIN) |
| 312 | if (!IsStringASCII(base::AsStringPiece16(value))) { |
| 313 | #elif defined(OS_POSIX) || defined(OS_FUCHSIA) |
[email protected] | bd6fc2f | 2014-03-17 23:55:43 | [diff] [blame] | 314 | if (!IsStringASCII(value)) { |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 315 | #endif |
[email protected] | a42d463 | 2011-10-26 21:48:00 | [diff] [blame] | 316 | DLOG(WARNING) << "Value of switch (" << switch_string << ") must be ASCII."; |
| 317 | return std::string(); |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 318 | } |
| 319 | #if defined(OS_WIN) |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 320 | return WideToUTF8(value); |
Fabrice de Gans-Riberi | 306871de | 2018-05-16 19:38:39 | [diff] [blame] | 321 | #elif defined(OS_POSIX) || defined(OS_FUCHSIA) |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 322 | return value; |
| 323 | #endif |
| 324 | } |
| 325 | |
| 326 | FilePath CommandLine::GetSwitchValuePath( |
jdoerrie | 5c4dc4e | 2019-02-01 18:02:33 | [diff] [blame] | 327 | const StringPiece& switch_string) const { |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 328 | return FilePath(GetSwitchValueNative(switch_string)); |
| 329 | } |
| 330 | |
| 331 | CommandLine::StringType CommandLine::GetSwitchValueNative( |
jdoerrie | 5c4dc4e | 2019-02-01 18:02:33 | [diff] [blame] | 332 | const StringPiece& switch_string) const { |
brettw | fce8d19 | 2015-08-10 19:07:51 | [diff] [blame] | 333 | DCHECK_EQ(ToLowerASCII(switch_string), switch_string); |
Jeremy Roman | 863386d | 2017-10-31 19:25:38 | [diff] [blame] | 334 | auto result = switches_.find(switch_string); |
| 335 | return result == switches_.end() ? StringType() : result->second; |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 336 | } |
| 337 | |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 338 | void CommandLine::AppendSwitch(const std::string& switch_string) { |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 339 | AppendSwitchNative(switch_string, StringType()); |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | void CommandLine::AppendSwitchPath(const std::string& switch_string, |
| 343 | const FilePath& path) { |
| 344 | AppendSwitchNative(switch_string, path.value()); |
| 345 | } |
| 346 | |
| 347 | void CommandLine::AppendSwitchNative(const std::string& switch_string, |
| 348 | const CommandLine::StringType& value) { |
| 349 | #if defined(OS_WIN) |
brettw | fce8d19 | 2015-08-10 19:07:51 | [diff] [blame] | 350 | const std::string switch_key = ToLowerASCII(switch_string); |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 351 | StringType combined_switch_string(UTF8ToWide(switch_key)); |
Fabrice de Gans-Riberi | 306871de | 2018-05-16 19:38:39 | [diff] [blame] | 352 | #elif defined(OS_POSIX) || defined(OS_FUCHSIA) |
jackhou | 1bd9da9 | 2015-05-21 04:48:00 | [diff] [blame] | 353 | const std::string& switch_key = switch_string; |
| 354 | StringType combined_switch_string(switch_key); |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 355 | #endif |
| 356 | size_t prefix_length = GetSwitchPrefixLength(combined_switch_string); |
jackhou | 1bd9da9 | 2015-05-21 04:48:00 | [diff] [blame] | 357 | auto insertion = |
| 358 | switches_.insert(make_pair(switch_key.substr(prefix_length), value)); |
| 359 | if (!insertion.second) |
| 360 | insertion.first->second = value; |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 361 | // Preserve existing switch prefixes in |argv_|; only append one if necessary. |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 362 | if (prefix_length == 0) { |
| 363 | combined_switch_string.insert(0, kSwitchPrefixes[0].data(), |
| 364 | kSwitchPrefixes[0].size()); |
| 365 | } |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 366 | if (!value.empty()) |
| 367 | combined_switch_string += kSwitchValueSeparator + value; |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 368 | // Append the switch and update the switches/arguments divider |begin_args_|. |
| 369 | argv_.insert(argv_.begin() + begin_args_++, combined_switch_string); |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | void CommandLine::AppendSwitchASCII(const std::string& switch_string, |
| 373 | const std::string& value_string) { |
| 374 | #if defined(OS_WIN) |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 375 | AppendSwitchNative(switch_string, UTF8ToWide(value_string)); |
Fabrice de Gans-Riberi | 306871de | 2018-05-16 19:38:39 | [diff] [blame] | 376 | #elif defined(OS_POSIX) || defined(OS_FUCHSIA) |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 377 | AppendSwitchNative(switch_string, value_string); |
Fabrice de Gans-Riberi | 306871de | 2018-05-16 19:38:39 | [diff] [blame] | 378 | #else |
| 379 | #error Unsupported platform |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 380 | #endif |
| 381 | } |
| 382 | |
Pavol Marko | bf16b81 | 2019-06-14 00:53:12 | [diff] [blame] | 383 | void CommandLine::RemoveSwitch(base::StringPiece switch_key_without_prefix) { |
| 384 | #if defined(OS_WIN) |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 385 | StringType switch_key_native = UTF8ToWide(switch_key_without_prefix); |
Pavol Marko | bf16b81 | 2019-06-14 00:53:12 | [diff] [blame] | 386 | #elif defined(OS_POSIX) || defined(OS_FUCHSIA) |
| 387 | StringType switch_key_native = switch_key_without_prefix.as_string(); |
| 388 | #endif |
| 389 | |
| 390 | DCHECK_EQ(ToLowerASCII(switch_key_without_prefix), switch_key_without_prefix); |
| 391 | DCHECK_EQ(0u, GetSwitchPrefixLength(switch_key_native)); |
| 392 | size_t erased_from_switches = |
| 393 | switches_.erase(switch_key_without_prefix.as_string()); |
| 394 | DCHECK(erased_from_switches <= 1); |
| 395 | if (!erased_from_switches) |
| 396 | return; |
| 397 | |
| 398 | // Also erase from the switches section of |argv_| and update |begin_args_| |
| 399 | // accordingly. |
| 400 | // Switches in |argv_| have indices [1, begin_args_). |
| 401 | auto argv_switches_begin = argv_.begin() + 1; |
| 402 | auto argv_switches_end = argv_.begin() + begin_args_; |
| 403 | DCHECK(argv_switches_begin <= argv_switches_end); |
| 404 | DCHECK(argv_switches_end <= argv_.end()); |
Andrei Polushin | 2ec89bc | 2019-07-30 20:47:17 | [diff] [blame] | 405 | auto expell = std::remove_if(argv_switches_begin, argv_switches_end, |
Pavol Marko | bf16b81 | 2019-06-14 00:53:12 | [diff] [blame] | 406 | [&switch_key_native](const StringType& arg) { |
| 407 | return IsSwitchWithKey(arg, switch_key_native); |
| 408 | }); |
Andrei Polushin | 2ec89bc | 2019-07-30 20:47:17 | [diff] [blame] | 409 | if (expell == argv_switches_end) { |
Pavol Marko | bf16b81 | 2019-06-14 00:53:12 | [diff] [blame] | 410 | NOTREACHED(); |
| 411 | return; |
| 412 | } |
Andrei Polushin | 2ec89bc | 2019-07-30 20:47:17 | [diff] [blame] | 413 | begin_args_ -= argv_switches_end - expell; |
| 414 | argv_.erase(expell, argv_switches_end); |
Avi Drissman | 1aa6cb9 | 2019-01-23 15:58:38 | [diff] [blame] | 415 | } |
| 416 | |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 417 | void CommandLine::CopySwitchesFrom(const CommandLine& source, |
| 418 | const char* const switches[], |
| 419 | size_t count) { |
| 420 | for (size_t i = 0; i < count; ++i) { |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 421 | if (source.HasSwitch(switches[i])) |
| 422 | AppendSwitchNative(switches[i], source.GetSwitchValueNative(switches[i])); |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
[email protected] | 75f1c78 | 2011-07-13 23:41:22 | [diff] [blame] | 426 | CommandLine::StringVector CommandLine::GetArgs() const { |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 427 | // Gather all arguments after the last switch (may include kSwitchTerminator). |
| 428 | StringVector args(argv_.begin() + begin_args_, argv_.end()); |
| 429 | // Erase only the first kSwitchTerminator (maybe "--" is a legitimate page?) |
jdoerrie | 1c4b8ff | 2018-10-03 00:10:57 | [diff] [blame] | 430 | auto switch_terminator = |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 431 | std::find(args.begin(), args.end(), kSwitchTerminator); |
| 432 | if (switch_terminator != args.end()) |
| 433 | args.erase(switch_terminator); |
| 434 | return args; |
| 435 | } |
| 436 | |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 437 | void CommandLine::AppendArg(const std::string& value) { |
| 438 | #if defined(OS_WIN) |
[email protected] | bd6fc2f | 2014-03-17 23:55:43 | [diff] [blame] | 439 | DCHECK(IsStringUTF8(value)); |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 440 | AppendArgNative(UTF8ToWide(value)); |
Fabrice de Gans-Riberi | 306871de | 2018-05-16 19:38:39 | [diff] [blame] | 441 | #elif defined(OS_POSIX) || defined(OS_FUCHSIA) |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 442 | AppendArgNative(value); |
Fabrice de Gans-Riberi | 306871de | 2018-05-16 19:38:39 | [diff] [blame] | 443 | #else |
| 444 | #error Unsupported platform |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 445 | #endif |
| 446 | } |
| 447 | |
| 448 | void CommandLine::AppendArgPath(const FilePath& path) { |
| 449 | AppendArgNative(path.value()); |
| 450 | } |
| 451 | |
| 452 | void CommandLine::AppendArgNative(const CommandLine::StringType& value) { |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 453 | argv_.push_back(value); |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | void CommandLine::AppendArguments(const CommandLine& other, |
| 457 | bool include_program) { |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 458 | if (include_program) |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 459 | SetProgram(other.GetProgram()); |
thestig | 8badc79 | 2014-12-04 22:14:22 | [diff] [blame] | 460 | AppendSwitchesAndArguments(this, other.argv()); |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | void CommandLine::PrependWrapper(const CommandLine::StringType& wrapper) { |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 464 | if (wrapper.empty()) |
| 465 | return; |
skyostil | d851aa1 | 2017-03-29 17:38:35 | [diff] [blame] | 466 | // Split the wrapper command based on whitespace (with quoting). |
| 467 | using CommandLineTokenizer = |
| 468 | StringTokenizerT<StringType, StringType::const_iterator>; |
| 469 | CommandLineTokenizer tokenizer(wrapper, FILE_PATH_LITERAL(" ")); |
| 470 | tokenizer.set_quote_chars(FILE_PATH_LITERAL("'\"")); |
| 471 | std::vector<StringType> wrapper_argv; |
| 472 | while (tokenizer.GetNext()) |
| 473 | wrapper_argv.emplace_back(tokenizer.token()); |
| 474 | |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 475 | // Prepend the wrapper and update the switches/arguments |begin_args_|. |
| 476 | argv_.insert(argv_.begin(), wrapper_argv.begin(), wrapper_argv.end()); |
| 477 | begin_args_ += wrapper_argv.size(); |
[email protected] | 06cc083a | 2011-03-01 02:28:42 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | #if defined(OS_WIN) |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 481 | void CommandLine::ParseFromString(StringPieceType command_line) { |
jdoerrie | 9078701 | 2019-02-07 16:22:02 | [diff] [blame] | 482 | command_line = TrimWhitespace(command_line, TRIM_ALL); |
| 483 | if (command_line.empty()) |
[email protected] | bb97536 | 2009-01-21 01:00:22 | [diff] [blame] | 484 | return; |
| 485 | |
| 486 | int num_args = 0; |
| 487 | wchar_t** args = NULL; |
Cliff Smolinsky | c5c5210 | 2019-05-03 20:51:54 | [diff] [blame] | 488 | // When calling CommandLineToArgvW, use the apiset if available. |
| 489 | // Doing so will bypass loading shell32.dll on Win8+. |
| 490 | HMODULE downlevel_shell32_dll = |
| 491 | ::LoadLibraryEx(L"api-ms-win-downlevel-shell32-l1-1-0.dll", nullptr, |
| 492 | LOAD_LIBRARY_SEARCH_SYSTEM32); |
| 493 | if (downlevel_shell32_dll) { |
| 494 | auto command_line_to_argv_w_proc = |
| 495 | reinterpret_cast<decltype(::CommandLineToArgvW)*>( |
| 496 | ::GetProcAddress(downlevel_shell32_dll, "CommandLineToArgvW")); |
| 497 | if (command_line_to_argv_w_proc) |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 498 | args = command_line_to_argv_w_proc(command_line.data(), &num_args); |
Cliff Smolinsky | c5c5210 | 2019-05-03 20:51:54 | [diff] [blame] | 499 | ::FreeLibrary(downlevel_shell32_dll); |
| 500 | } else { |
| 501 | // Since the apiset is not available, allow the delayload of shell32.dll |
| 502 | // to take place. |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 503 | args = ::CommandLineToArgvW(command_line.data(), &num_args); |
Cliff Smolinsky | c5c5210 | 2019-05-03 20:51:54 | [diff] [blame] | 504 | } |
[email protected] | bb97536 | 2009-01-21 01:00:22 | [diff] [blame] | 505 | |
[email protected] | a42d463 | 2011-10-26 21:48:00 | [diff] [blame] | 506 | DPLOG_IF(FATAL, !args) << "CommandLineToArgvW failed on command line: " |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 507 | << command_line; |
| 508 | StringVector argv(args, args + num_args); |
jdoerrie | 5c4dc4e | 2019-02-01 18:02:33 | [diff] [blame] | 509 | InitFromArgv(argv); |
[email protected] | a40ca430 | 2011-05-14 01:10:24 | [diff] [blame] | 510 | LocalFree(args); |
[email protected] | bb97536 | 2009-01-21 01:00:22 | [diff] [blame] | 511 | } |
[email protected] | f3adb5c | 2008-08-07 20:07:32 | [diff] [blame] | 512 | #endif |
[email protected] | 2f3b1cc | 2014-03-17 23:07:15 | [diff] [blame] | 513 | |
mgiuca | c974d510 | 2014-10-01 09:24:51 | [diff] [blame] | 514 | CommandLine::StringType CommandLine::GetCommandLineStringInternal( |
| 515 | bool quote_placeholders) const { |
| 516 | StringType string(argv_[0]); |
| 517 | #if defined(OS_WIN) |
| 518 | string = QuoteForCommandLineToArgvW(string, quote_placeholders); |
| 519 | #endif |
| 520 | StringType params(GetArgumentsStringInternal(quote_placeholders)); |
| 521 | if (!params.empty()) { |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 522 | string.append(FILE_PATH_LITERAL(" ")); |
mgiuca | c974d510 | 2014-10-01 09:24:51 | [diff] [blame] | 523 | string.append(params); |
| 524 | } |
| 525 | return string; |
| 526 | } |
| 527 | |
| 528 | CommandLine::StringType CommandLine::GetArgumentsStringInternal( |
| 529 | bool quote_placeholders) const { |
| 530 | StringType params; |
| 531 | // Append switches and arguments. |
| 532 | bool parse_switches = true; |
| 533 | for (size_t i = 1; i < argv_.size(); ++i) { |
| 534 | StringType arg = argv_[i]; |
| 535 | StringType switch_string; |
| 536 | StringType switch_value; |
| 537 | parse_switches &= arg != kSwitchTerminator; |
| 538 | if (i > 1) |
Jan Wilken Dörrie | da77fd43 | 2019-10-24 21:40:34 | [diff] [blame] | 539 | params.append(FILE_PATH_LITERAL(" ")); |
mgiuca | c974d510 | 2014-10-01 09:24:51 | [diff] [blame] | 540 | if (parse_switches && IsSwitch(arg, &switch_string, &switch_value)) { |
| 541 | params.append(switch_string); |
| 542 | if (!switch_value.empty()) { |
| 543 | #if defined(OS_WIN) |
| 544 | switch_value = |
| 545 | QuoteForCommandLineToArgvW(switch_value, quote_placeholders); |
| 546 | #endif |
| 547 | params.append(kSwitchValueSeparator + switch_value); |
| 548 | } |
thestig | 8badc79 | 2014-12-04 22:14:22 | [diff] [blame] | 549 | } else { |
mgiuca | c974d510 | 2014-10-01 09:24:51 | [diff] [blame] | 550 | #if defined(OS_WIN) |
| 551 | arg = QuoteForCommandLineToArgvW(arg, quote_placeholders); |
| 552 | #endif |
| 553 | params.append(arg); |
| 554 | } |
| 555 | } |
| 556 | return params; |
| 557 | } |
| 558 | |
[email protected] | 2f3b1cc | 2014-03-17 23:07:15 | [diff] [blame] | 559 | } // namespace base |