diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-13 22:10:30 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-13 22:10:30 +0000 |
commit | 0445eb4ed9f9a9bb86f8c4338f86a84fbce7b7f2 (patch) | |
tree | 63eb34b491bfec6af9a6c04361d21d86c086d7eb /base | |
parent | c2c263cd9f2ac658d6dc35ecbd4551ca0c5cb154 (diff) | |
download | chromium_src-0445eb4ed9f9a9bb86f8c4338f86a84fbce7b7f2.zip chromium_src-0445eb4ed9f9a9bb86f8c4338f86a84fbce7b7f2.tar.gz chromium_src-0445eb4ed9f9a9bb86f8c4338f86a84fbce7b7f2.tar.bz2 |
CommandLine: eliminate wstring-accepting AppendLooseValue
Instead use AppendArg variants which accept a FilePath or an ASCII string.
Review URL: http://codereview.chromium.org/3134008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56100 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/command_line.cc | 24 | ||||
-rw-r--r-- | base/command_line.h | 10 | ||||
-rw-r--r-- | base/process_util_unittest.cc | 10 |
3 files changed, 30 insertions, 14 deletions
diff --git a/base/command_line.cc b/base/command_line.cc index 5767669..9b531fa 100644 --- a/base/command_line.cc +++ b/base/command_line.cc @@ -422,11 +422,14 @@ void CommandLine::AppendSwitchNative(const std::string& switch_string, switches_[switch_string] = value; } -void CommandLine::AppendLooseValue(const std::wstring& value) { - // TODO(evan): the quoting here is wrong, but current callers rely on it - // being wrong. I have another branch which fixes all the callers. +void CommandLine::AppendArg(const std::string& value) { + DCHECK(IsStringUTF8(value)); + AppendArgNative(UTF8ToWide(value)); +} + +void CommandLine::AppendArgNative(const std::wstring& value) { command_line_string_.append(L" "); - command_line_string_.append(value); + command_line_string_.append(WindowsStyleQuote(value)); args_.push_back(value); } @@ -472,8 +475,13 @@ void CommandLine::AppendSwitchASCII(const std::string& switch_string, AppendSwitchNative(switch_string, value_string); } -void CommandLine::AppendLooseValue(const std::wstring& value) { - argv_.push_back(base::SysWideToNativeMB(value)); +void CommandLine::AppendArg(const std::string& value) { + AppendArgNative(value); +} + +void CommandLine::AppendArgNative(const std::string& value) { + DCHECK(IsStringUTF8(value)); + argv_.push_back(value); } void CommandLine::AppendArguments(const CommandLine& other, @@ -499,6 +507,10 @@ void CommandLine::PrependWrapper(const std::string& wrapper) { #endif +void CommandLine::AppendArgPath(const FilePath& path) { + AppendArgNative(path.value()); +} + void CommandLine::AppendSwitchPath(const std::string& switch_string, const FilePath& path) { AppendSwitchNative(switch_string, path.value()); diff --git a/base/command_line.h b/base/command_line.h index 10fbc92..e4ac08b 100644 --- a/base/command_line.h +++ b/base/command_line.h @@ -141,8 +141,14 @@ class CommandLine { void AppendSwitchASCII(const std::string& switch_string, const std::string& value); - // Append a loose value to the command line. - void AppendLooseValue(const std::wstring& value); + // Append an argument to the command line. + // Note on quoting: the argument will be quoted properly such that it is + // interpreted as one argument to the target command. + // AppendArg is primarily for ASCII; non-ASCII input will be + // interpreted as UTF-8. + void AppendArg(const std::string& value); + void AppendArgPath(const FilePath& value); + void AppendArgNative(const StringType& value); // Append the arguments from another command line to this one. // If |include_program| is true, include |other|'s program as well. diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc index 8da89b0..6f4ed39 100644 --- a/base/process_util_unittest.cc +++ b/base/process_util_unittest.cc @@ -205,18 +205,16 @@ TEST_F(ProcessUtilTest, GetAppOutput) { .Append(FILE_PATH_LITERAL("python.exe")); CommandLine cmd_line(python_runtime); - cmd_line.AppendLooseValue(L"-c"); - cmd_line.AppendLooseValue(L"\"import sys; sys.stdout.write('" + - ASCIIToWide(message) + L"');\""); + cmd_line.AppendArg("-c"); + cmd_line.AppendArg("import sys; sys.stdout.write('" + message + "');"); std::string output; ASSERT_TRUE(base::GetAppOutput(cmd_line, &output)); EXPECT_EQ(message, output); // Let's make sure stderr is ignored. CommandLine other_cmd_line(python_runtime); - other_cmd_line.AppendLooseValue(L"-c"); - other_cmd_line.AppendLooseValue( - L"\"import sys; sys.stderr.write('Hello!');\""); + other_cmd_line.AppendArg("-c"); + other_cmd_line.AppendArg("import sys; sys.stderr.write('Hello!');"); output.clear(); ASSERT_TRUE(base::GetAppOutput(other_cmd_line, &output)); EXPECT_EQ("", output); |