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

Side by Side Diff: base/command_line.cc

Issue 1043803002: Use StringPiece for base CommandLine::HasSwitch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « base/command_line.h ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <algorithm> 7 #include <algorithm>
8 #include <ostream> 8 #include <ostream>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 switch_value); 86 switch_value);
87 #elif defined(OS_POSIX) 87 #elif defined(OS_POSIX)
88 command_line->AppendSwitchNative(switch_string, switch_value); 88 command_line->AppendSwitchNative(switch_string, switch_value);
89 #endif 89 #endif
90 } else { 90 } else {
91 command_line->AppendArgNative(arg); 91 command_line->AppendArgNative(arg);
92 } 92 }
93 } 93 }
94 } 94 }
95 95
96 // Lowercase switches for backwards compatiblity *on Windows*. 96 // Lowercase switches for backwards compatibility *on Windows*.
97 #if defined(OS_WIN) 97 #if defined(OS_WIN)
98 std::string LowerASCIIOnWindows(const std::string& string) { 98 std::string LowerASCIIOnWindows(const base::StringPiece& string) {
99 return StringToLowerASCII(string); 99 return StringToLowerASCII(string.as_string());
100 } 100 }
101 #elif defined(OS_POSIX) 101 #elif defined(OS_POSIX)
102 const std::string& LowerASCIIOnWindows(const std::string& string) { 102 std::string LowerASCIIOnWindows(const base::StringPiece& string) {
103 return string; 103 return string.as_string();
104 } 104 }
105 #endif 105 #endif
106 106
107 107
108 #if defined(OS_WIN) 108 #if defined(OS_WIN)
109 // Quote a string as necessary for CommandLineToArgvW compatiblity *on Windows*. 109 // Quote a string as necessary for CommandLineToArgvW compatiblity *on Windows*.
110 string16 QuoteForCommandLineToArgvW(const string16& arg, 110 string16 QuoteForCommandLineToArgvW(const string16& arg,
111 bool quote_placeholders) { 111 bool quote_placeholders) {
112 // We follow the quoting rules of CommandLineToArgvW. 112 // We follow the quoting rules of CommandLineToArgvW.
113 // http://msdn.microsoft.com/en-us/library/17w5ykft.aspx 113 // http://msdn.microsoft.com/en-us/library/17w5ykft.aspx
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 255 }
256 256
257 FilePath CommandLine::GetProgram() const { 257 FilePath CommandLine::GetProgram() const {
258 return FilePath(argv_[0]); 258 return FilePath(argv_[0]);
259 } 259 }
260 260
261 void CommandLine::SetProgram(const FilePath& program) { 261 void CommandLine::SetProgram(const FilePath& program) {
262 TrimWhitespace(program.value(), TRIM_ALL, &argv_[0]); 262 TrimWhitespace(program.value(), TRIM_ALL, &argv_[0]);
263 } 263 }
264 264
265 bool CommandLine::HasSwitch(const std::string& switch_string) const { 265 bool CommandLine::HasSwitch(const base::StringPiece& switch_string) const {
266 return switches_.find(LowerASCIIOnWindows(switch_string)) != switches_.end(); 266 return switches_.find(LowerASCIIOnWindows(switch_string)) != switches_.end();
267 } 267 }
268 268
269 std::string CommandLine::GetSwitchValueASCII( 269 std::string CommandLine::GetSwitchValueASCII(
270 const std::string& switch_string) const { 270 const std::string& switch_string) const {
271 StringType value = GetSwitchValueNative(switch_string); 271 StringType value = GetSwitchValueNative(switch_string);
272 if (!IsStringASCII(value)) { 272 if (!IsStringASCII(value)) {
273 DLOG(WARNING) << "Value of switch (" << switch_string << ") must be ASCII."; 273 DLOG(WARNING) << "Value of switch (" << switch_string << ") must be ASCII.";
274 return std::string(); 274 return std::string();
275 } 275 }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 #if defined(OS_WIN) 442 #if defined(OS_WIN)
443 arg = QuoteForCommandLineToArgvW(arg, quote_placeholders); 443 arg = QuoteForCommandLineToArgvW(arg, quote_placeholders);
444 #endif 444 #endif
445 params.append(arg); 445 params.append(arg);
446 } 446 }
447 } 447 }
448 return params; 448 return params;
449 } 449 }
450 450
451 } // namespace base 451 } // namespace base
OLDNEW
« no previous file with comments | « base/command_line.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698