| 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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 356 |
| 357 void CommandLine::AppendSwitchASCII(const std::string& switch_string, | 357 void CommandLine::AppendSwitchASCII(const std::string& switch_string, |
| 358 const std::string& value_string) { | 358 const std::string& value_string) { |
| 359 #if defined(OS_WIN) | 359 #if defined(OS_WIN) |
| 360 AppendSwitchNative(switch_string, ASCIIToWide(value_string)); | 360 AppendSwitchNative(switch_string, ASCIIToWide(value_string)); |
| 361 #elif defined(OS_POSIX) | 361 #elif defined(OS_POSIX) |
| 362 AppendSwitchNative(switch_string, value_string); | 362 AppendSwitchNative(switch_string, value_string); |
| 363 #endif | 363 #endif |
| 364 } | 364 } |
| 365 | 365 |
| 366 namespace { |
| 367 |
| 368 class DoesSwitchEqual { |
| 369 public: |
| 370 explicit DoesSwitchEqual(const CommandLine::StringType& switch_string) |
| 371 : switch_string_(switch_string) { |
| 372 } |
| 373 bool operator()(const CommandLine::StringType& arg_string) const { |
| 374 return |
| 375 (arg_string.compare(0, switch_string_.length(), switch_string_) == 0); |
| 376 } |
| 377 private: |
| 378 const CommandLine::StringType switch_string_; |
| 379 }; |
| 380 |
| 381 } // namespace |
| 382 |
| 383 void CommandLine::RemoveSwitch(const std::string& switch_string) { |
| 384 std::string switch_key(LowerASCIIOnWindows(switch_string)); |
| 385 #if defined(OS_WIN) |
| 386 StringType combined_switch_string(ASCIIToWide(switch_key)); |
| 387 #elif defined(OS_POSIX) |
| 388 StringType combined_switch_string(switch_string); |
| 389 #endif |
| 390 size_t prefix_length = GetSwitchPrefixLength(combined_switch_string); |
| 391 |
| 392 if (!HasSwitch(switch_key.substr(prefix_length))) |
| 393 return; |
| 394 |
| 395 switches_.erase(switch_key.substr(prefix_length)); |
| 396 |
| 397 if (prefix_length == 0) |
| 398 combined_switch_string = kSwitchPrefixes[0] + combined_switch_string; |
| 399 size_t previous_size = argv_.size(); |
| 400 argv_.erase(std::remove_if(argv_.begin(), argv_.end(), |
| 401 DoesSwitchEqual(combined_switch_string)), |
| 402 argv_.end()); |
| 403 DCHECK((argv_.size() + 1) == previous_size); |
| 404 begin_args_--; |
| 405 } |
| 406 |
| 366 void CommandLine::CopySwitchesFrom(const CommandLine& source, | 407 void CommandLine::CopySwitchesFrom(const CommandLine& source, |
| 367 const char* const switches[], | 408 const char* const switches[], |
| 368 size_t count) { | 409 size_t count) { |
| 369 for (size_t i = 0; i < count; ++i) { | 410 for (size_t i = 0; i < count; ++i) { |
| 370 if (source.HasSwitch(switches[i])) | 411 if (source.HasSwitch(switches[i])) |
| 371 AppendSwitchNative(switches[i], source.GetSwitchValueNative(switches[i])); | 412 AppendSwitchNative(switches[i], source.GetSwitchValueNative(switches[i])); |
| 372 } | 413 } |
| 373 } | 414 } |
| 374 | 415 |
| 375 CommandLine::StringVector CommandLine::GetArgs() const { | 416 CommandLine::StringVector CommandLine::GetArgs() const { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 int num_args = 0; | 470 int num_args = 0; |
| 430 wchar_t** args = NULL; | 471 wchar_t** args = NULL; |
| 431 args = ::CommandLineToArgvW(command_line_string.c_str(), &num_args); | 472 args = ::CommandLineToArgvW(command_line_string.c_str(), &num_args); |
| 432 | 473 |
| 433 DPLOG_IF(FATAL, !args) << "CommandLineToArgvW failed on command line: " | 474 DPLOG_IF(FATAL, !args) << "CommandLineToArgvW failed on command line: " |
| 434 << command_line; | 475 << command_line; |
| 435 InitFromArgv(num_args, args); | 476 InitFromArgv(num_args, args); |
| 436 LocalFree(args); | 477 LocalFree(args); |
| 437 } | 478 } |
| 438 #endif | 479 #endif |
| OLD | NEW |