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

Unified Diff: base/command_line.cc

Issue 24613003: Allow typing label names on Windows by not treating things that start with slashes as arguments rat… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: const removed Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/command_line.h ('k') | tools/gn/command_desc.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/command_line.cc
diff --git a/base/command_line.cc b/base/command_line.cc
index 36ac88f12c18c78794768e5e881e45201506c3ef..7050242e676c70b471705505c442588a43445b29 100644
--- a/base/command_line.cc
+++ b/base/command_line.cc
@@ -27,17 +27,22 @@ 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"/"};
#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) {
- 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 +174,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_) {
« no previous file with comments | « base/command_line.h ('k') | tools/gn/command_desc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698