Chromium Code Reviews| 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/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "base/strings/string_tokenizer.h" | |
| 14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 17 | 18 |
| 18 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
| 19 #include <windows.h> | 20 #include <windows.h> |
| 20 #include <shellapi.h> | 21 #include <shellapi.h> |
| 21 #endif | 22 #endif |
| 22 | 23 |
| 23 namespace base { | 24 namespace base { |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 void CommandLine::AppendArguments(const CommandLine& other, | 405 void CommandLine::AppendArguments(const CommandLine& other, |
| 405 bool include_program) { | 406 bool include_program) { |
| 406 if (include_program) | 407 if (include_program) |
| 407 SetProgram(other.GetProgram()); | 408 SetProgram(other.GetProgram()); |
| 408 AppendSwitchesAndArguments(this, other.argv()); | 409 AppendSwitchesAndArguments(this, other.argv()); |
| 409 } | 410 } |
| 410 | 411 |
| 411 void CommandLine::PrependWrapper(const CommandLine::StringType& wrapper) { | 412 void CommandLine::PrependWrapper(const CommandLine::StringType& wrapper) { |
| 412 if (wrapper.empty()) | 413 if (wrapper.empty()) |
| 413 return; | 414 return; |
| 414 // The wrapper may have embedded arguments (like "gdb --args"). In this case, | 415 // Split the wrapper command based on whitespace (with quoting). |
| 415 // we don't pretend to do anything fancy, we just split on spaces. | 416 using CommandLineTokenizer = |
| 416 StringVector wrapper_argv = SplitString( | 417 StringTokenizerT<StringType, CommandLine::StringType::const_iterator>; |
|
gab
2017/03/28 19:31:46
can we forgo the CommandLine:: namespace prefix in
Sami
2017/03/29 09:17:28
Well spotted, done.
| |
| 417 wrapper, FilePath::StringType(1, ' '), base::TRIM_WHITESPACE, | 418 CommandLineTokenizer tokenizer(wrapper, FILE_PATH_LITERAL(" ")); |
|
gab
2017/03/28 19:31:46
Unfortunate to use FILE_PATH_LITERAL on a non-file
Sami
2017/03/29 09:17:28
Yep, doesn't look like there's any neat alternativ
| |
| 418 base::SPLIT_WANT_ALL); | 419 tokenizer.set_quote_chars(FILE_PATH_LITERAL("'\"")); |
| 419 // Prepend the wrapper and update the switches/arguments |begin_args_|. | 420 std::vector<StringType> wrapper_argv; |
| 421 while (tokenizer.GetNext()) | |
| 422 wrapper_argv.emplace_back(tokenizer.token()); | |
| 423 | |
| 424 // Prepend the wrapper and update the switches/arguments |begin_args_| | |
|
gab
2017/03/28 19:31:46
nit: keep '.' at end of comment
Sami
2017/03/29 09:17:28
Done.
| |
| 420 argv_.insert(argv_.begin(), wrapper_argv.begin(), wrapper_argv.end()); | 425 argv_.insert(argv_.begin(), wrapper_argv.begin(), wrapper_argv.end()); |
| 421 begin_args_ += wrapper_argv.size(); | 426 begin_args_ += wrapper_argv.size(); |
| 422 } | 427 } |
| 423 | 428 |
| 424 #if defined(OS_WIN) | 429 #if defined(OS_WIN) |
| 425 void CommandLine::ParseFromString(const string16& command_line) { | 430 void CommandLine::ParseFromString(const string16& command_line) { |
| 426 string16 command_line_string; | 431 string16 command_line_string; |
| 427 TrimWhitespace(command_line, TRIM_ALL, &command_line_string); | 432 TrimWhitespace(command_line, TRIM_ALL, &command_line_string); |
| 428 if (command_line_string.empty()) | 433 if (command_line_string.empty()) |
| 429 return; | 434 return; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 return params; | 489 return params; |
| 485 } | 490 } |
| 486 | 491 |
| 487 void CommandLine::ResetStringPieces() { | 492 void CommandLine::ResetStringPieces() { |
| 488 switches_by_stringpiece_.clear(); | 493 switches_by_stringpiece_.clear(); |
| 489 for (const auto& entry : switches_) | 494 for (const auto& entry : switches_) |
| 490 switches_by_stringpiece_[entry.first] = &(entry.second); | 495 switches_by_stringpiece_[entry.first] = &(entry.second); |
| 491 } | 496 } |
| 492 | 497 |
| 493 } // namespace base | 498 } // namespace base |
| OLD | NEW |