Index: base/command_line.cc |
diff --git a/base/command_line.cc b/base/command_line.cc |
index 3fcf22ac52fc316358eb64173060db22029922b3..6fd50cc39b86eb47ba62748327d001f1d51365fd 100644 |
--- a/base/command_line.cc |
+++ b/base/command_line.cc |
@@ -15,11 +15,6 @@ |
#include "base/strings/utf_string_conversions.h" |
#include "build/build_config.h" |
-#if defined(OS_WIN) |
-#include <windows.h> |
-#include <shellapi.h> |
-#endif |
- |
namespace base { |
CommandLine* CommandLine::current_process_commandline_ = NULL; |
@@ -31,15 +26,8 @@ const CommandLine::CharType kSwitchValueSeparator[] = FILE_PATH_LITERAL("="); |
// Since we use a lazy match, make sure that longer versions (like "--") are |
// listed before shorter versions (like "-") of similar prefixes. |
-#if defined(OS_WIN) |
-// By putting slash last, we can control whether it is treaded as a switch |
-// value by changing the value of switch_prefix_count to be one less than |
-// the array size. |
-const CommandLine::CharType* const kSwitchPrefixes[] = {L"--", L"-", L"/"}; |
-#elif defined(OS_POSIX) |
// Unixes don't use slash as a switch. |
const CommandLine::CharType* const kSwitchPrefixes[] = {"--", "-"}; |
-#endif |
size_t switch_prefix_count = arraysize(kSwitchPrefixes); |
size_t GetSwitchPrefixLength(const CommandLine::StringType& string) { |
@@ -81,68 +69,13 @@ void AppendSwitchesAndArguments(CommandLine* command_line, |
CommandLine::StringType switch_value; |
parse_switches &= (arg != kSwitchTerminator); |
if (parse_switches && IsSwitch(arg, &switch_string, &switch_value)) { |
-#if defined(OS_WIN) |
- command_line->AppendSwitchNative(UTF16ToASCII(switch_string), |
- switch_value); |
-#elif defined(OS_POSIX) |
command_line->AppendSwitchNative(switch_string, switch_value); |
-#endif |
} else { |
command_line->AppendArgNative(arg); |
} |
} |
} |
-#if defined(OS_WIN) |
-// Quote a string as necessary for CommandLineToArgvW compatiblity *on Windows*. |
-string16 QuoteForCommandLineToArgvW(const string16& arg, |
- bool quote_placeholders) { |
- // We follow the quoting rules of CommandLineToArgvW. |
- // http://msdn.microsoft.com/en-us/library/17w5ykft.aspx |
- string16 quotable_chars(L" \\\""); |
- // We may also be required to quote '%', which is commonly used in a command |
- // line as a placeholder. (It may be substituted for a string with spaces.) |
- if (quote_placeholders) |
- quotable_chars.push_back(L'%'); |
- if (arg.find_first_of(quotable_chars) == string16::npos) { |
- // No quoting necessary. |
- return arg; |
- } |
- |
- string16 out; |
- out.push_back(L'"'); |
- for (size_t i = 0; i < arg.size(); ++i) { |
- if (arg[i] == '\\') { |
- // Find the extent of this run of backslashes. |
- size_t start = i, end = start + 1; |
- for (; end < arg.size() && arg[end] == '\\'; ++end) {} |
- size_t backslash_count = end - start; |
- |
- // Backslashes are escapes only if the run is followed by a double quote. |
- // Since we also will end the string with a double quote, we escape for |
- // either a double quote or the end of the string. |
- if (end == arg.size() || arg[end] == '"') { |
- // To quote, we need to output 2x as many backslashes. |
- backslash_count *= 2; |
- } |
- for (size_t j = 0; j < backslash_count; ++j) |
- out.push_back('\\'); |
- |
- // Advance i to one before the end to balance i++ in loop. |
- i = end - 1; |
- } else if (arg[i] == '"') { |
- out.push_back('\\'); |
- out.push_back('"'); |
- } else { |
- out.push_back(arg[i]); |
- } |
- } |
- out.push_back('"'); |
- |
- return out; |
-} |
-#endif |
- |
} // namespace |
CommandLine::CommandLine(NoProgram no_program) |
@@ -186,15 +119,6 @@ CommandLine& CommandLine::operator=(const CommandLine& other) { |
CommandLine::~CommandLine() { |
} |
-#if defined(OS_WIN) |
-// static |
-void CommandLine::set_slash_is_not_a_switch() { |
- // The last switch prefix should be slash, so adjust the size to skip it. |
- DCHECK_EQ(wcscmp(kSwitchPrefixes[arraysize(kSwitchPrefixes) - 1], L"/"), 0); |
- switch_prefix_count = arraysize(kSwitchPrefixes) - 1; |
-} |
-#endif |
- |
// static |
bool CommandLine::Init(int argc, const char* const* argv) { |
if (current_process_commandline_) { |
@@ -205,11 +129,7 @@ bool CommandLine::Init(int argc, const char* const* argv) { |
} |
current_process_commandline_ = new CommandLine(NO_PROGRAM); |
-#if defined(OS_WIN) |
- current_process_commandline_->ParseFromString(::GetCommandLineW()); |
-#elif defined(OS_POSIX) |
current_process_commandline_->InitFromArgv(argc, argv); |
-#endif |
return true; |
} |
@@ -232,15 +152,6 @@ bool CommandLine::InitializedForCurrentProcess() { |
return !!current_process_commandline_; |
} |
-#if defined(OS_WIN) |
-// static |
-CommandLine CommandLine::FromString(const string16& command_line) { |
- CommandLine cmd(NO_PROGRAM); |
- cmd.ParseFromString(command_line); |
- return cmd; |
-} |
-#endif |
- |
void CommandLine::InitFromArgv(int argc, |
const CommandLine::CharType* const* argv) { |
StringVector new_argv; |
@@ -283,11 +194,7 @@ std::string CommandLine::GetSwitchValueASCII( |
DLOG(WARNING) << "Value of switch (" << switch_string << ") must be ASCII."; |
return std::string(); |
} |
-#if defined(OS_WIN) |
- return UTF16ToASCII(value); |
-#else |
return value; |
-#endif |
} |
FilePath CommandLine::GetSwitchValuePath( |
@@ -314,13 +221,8 @@ void CommandLine::AppendSwitchPath(const std::string& switch_string, |
void CommandLine::AppendSwitchNative(const std::string& switch_string, |
const CommandLine::StringType& value) { |
-#if defined(OS_WIN) |
- const std::string switch_key = StringToLowerASCII(switch_string); |
- StringType combined_switch_string(ASCIIToUTF16(switch_key)); |
-#elif defined(OS_POSIX) |
const std::string& switch_key = switch_string; |
StringType combined_switch_string(switch_key); |
-#endif |
size_t prefix_length = GetSwitchPrefixLength(combined_switch_string); |
auto insertion = |
switches_.insert(make_pair(switch_key.substr(prefix_length), value)); |
@@ -338,11 +240,7 @@ void CommandLine::AppendSwitchNative(const std::string& switch_string, |
void CommandLine::AppendSwitchASCII(const std::string& switch_string, |
const std::string& value_string) { |
-#if defined(OS_WIN) |
- AppendSwitchNative(switch_string, ASCIIToUTF16(value_string)); |
-#elif defined(OS_POSIX) |
AppendSwitchNative(switch_string, value_string); |
-#endif |
} |
void CommandLine::CopySwitchesFrom(const CommandLine& source, |
@@ -366,12 +264,7 @@ CommandLine::StringVector CommandLine::GetArgs() const { |
} |
void CommandLine::AppendArg(const std::string& value) { |
-#if defined(OS_WIN) |
- DCHECK(IsStringUTF8(value)); |
- AppendArgNative(UTF8ToWide(value)); |
-#elif defined(OS_POSIX) |
AppendArgNative(value); |
-#endif |
} |
void CommandLine::AppendArgPath(const FilePath& path) { |
@@ -401,30 +294,9 @@ void CommandLine::PrependWrapper(const CommandLine::StringType& wrapper) { |
begin_args_ += wrapper_argv.size(); |
} |
-#if defined(OS_WIN) |
-void CommandLine::ParseFromString(const string16& command_line) { |
- string16 command_line_string; |
- TrimWhitespace(command_line, TRIM_ALL, &command_line_string); |
- if (command_line_string.empty()) |
- return; |
- |
- int num_args = 0; |
- wchar_t** args = NULL; |
- args = ::CommandLineToArgvW(command_line_string.c_str(), &num_args); |
- |
- DPLOG_IF(FATAL, !args) << "CommandLineToArgvW failed on command line: " |
- << UTF16ToUTF8(command_line); |
- InitFromArgv(num_args, args); |
- LocalFree(args); |
-} |
-#endif |
- |
CommandLine::StringType CommandLine::GetCommandLineStringInternal( |
bool quote_placeholders) const { |
StringType string(argv_[0]); |
-#if defined(OS_WIN) |
- string = QuoteForCommandLineToArgvW(string, quote_placeholders); |
-#endif |
StringType params(GetArgumentsStringInternal(quote_placeholders)); |
if (!params.empty()) { |
string.append(StringType(FILE_PATH_LITERAL(" "))); |
@@ -448,16 +320,9 @@ CommandLine::StringType CommandLine::GetArgumentsStringInternal( |
if (parse_switches && IsSwitch(arg, &switch_string, &switch_value)) { |
params.append(switch_string); |
if (!switch_value.empty()) { |
-#if defined(OS_WIN) |
- switch_value = |
- QuoteForCommandLineToArgvW(switch_value, quote_placeholders); |
-#endif |
params.append(kSwitchValueSeparator + switch_value); |
} |
} else { |
-#if defined(OS_WIN) |
- arg = QuoteForCommandLineToArgvW(arg, quote_placeholders); |
-#endif |
params.append(arg); |
} |
} |