Chromium Code Reviews| Index: base/command_line.cc |
| diff --git a/base/command_line.cc b/base/command_line.cc |
| index 36ac88f12c18c78794768e5e881e45201506c3ef..2492453c20e091eb2d01f37c44f1b98ddbc90b2c 100644 |
| --- a/base/command_line.cc |
| +++ b/base/command_line.cc |
| @@ -27,17 +27,23 @@ CommandLine* CommandLine::current_process_commandline_ = NULL; |
| namespace { |
| const CommandLine::CharType kSwitchTerminator[] = FILE_PATH_LITERAL("--"); |
| 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"/"}; |
| +size_t switch_prefix_count = arraysize(kSwitchPrefixes); |
|
scottmg
2013/09/25 18:20:36
nit; don't see a lot of benefit to the const for n
|
| #elif defined(OS_POSIX) |
| // Unixes don't use slash as a switch. |
| const CommandLine::CharType* const kSwitchPrefixes[] = {"--", "-"}; |
| +const size_t switch_prefix_count = arraysize(kSwitchPrefixes); |
| #endif |
| size_t GetSwitchPrefixLength(const CommandLine::StringType& string) { |
| - for (size_t i = 0; i < arraysize(kSwitchPrefixes); ++i) { |
| + for (size_t i = 0; i < switch_prefix_count; ++i) { |
| CommandLine::StringType prefix(kSwitchPrefixes[i]); |
| if (string.compare(0, prefix.length(), prefix) == 0) |
| return prefix.length(); |
| @@ -169,6 +175,15 @@ CommandLine::CommandLine(const StringVector& argv) |
| 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(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_) { |