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

Side by Side Diff: base/command_line.cc

Issue 602253006: base::CommandLine: Replace use of wstring with string16. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@commandline-test-hardcode
Patch Set: Created 6 years, 2 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 #if defined(OS_WIN) 98 #if defined(OS_WIN)
99 return base::StringToLowerASCII(string); 99 return base::StringToLowerASCII(string);
100 #elif defined(OS_POSIX) 100 #elif defined(OS_POSIX)
101 return string; 101 return string;
102 #endif 102 #endif
103 } 103 }
104 104
105 105
106 #if defined(OS_WIN) 106 #if defined(OS_WIN)
107 // Quote a string as necessary for CommandLineToArgvW compatiblity *on Windows*. 107 // Quote a string as necessary for CommandLineToArgvW compatiblity *on Windows*.
108 std::wstring QuoteForCommandLineToArgvW(const std::wstring& arg) { 108 base::string16 QuoteForCommandLineToArgvW(const base::string16& arg) {
109 // We follow the quoting rules of CommandLineToArgvW. 109 // We follow the quoting rules of CommandLineToArgvW.
110 // http://msdn.microsoft.com/en-us/library/17w5ykft.aspx 110 // http://msdn.microsoft.com/en-us/library/17w5ykft.aspx
111 if (arg.find_first_of(L" \\\"") == std::wstring::npos) { 111 if (arg.find_first_of(L" \\\"") == base::string16::npos) {
112 // No quoting necessary. 112 // No quoting necessary.
113 return arg; 113 return arg;
114 } 114 }
115 115
116 std::wstring out; 116 base::string16 out;
117 out.push_back(L'"'); 117 out.push_back(L'"');
118 for (size_t i = 0; i < arg.size(); ++i) { 118 for (size_t i = 0; i < arg.size(); ++i) {
119 if (arg[i] == '\\') { 119 if (arg[i] == '\\') {
120 // Find the extent of this run of backslashes. 120 // Find the extent of this run of backslashes.
121 size_t start = i, end = start + 1; 121 size_t start = i, end = start + 1;
122 for (; end < arg.size() && arg[end] == '\\'; ++end) 122 for (; end < arg.size() && arg[end] == '\\'; ++end)
123 /* empty */; 123 /* empty */;
124 size_t backslash_count = end - start; 124 size_t backslash_count = end - start;
125 125
126 // Backslashes are escapes only if the run is followed by a double quote. 126 // Backslashes are escapes only if the run is followed by a double quote.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 return current_process_commandline_; 217 return current_process_commandline_;
218 } 218 }
219 219
220 // static 220 // static
221 bool CommandLine::InitializedForCurrentProcess() { 221 bool CommandLine::InitializedForCurrentProcess() {
222 return !!current_process_commandline_; 222 return !!current_process_commandline_;
223 } 223 }
224 224
225 #if defined(OS_WIN) 225 #if defined(OS_WIN)
226 // static 226 // static
227 CommandLine CommandLine::FromString(const std::wstring& command_line) { 227 CommandLine CommandLine::FromString(const base::string16& command_line) {
228 CommandLine cmd(NO_PROGRAM); 228 CommandLine cmd(NO_PROGRAM);
229 cmd.ParseFromString(command_line); 229 cmd.ParseFromString(command_line);
230 return cmd; 230 return cmd;
231 } 231 }
232 #endif 232 #endif
233 233
234 void CommandLine::InitFromArgv(int argc, 234 void CommandLine::InitFromArgv(int argc,
235 const CommandLine::CharType* const* argv) { 235 const CommandLine::CharType* const* argv) {
236 StringVector new_argv; 236 StringVector new_argv;
237 for (int i = 0; i < argc; ++i) 237 for (int i = 0; i < argc; ++i)
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 // The wrapper may have embedded arguments (like "gdb --args"). In this case, 415 // The wrapper may have embedded arguments (like "gdb --args"). In this case,
416 // we don't pretend to do anything fancy, we just split on spaces. 416 // we don't pretend to do anything fancy, we just split on spaces.
417 StringVector wrapper_argv; 417 StringVector wrapper_argv;
418 SplitString(wrapper, FILE_PATH_LITERAL(' '), &wrapper_argv); 418 SplitString(wrapper, FILE_PATH_LITERAL(' '), &wrapper_argv);
419 // Prepend the wrapper and update the switches/arguments |begin_args_|. 419 // Prepend the wrapper and update the switches/arguments |begin_args_|.
420 argv_.insert(argv_.begin(), wrapper_argv.begin(), wrapper_argv.end()); 420 argv_.insert(argv_.begin(), wrapper_argv.begin(), wrapper_argv.end());
421 begin_args_ += wrapper_argv.size(); 421 begin_args_ += wrapper_argv.size();
422 } 422 }
423 423
424 #if defined(OS_WIN) 424 #if defined(OS_WIN)
425 void CommandLine::ParseFromString(const std::wstring& command_line) { 425 void CommandLine::ParseFromString(const base::string16& command_line) {
426 std::wstring command_line_string; 426 base::string16 command_line_string;
427 TrimWhitespace(command_line, TRIM_ALL, &command_line_string); 427 TrimWhitespace(command_line, TRIM_ALL, &command_line_string);
428 if (command_line_string.empty()) 428 if (command_line_string.empty())
429 return; 429 return;
430 430
431 int num_args = 0; 431 int num_args = 0;
432 wchar_t** args = NULL; 432 wchar_t** args = NULL;
433 args = ::CommandLineToArgvW(command_line_string.c_str(), &num_args); 433 args = ::CommandLineToArgvW(command_line_string.c_str(), &num_args);
434 434
435 DPLOG_IF(FATAL, !args) << "CommandLineToArgvW failed on command line: " 435 DPLOG_IF(FATAL, !args) << "CommandLineToArgvW failed on command line: "
436 << UTF16ToUTF8(command_line); 436 << UTF16ToUTF8(command_line);
437 InitFromArgv(num_args, args); 437 InitFromArgv(num_args, args);
438 LocalFree(args); 438 LocalFree(args);
439 } 439 }
440 #endif 440 #endif
441 441
442 } // namespace base 442 } // 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