Chromium Code Reviews| Index: base/command_line.cc |
| diff --git a/base/command_line.cc b/base/command_line.cc |
| index 99ea2b000324b87ea4ab11bae1f7c5374586331c..ceff0ec3a8caaa3d8a81a9f3710672f018e3e9d1 100644 |
| --- a/base/command_line.cc |
| +++ b/base/command_line.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/logging.h" |
| #include "base/macros.h" |
| #include "base/strings/string_split.h" |
| +#include "base/strings/string_tokenizer.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "build/build_config.h" |
| @@ -411,12 +412,16 @@ void CommandLine::AppendArguments(const CommandLine& other, |
| void CommandLine::PrependWrapper(const CommandLine::StringType& wrapper) { |
| if (wrapper.empty()) |
| return; |
| - // The wrapper may have embedded arguments (like "gdb --args"). In this case, |
| - // we don't pretend to do anything fancy, we just split on spaces. |
| - StringVector wrapper_argv = SplitString( |
| - wrapper, FilePath::StringType(1, ' '), base::TRIM_WHITESPACE, |
| - base::SPLIT_WANT_ALL); |
| - // Prepend the wrapper and update the switches/arguments |begin_args_|. |
| + // Split the wrapper command based on whitespace (with quoting). |
| + using CommandLineTokenizer = |
| + 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.
|
| + 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
|
| + tokenizer.set_quote_chars(FILE_PATH_LITERAL("'\"")); |
| + std::vector<StringType> wrapper_argv; |
| + while (tokenizer.GetNext()) |
| + wrapper_argv.emplace_back(tokenizer.token()); |
| + |
| + // 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.
|
| argv_.insert(argv_.begin(), wrapper_argv.begin(), wrapper_argv.end()); |
| begin_args_ += wrapper_argv.size(); |
| } |