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

Side by Side Diff: base/command_line.cc

Issue 3138001: CommandLine: remove PrefixedSwitchString(). (Closed)
Patch Set: works Created 10 years, 4 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') | chrome/browser/jumplist_win.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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 return base::SysNativeMBToWide(argv_[0]); 345 return base::SysNativeMBToWide(argv_[0]);
346 } 346 }
347 #endif 347 #endif
348 348
349 #if defined(OS_POSIX) 349 #if defined(OS_POSIX)
350 std::string CommandLine::command_line_string() const { 350 std::string CommandLine::command_line_string() const {
351 return JoinString(argv_, ' '); 351 return JoinString(argv_, ' ');
352 } 352 }
353 #endif 353 #endif
354 354
355 // static
356 std::wstring CommandLine::PrefixedSwitchString(
357 const std::string& switch_string) {
358 #if defined(OS_WIN)
359 return kSwitchPrefixes[0] + ASCIIToWide(switch_string);
360 #else
361 return ASCIIToWide(kSwitchPrefixes[0] + switch_string);
362 #endif
363 }
364
365 // static
366 std::wstring CommandLine::PrefixedSwitchStringWithValue(
367 const std::string& switch_string, const std::wstring& value_string) {
368 if (value_string.empty()) {
369 return PrefixedSwitchString(switch_string);
370 }
371
372 return PrefixedSwitchString(switch_string +
373 #if defined(OS_WIN)
374 WideToASCII(kSwitchValueSeparator)
375 #else
376 kSwitchValueSeparator
377 #endif
378 ) + value_string;
379 }
380
381 #if defined(OS_WIN) 355 #if defined(OS_WIN)
382 void CommandLine::AppendSwitch(const std::string& switch_string) { 356 void CommandLine::AppendSwitch(const std::string& switch_string) {
383 std::wstring prefixed_switch_string = PrefixedSwitchString(switch_string);
384 command_line_string_.append(L" "); 357 command_line_string_.append(L" ");
385 command_line_string_.append(prefixed_switch_string); 358 command_line_string_.append(kSwitchPrefixes[0] + ASCIIToWide(switch_string));
386 switches_[switch_string] = L""; 359 switches_[switch_string] = L"";
387 } 360 }
388 361
389 void CommandLine::AppendSwitchASCII(const std::string& switch_string, 362 void CommandLine::AppendSwitchASCII(const std::string& switch_string,
390 const std::string& value_string) { 363 const std::string& value_string) {
391 AppendSwitchNative(switch_string, ASCIIToWide(value_string)); 364 AppendSwitchNative(switch_string, ASCIIToWide(value_string));
392 } 365 }
393 366
394 void CommandLine::AppendSwitchNative(const std::string& switch_string, 367 void CommandLine::AppendSwitchNative(const std::string& switch_string,
395 const std::wstring& value_string) { 368 const std::wstring& value_string) {
396 std::wstring value_string_edit; 369 std::wstring value_string_edit;
397 370
398 // NOTE(jhughes): If the value contains a quotation mark at one 371 // NOTE(jhughes): If the value contains a quotation mark at one
399 // end but not both, you may get unusable output. 372 // end but not both, you may get unusable output.
400 if (!value_string.empty() && 373 if (!value_string.empty() &&
401 (value_string.find(L" ") != std::wstring::npos) && 374 (value_string.find(L" ") != std::wstring::npos) &&
402 (value_string[0] != L'"') && 375 (value_string[0] != L'"') &&
403 (value_string[value_string.length() - 1] != L'"')) { 376 (value_string[value_string.length() - 1] != L'"')) {
404 // need to provide quotes 377 // need to provide quotes
405 value_string_edit = StringPrintf(L"\"%ls\"", value_string.c_str()); 378 value_string_edit = StringPrintf(L"\"%ls\"", value_string.c_str());
406 } else { 379 } else {
407 value_string_edit = value_string; 380 value_string_edit = value_string;
408 } 381 }
409 382
410 std::wstring combined_switch_string = 383 std::wstring combined_switch_string =
411 PrefixedSwitchStringWithValue(switch_string, value_string_edit); 384 kSwitchPrefixes[0] + ASCIIToWide(switch_string);
385 if (!value_string_edit.empty())
386 combined_switch_string += kSwitchValueSeparator + value_string_edit;
412 387
413 command_line_string_.append(L" "); 388 command_line_string_.append(L" ");
414 command_line_string_.append(combined_switch_string); 389 command_line_string_.append(combined_switch_string);
415 390
416 switches_[switch_string] = value_string; 391 switches_[switch_string] = value_string;
417 } 392 }
418 393
419 void CommandLine::AppendLooseValue(const std::wstring& value) { 394 void CommandLine::AppendLooseValue(const std::wstring& value) {
420 // TODO(evan): quoting? 395 // TODO(evan): quoting?
421 command_line_string_.append(L" "); 396 command_line_string_.append(L" ");
(...skipping 24 matching lines...) Expand all
446 } 421 }
447 422
448 #elif defined(OS_POSIX) 423 #elif defined(OS_POSIX)
449 void CommandLine::AppendSwitch(const std::string& switch_string) { 424 void CommandLine::AppendSwitch(const std::string& switch_string) {
450 argv_.push_back(kSwitchPrefixes[0] + switch_string); 425 argv_.push_back(kSwitchPrefixes[0] + switch_string);
451 switches_[switch_string] = ""; 426 switches_[switch_string] = "";
452 } 427 }
453 428
454 void CommandLine::AppendSwitchNative(const std::string& switch_string, 429 void CommandLine::AppendSwitchNative(const std::string& switch_string,
455 const std::string& value) { 430 const std::string& value) {
456 argv_.push_back(kSwitchPrefixes[0] + switch_string + 431 std::string combined_switch_string = kSwitchPrefixes[0] + switch_string;
457 kSwitchValueSeparator + value); 432 if (!value.empty())
433 combined_switch_string += kSwitchValueSeparator + value;
434 argv_.push_back(combined_switch_string);
458 switches_[switch_string] = value; 435 switches_[switch_string] = value;
459 } 436 }
460 437
461 void CommandLine::AppendSwitchASCII(const std::string& switch_string, 438 void CommandLine::AppendSwitchASCII(const std::string& switch_string,
462 const std::string& value_string) { 439 const std::string& value_string) {
463 AppendSwitchNative(switch_string, value_string); 440 AppendSwitchNative(switch_string, value_string);
464 } 441 }
465 442
466 void CommandLine::AppendLooseValue(const std::wstring& value) { 443 void CommandLine::AppendLooseValue(const std::wstring& value) {
467 argv_.push_back(base::SysWideToNativeMB(value)); 444 argv_.push_back(base::SysWideToNativeMB(value));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 if (source.HasSwitch(switches[i])) { 479 if (source.HasSwitch(switches[i])) {
503 StringType value = source.GetSwitchValueNative(switches[i]); 480 StringType value = source.GetSwitchValueNative(switches[i]);
504 AppendSwitchNative(switches[i], value); 481 AppendSwitchNative(switches[i], value);
505 } 482 }
506 } 483 }
507 } 484 }
508 485
509 // private 486 // private
510 CommandLine::CommandLine() { 487 CommandLine::CommandLine() {
511 } 488 }
OLDNEW
« no previous file with comments | « base/command_line.h ('k') | chrome/browser/jumplist_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698