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

Side by Side Diff: base/command_line.cc

Issue 4949004: Add a unit test for CommandLine that makes sure that GetProgram will not retu... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 1 month 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 | Annotate | Revision Log
« 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #elif defined(OS_POSIX) 10 #elif defined(OS_POSIX)
(...skipping 28 matching lines...) Expand all
39 const wchar_t* const kSwitchPrefixes[] = {L"--", L"-", L"/"}; 39 const wchar_t* const kSwitchPrefixes[] = {L"--", L"-", L"/"};
40 const wchar_t kSwitchTerminator[] = L"--"; 40 const wchar_t kSwitchTerminator[] = L"--";
41 const wchar_t kSwitchValueSeparator[] = L"="; 41 const wchar_t kSwitchValueSeparator[] = L"=";
42 #elif defined(OS_POSIX) 42 #elif defined(OS_POSIX)
43 // Unixes don't use slash as a switch. 43 // Unixes don't use slash as a switch.
44 const char* const kSwitchPrefixes[] = {"--", "-"}; 44 const char* const kSwitchPrefixes[] = {"--", "-"};
45 const char kSwitchTerminator[] = "--"; 45 const char kSwitchTerminator[] = "--";
46 const char kSwitchValueSeparator[] = "="; 46 const char kSwitchValueSeparator[] = "=";
47 #endif 47 #endif
48 48
49 namespace {
50
51 // Trims the quotes from the beginning and end of a path.
52 CommandLine::StringType TrimQuotes(const FilePath::StringType& path) {
53 if (!path.empty() && path[0] == '"' && path[path.length() - 1] == '"')
54 return path.substr(1, path.length() - 2);
55 return path;
56 }
57
58 } // end namespace
59
49 #if defined(OS_WIN) 60 #if defined(OS_WIN)
50 // Lowercase a string. This is used to lowercase switch names. 61 // Lowercase a string. This is used to lowercase switch names.
51 // Is this what we really want? It seems crazy to me. I've left it in 62 // Is this what we really want? It seems crazy to me. I've left it in
52 // for backwards compatibility on Windows. 63 // for backwards compatibility on Windows.
53 static void Lowercase(std::string* parameter) { 64 static void Lowercase(std::string* parameter) {
54 transform(parameter->begin(), parameter->end(), parameter->begin(), 65 transform(parameter->begin(), parameter->end(), parameter->begin(),
55 tolower); 66 tolower);
56 } 67 }
57 #endif 68 #endif
58 69
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 118
108 // static 119 // static
109 CommandLine CommandLine::FromString(const std::wstring& command_line) { 120 CommandLine CommandLine::FromString(const std::wstring& command_line) {
110 CommandLine cmd; 121 CommandLine cmd;
111 cmd.ParseFromString(command_line); 122 cmd.ParseFromString(command_line);
112 return cmd; 123 return cmd;
113 } 124 }
114 125
115 CommandLine::CommandLine(const FilePath& program) { 126 CommandLine::CommandLine(const FilePath& program) {
116 if (!program.empty()) { 127 if (!program.empty()) {
117 program_ = program.value(); 128 program_ = TrimQuotes(program.value());
Evan Martin 2010/11/15 21:01:08 I think this is wrong. A FilePath is a platonic i
118 // TODO(evanm): proper quoting here. 129 // TODO(evanm): proper quoting here.
119 command_line_string_ = L'"' + program.value() + L'"'; 130 command_line_string_ = L'"' + program_ + L'"';
120 } 131 }
121 } 132 }
122 133
123 #elif defined(OS_POSIX) 134 #elif defined(OS_POSIX)
124 CommandLine::CommandLine(NoProgram no_program) { 135 CommandLine::CommandLine(NoProgram no_program) {
125 // Push an empty argument, because we always assume argv_[0] is a program. 136 // Push an empty argument, because we always assume argv_[0] is a program.
126 argv_.push_back(""); 137 argv_.push_back("");
127 } 138 }
128 139
129 CommandLine::CommandLine(int argc, const char* const* argv) { 140 CommandLine::CommandLine(int argc, const char* const* argv) {
(...skipping 30 matching lines...) Expand all
160 std::string switch_value; 171 std::string switch_value;
161 if (IsSwitch(arg, &switch_string, &switch_value)) { 172 if (IsSwitch(arg, &switch_string, &switch_value)) {
162 switches_[switch_string] = switch_value; 173 switches_[switch_string] = switch_value;
163 } else { 174 } else {
164 args_.push_back(arg); 175 args_.push_back(arg);
165 } 176 }
166 } 177 }
167 } 178 }
168 179
169 CommandLine::CommandLine(const FilePath& program) { 180 CommandLine::CommandLine(const FilePath& program) {
170 argv_.push_back(program.value()); 181 argv_.push_back(TrimQuotes(program.value());
171 } 182 }
172 183
173 #endif 184 #endif
174 185
175 // static 186 // static
176 bool CommandLine::IsSwitch(const StringType& parameter_string, 187 bool CommandLine::IsSwitch(const StringType& parameter_string,
177 std::string* switch_string, 188 std::string* switch_string,
178 StringType* switch_value) { 189 StringType* switch_value) {
179 switch_string->clear(); 190 switch_string->clear();
180 switch_value->clear(); 191 switch_value->clear();
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 546
536 // private 547 // private
537 CommandLine::CommandLine() { 548 CommandLine::CommandLine() {
538 } 549 }
539 550
540 // static 551 // static
541 CommandLine* CommandLine::ForCurrentProcessMutable() { 552 CommandLine* CommandLine::ForCurrentProcessMutable() {
542 DCHECK(current_process_commandline_); 553 DCHECK(current_process_commandline_);
543 return current_process_commandline_; 554 return current_process_commandline_;
544 } 555 }
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