| 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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 | 332 |
| 333 void CommandLine::AppendSwitchPath(const std::string& switch_string, | 333 void CommandLine::AppendSwitchPath(const std::string& switch_string, |
| 334 const FilePath& path) { | 334 const FilePath& path) { |
| 335 AppendSwitchNative(switch_string, path.value()); | 335 AppendSwitchNative(switch_string, path.value()); |
| 336 } | 336 } |
| 337 | 337 |
| 338 void CommandLine::AppendSwitchNative(const std::string& switch_string, | 338 void CommandLine::AppendSwitchNative(const std::string& switch_string, |
| 339 const CommandLine::StringType& value) { | 339 const CommandLine::StringType& value) { |
| 340 std::string switch_key(LowerASCIIOnWindows(switch_string)); | 340 std::string switch_key(LowerASCIIOnWindows(switch_string)); |
| 341 #if defined(OS_WIN) | 341 #if defined(OS_WIN) |
| 342 StringType combined_switch_string(ASCIIToWide(switch_key)); | 342 StringType combined_switch_string(base::ASCIIToWide(switch_key)); |
| 343 #elif defined(OS_POSIX) | 343 #elif defined(OS_POSIX) |
| 344 StringType combined_switch_string(switch_string); | 344 StringType combined_switch_string(switch_string); |
| 345 #endif | 345 #endif |
| 346 size_t prefix_length = GetSwitchPrefixLength(combined_switch_string); | 346 size_t prefix_length = GetSwitchPrefixLength(combined_switch_string); |
| 347 switches_[switch_key.substr(prefix_length)] = value; | 347 switches_[switch_key.substr(prefix_length)] = value; |
| 348 // Preserve existing switch prefixes in |argv_|; only append one if necessary. | 348 // Preserve existing switch prefixes in |argv_|; only append one if necessary. |
| 349 if (prefix_length == 0) | 349 if (prefix_length == 0) |
| 350 combined_switch_string = kSwitchPrefixes[0] + combined_switch_string; | 350 combined_switch_string = kSwitchPrefixes[0] + combined_switch_string; |
| 351 if (!value.empty()) | 351 if (!value.empty()) |
| 352 combined_switch_string += kSwitchValueSeparator + value; | 352 combined_switch_string += kSwitchValueSeparator + value; |
| 353 // Append the switch and update the switches/arguments divider |begin_args_|. | 353 // Append the switch and update the switches/arguments divider |begin_args_|. |
| 354 argv_.insert(argv_.begin() + begin_args_++, combined_switch_string); | 354 argv_.insert(argv_.begin() + begin_args_++, combined_switch_string); |
| 355 } | 355 } |
| 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, base::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 void CommandLine::CopySwitchesFrom(const CommandLine& source, | 366 void CommandLine::CopySwitchesFrom(const CommandLine& source, |
| 367 const char* const switches[], | 367 const char* const switches[], |
| 368 size_t count) { | 368 size_t count) { |
| 369 for (size_t i = 0; i < count; ++i) { | 369 for (size_t i = 0; i < count; ++i) { |
| 370 if (source.HasSwitch(switches[i])) | 370 if (source.HasSwitch(switches[i])) |
| 371 AppendSwitchNative(switches[i], source.GetSwitchValueNative(switches[i])); | 371 AppendSwitchNative(switches[i], source.GetSwitchValueNative(switches[i])); |
| 372 } | 372 } |
| 373 } | 373 } |
| 374 | 374 |
| 375 CommandLine::StringVector CommandLine::GetArgs() const { | 375 CommandLine::StringVector CommandLine::GetArgs() const { |
| 376 // Gather all arguments after the last switch (may include kSwitchTerminator). | 376 // Gather all arguments after the last switch (may include kSwitchTerminator). |
| 377 StringVector args(argv_.begin() + begin_args_, argv_.end()); | 377 StringVector args(argv_.begin() + begin_args_, argv_.end()); |
| 378 // Erase only the first kSwitchTerminator (maybe "--" is a legitimate page?) | 378 // Erase only the first kSwitchTerminator (maybe "--" is a legitimate page?) |
| 379 StringVector::iterator switch_terminator = | 379 StringVector::iterator switch_terminator = |
| 380 std::find(args.begin(), args.end(), kSwitchTerminator); | 380 std::find(args.begin(), args.end(), kSwitchTerminator); |
| 381 if (switch_terminator != args.end()) | 381 if (switch_terminator != args.end()) |
| 382 args.erase(switch_terminator); | 382 args.erase(switch_terminator); |
| 383 return args; | 383 return args; |
| 384 } | 384 } |
| 385 | 385 |
| 386 void CommandLine::AppendArg(const std::string& value) { | 386 void CommandLine::AppendArg(const std::string& value) { |
| 387 #if defined(OS_WIN) | 387 #if defined(OS_WIN) |
| 388 DCHECK(IsStringUTF8(value)); | 388 DCHECK(IsStringUTF8(value)); |
| 389 AppendArgNative(UTF8ToWide(value)); | 389 AppendArgNative(base::UTF8ToWide(value)); |
| 390 #elif defined(OS_POSIX) | 390 #elif defined(OS_POSIX) |
| 391 AppendArgNative(value); | 391 AppendArgNative(value); |
| 392 #endif | 392 #endif |
| 393 } | 393 } |
| 394 | 394 |
| 395 void CommandLine::AppendArgPath(const FilePath& path) { | 395 void CommandLine::AppendArgPath(const FilePath& path) { |
| 396 AppendArgNative(path.value()); | 396 AppendArgNative(path.value()); |
| 397 } | 397 } |
| 398 | 398 |
| 399 void CommandLine::AppendArgNative(const CommandLine::StringType& value) { | 399 void CommandLine::AppendArgNative(const CommandLine::StringType& value) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 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 |