Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: base/command_line.cc

Issue 2778173003: base: Support command line wrappers with quoted arguments (Closed)
Patch Set: Review comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/command_line_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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, StringType::const_iterator>;
417 wrapper, FilePath::StringType(1, ' '), base::TRIM_WHITESPACE, 418 CommandLineTokenizer tokenizer(wrapper, FILE_PATH_LITERAL(" "));
418 base::SPLIT_WANT_ALL); 419 tokenizer.set_quote_chars(FILE_PATH_LITERAL("'\""));
420 std::vector<StringType> wrapper_argv;
421 while (tokenizer.GetNext())
422 wrapper_argv.emplace_back(tokenizer.token());
423
419 // Prepend the wrapper and update the switches/arguments |begin_args_|. 424 // Prepend the wrapper and update the switches/arguments |begin_args_|.
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())
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « no previous file | base/command_line_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698