OLD | NEW |
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 *switch_value = string.substr(equals_position + 1); | 68 *switch_value = string.substr(equals_position + 1); |
69 return true; | 69 return true; |
70 } | 70 } |
71 | 71 |
72 // Append switches and arguments, keeping switches before arguments. | 72 // Append switches and arguments, keeping switches before arguments. |
73 void AppendSwitchesAndArguments(CommandLine* command_line, | 73 void AppendSwitchesAndArguments(CommandLine* command_line, |
74 const CommandLine::StringVector& argv) { | 74 const CommandLine::StringVector& argv) { |
75 bool parse_switches = true; | 75 bool parse_switches = true; |
76 for (size_t i = 1; i < argv.size(); ++i) { | 76 for (size_t i = 1; i < argv.size(); ++i) { |
77 CommandLine::StringType arg = argv[i]; | 77 CommandLine::StringType arg = argv[i]; |
| 78 #if defined(OS_WIN) |
78 TrimWhitespace(arg, TRIM_ALL, &arg); | 79 TrimWhitespace(arg, TRIM_ALL, &arg); |
| 80 #else |
| 81 TrimWhitespaceASCII(arg, TRIM_ALL, &arg); |
| 82 #endif |
79 | 83 |
80 CommandLine::StringType switch_string; | 84 CommandLine::StringType switch_string; |
81 CommandLine::StringType switch_value; | 85 CommandLine::StringType switch_value; |
82 parse_switches &= (arg != kSwitchTerminator); | 86 parse_switches &= (arg != kSwitchTerminator); |
83 if (parse_switches && IsSwitch(arg, &switch_string, &switch_value)) { | 87 if (parse_switches && IsSwitch(arg, &switch_string, &switch_value)) { |
84 #if defined(OS_WIN) | 88 #if defined(OS_WIN) |
85 command_line->AppendSwitchNative(UTF16ToASCII(switch_string), | 89 command_line->AppendSwitchNative(UTF16ToASCII(switch_string), |
86 switch_value); | 90 switch_value); |
87 #elif defined(OS_POSIX) | 91 #elif defined(OS_POSIX) |
88 command_line->AppendSwitchNative(switch_string, switch_value); | 92 command_line->AppendSwitchNative(switch_string, switch_value); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 begin_args_ = 1; | 260 begin_args_ = 1; |
257 SetProgram(argv.empty() ? FilePath() : FilePath(argv[0])); | 261 SetProgram(argv.empty() ? FilePath() : FilePath(argv[0])); |
258 AppendSwitchesAndArguments(this, argv); | 262 AppendSwitchesAndArguments(this, argv); |
259 } | 263 } |
260 | 264 |
261 FilePath CommandLine::GetProgram() const { | 265 FilePath CommandLine::GetProgram() const { |
262 return FilePath(argv_[0]); | 266 return FilePath(argv_[0]); |
263 } | 267 } |
264 | 268 |
265 void CommandLine::SetProgram(const FilePath& program) { | 269 void CommandLine::SetProgram(const FilePath& program) { |
| 270 #if defined(OS_WIN) |
266 TrimWhitespace(program.value(), TRIM_ALL, &argv_[0]); | 271 TrimWhitespace(program.value(), TRIM_ALL, &argv_[0]); |
| 272 #else |
| 273 TrimWhitespaceASCII(program.value(), TRIM_ALL, &argv_[0]); |
| 274 #endif |
267 } | 275 } |
268 | 276 |
269 bool CommandLine::HasSwitch(const base::StringPiece& switch_string) const { | 277 bool CommandLine::HasSwitch(const base::StringPiece& switch_string) const { |
270 DCHECK_EQ(ToLowerASCII(switch_string), switch_string); | 278 DCHECK_EQ(ToLowerASCII(switch_string), switch_string); |
271 return switches_by_stringpiece_.find(switch_string) != | 279 return switches_by_stringpiece_.find(switch_string) != |
272 switches_by_stringpiece_.end(); | 280 switches_by_stringpiece_.end(); |
273 } | 281 } |
274 | 282 |
275 bool CommandLine::HasSwitch(const char switch_constant[]) const { | 283 bool CommandLine::HasSwitch(const char switch_constant[]) const { |
276 return HasSwitch(base::StringPiece(switch_constant)); | 284 return HasSwitch(base::StringPiece(switch_constant)); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 return params; | 473 return params; |
466 } | 474 } |
467 | 475 |
468 void CommandLine::ResetStringPieces() { | 476 void CommandLine::ResetStringPieces() { |
469 switches_by_stringpiece_.clear(); | 477 switches_by_stringpiece_.clear(); |
470 for (const auto& entry : switches_) | 478 for (const auto& entry : switches_) |
471 switches_by_stringpiece_[entry.first] = &(entry.second); | 479 switches_by_stringpiece_[entry.first] = &(entry.second); |
472 } | 480 } |
473 | 481 |
474 } // namespace base | 482 } // namespace base |
OLD | NEW |