| 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 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <ostream> | 8 #include <ostream> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 *switch_value = string.substr(equals_position + 1); | 67 *switch_value = string.substr(equals_position + 1); |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Append switches and arguments, keeping switches before arguments. | 71 // Append switches and arguments, keeping switches before arguments. |
| 72 void AppendSwitchesAndArguments(CommandLine& command_line, | 72 void AppendSwitchesAndArguments(CommandLine& command_line, |
| 73 const CommandLine::StringVector& argv) { | 73 const CommandLine::StringVector& argv) { |
| 74 bool parse_switches = true; | 74 bool parse_switches = true; |
| 75 for (size_t i = 1; i < argv.size(); ++i) { | 75 for (size_t i = 1; i < argv.size(); ++i) { |
| 76 CommandLine::StringType arg = argv[i]; | 76 CommandLine::StringType arg = argv[i]; |
| 77 TrimWhitespace(arg, TRIM_ALL, &arg); | 77 base::TrimWhitespace(arg, base::TRIM_ALL, &arg); |
| 78 | 78 |
| 79 CommandLine::StringType switch_string; | 79 CommandLine::StringType switch_string; |
| 80 CommandLine::StringType switch_value; | 80 CommandLine::StringType switch_value; |
| 81 parse_switches &= (arg != kSwitchTerminator); | 81 parse_switches &= (arg != kSwitchTerminator); |
| 82 if (parse_switches && IsSwitch(arg, &switch_string, &switch_value)) { | 82 if (parse_switches && IsSwitch(arg, &switch_string, &switch_value)) { |
| 83 #if defined(OS_WIN) | 83 #if defined(OS_WIN) |
| 84 command_line.AppendSwitchNative(WideToASCII(switch_string), switch_value); | 84 command_line.AppendSwitchNative(WideToASCII(switch_string), switch_value); |
| 85 #elif defined(OS_POSIX) | 85 #elif defined(OS_POSIX) |
| 86 command_line.AppendSwitchNative(switch_string, switch_value); | 86 command_line.AppendSwitchNative(switch_string, switch_value); |
| 87 #endif | 87 #endif |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 } | 286 } |
| 287 } | 287 } |
| 288 return params; | 288 return params; |
| 289 } | 289 } |
| 290 | 290 |
| 291 FilePath CommandLine::GetProgram() const { | 291 FilePath CommandLine::GetProgram() const { |
| 292 return FilePath(argv_[0]); | 292 return FilePath(argv_[0]); |
| 293 } | 293 } |
| 294 | 294 |
| 295 void CommandLine::SetProgram(const FilePath& program) { | 295 void CommandLine::SetProgram(const FilePath& program) { |
| 296 TrimWhitespace(program.value(), TRIM_ALL, &argv_[0]); | 296 base::TrimWhitespace(program.value(), base::TRIM_ALL, &argv_[0]); |
| 297 } | 297 } |
| 298 | 298 |
| 299 bool CommandLine::HasSwitch(const std::string& switch_string) const { | 299 bool CommandLine::HasSwitch(const std::string& switch_string) const { |
| 300 return switches_.find(LowerASCIIOnWindows(switch_string)) != switches_.end(); | 300 return switches_.find(LowerASCIIOnWindows(switch_string)) != switches_.end(); |
| 301 } | 301 } |
| 302 | 302 |
| 303 std::string CommandLine::GetSwitchValueASCII( | 303 std::string CommandLine::GetSwitchValueASCII( |
| 304 const std::string& switch_string) const { | 304 const std::string& switch_string) const { |
| 305 StringType value = GetSwitchValueNative(switch_string); | 305 StringType value = GetSwitchValueNative(switch_string); |
| 306 if (!IsStringASCII(value)) { | 306 if (!IsStringASCII(value)) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 StringVector wrapper_argv; | 415 StringVector wrapper_argv; |
| 416 base::SplitString(wrapper, FILE_PATH_LITERAL(' '), &wrapper_argv); | 416 base::SplitString(wrapper, FILE_PATH_LITERAL(' '), &wrapper_argv); |
| 417 // Prepend the wrapper and update the switches/arguments |begin_args_|. | 417 // Prepend the wrapper and update the switches/arguments |begin_args_|. |
| 418 argv_.insert(argv_.begin(), wrapper_argv.begin(), wrapper_argv.end()); | 418 argv_.insert(argv_.begin(), wrapper_argv.begin(), wrapper_argv.end()); |
| 419 begin_args_ += wrapper_argv.size(); | 419 begin_args_ += wrapper_argv.size(); |
| 420 } | 420 } |
| 421 | 421 |
| 422 #if defined(OS_WIN) | 422 #if defined(OS_WIN) |
| 423 void CommandLine::ParseFromString(const std::wstring& command_line) { | 423 void CommandLine::ParseFromString(const std::wstring& command_line) { |
| 424 std::wstring command_line_string; | 424 std::wstring command_line_string; |
| 425 TrimWhitespace(command_line, TRIM_ALL, &command_line_string); | 425 base::TrimWhitespace(command_line, base::TRIM_ALL, &command_line_string); |
| 426 if (command_line_string.empty()) | 426 if (command_line_string.empty()) |
| 427 return; | 427 return; |
| 428 | 428 |
| 429 int num_args = 0; | 429 int num_args = 0; |
| 430 wchar_t** args = NULL; | 430 wchar_t** args = NULL; |
| 431 args = ::CommandLineToArgvW(command_line_string.c_str(), &num_args); | 431 args = ::CommandLineToArgvW(command_line_string.c_str(), &num_args); |
| 432 | 432 |
| 433 DPLOG_IF(FATAL, !args) << "CommandLineToArgvW failed on command line: " | 433 DPLOG_IF(FATAL, !args) << "CommandLineToArgvW failed on command line: " |
| 434 << command_line; | 434 << command_line; |
| 435 InitFromArgv(num_args, args); | 435 InitFromArgv(num_args, args); |
| 436 LocalFree(args); | 436 LocalFree(args); |
| 437 } | 437 } |
| 438 #endif | 438 #endif |
| OLD | NEW |