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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 260 |
261 FilePath CommandLine::GetProgram() const { | 261 FilePath CommandLine::GetProgram() const { |
262 return FilePath(argv_[0]); | 262 return FilePath(argv_[0]); |
263 } | 263 } |
264 | 264 |
265 void CommandLine::SetProgram(const FilePath& program) { | 265 void CommandLine::SetProgram(const FilePath& program) { |
266 TrimWhitespace(program.value(), TRIM_ALL, &argv_[0]); | 266 TrimWhitespace(program.value(), TRIM_ALL, &argv_[0]); |
267 } | 267 } |
268 | 268 |
269 bool CommandLine::HasSwitch(const base::StringPiece& switch_string) const { | 269 bool CommandLine::HasSwitch(const base::StringPiece& switch_string) const { |
270 DCHECK_EQ(StringToLowerASCII(switch_string.as_string()), switch_string); | 270 DCHECK_EQ(ToLowerASCII(switch_string), switch_string); |
271 return switches_by_stringpiece_.find(switch_string) != | 271 return switches_by_stringpiece_.find(switch_string) != |
272 switches_by_stringpiece_.end(); | 272 switches_by_stringpiece_.end(); |
273 } | 273 } |
274 | 274 |
275 bool CommandLine::HasSwitch(const char switch_constant[]) const { | 275 bool CommandLine::HasSwitch(const char switch_constant[]) const { |
276 return HasSwitch(base::StringPiece(switch_constant)); | 276 return HasSwitch(base::StringPiece(switch_constant)); |
277 } | 277 } |
278 | 278 |
279 std::string CommandLine::GetSwitchValueASCII( | 279 std::string CommandLine::GetSwitchValueASCII( |
280 const base::StringPiece& switch_string) const { | 280 const base::StringPiece& switch_string) const { |
281 StringType value = GetSwitchValueNative(switch_string); | 281 StringType value = GetSwitchValueNative(switch_string); |
282 if (!IsStringASCII(value)) { | 282 if (!IsStringASCII(value)) { |
283 DLOG(WARNING) << "Value of switch (" << switch_string << ") must be ASCII."; | 283 DLOG(WARNING) << "Value of switch (" << switch_string << ") must be ASCII."; |
284 return std::string(); | 284 return std::string(); |
285 } | 285 } |
286 #if defined(OS_WIN) | 286 #if defined(OS_WIN) |
287 return UTF16ToASCII(value); | 287 return UTF16ToASCII(value); |
288 #else | 288 #else |
289 return value; | 289 return value; |
290 #endif | 290 #endif |
291 } | 291 } |
292 | 292 |
293 FilePath CommandLine::GetSwitchValuePath( | 293 FilePath CommandLine::GetSwitchValuePath( |
294 const base::StringPiece& switch_string) const { | 294 const base::StringPiece& switch_string) const { |
295 return FilePath(GetSwitchValueNative(switch_string)); | 295 return FilePath(GetSwitchValueNative(switch_string)); |
296 } | 296 } |
297 | 297 |
298 CommandLine::StringType CommandLine::GetSwitchValueNative( | 298 CommandLine::StringType CommandLine::GetSwitchValueNative( |
299 const base::StringPiece& switch_string) const { | 299 const base::StringPiece& switch_string) const { |
300 DCHECK_EQ(StringToLowerASCII(switch_string.as_string()), switch_string); | 300 DCHECK_EQ(ToLowerASCII(switch_string), switch_string); |
301 auto result = switches_by_stringpiece_.find(switch_string); | 301 auto result = switches_by_stringpiece_.find(switch_string); |
302 return result == switches_by_stringpiece_.end() ? StringType() | 302 return result == switches_by_stringpiece_.end() ? StringType() |
303 : *(result->second); | 303 : *(result->second); |
304 } | 304 } |
305 | 305 |
306 void CommandLine::AppendSwitch(const std::string& switch_string) { | 306 void CommandLine::AppendSwitch(const std::string& switch_string) { |
307 AppendSwitchNative(switch_string, StringType()); | 307 AppendSwitchNative(switch_string, StringType()); |
308 } | 308 } |
309 | 309 |
310 void CommandLine::AppendSwitchPath(const std::string& switch_string, | 310 void CommandLine::AppendSwitchPath(const std::string& switch_string, |
311 const FilePath& path) { | 311 const FilePath& path) { |
312 AppendSwitchNative(switch_string, path.value()); | 312 AppendSwitchNative(switch_string, path.value()); |
313 } | 313 } |
314 | 314 |
315 void CommandLine::AppendSwitchNative(const std::string& switch_string, | 315 void CommandLine::AppendSwitchNative(const std::string& switch_string, |
316 const CommandLine::StringType& value) { | 316 const CommandLine::StringType& value) { |
317 #if defined(OS_WIN) | 317 #if defined(OS_WIN) |
318 const std::string switch_key = StringToLowerASCII(switch_string); | 318 const std::string switch_key = ToLowerASCII(switch_string); |
319 StringType combined_switch_string(ASCIIToUTF16(switch_key)); | 319 StringType combined_switch_string(ASCIIToUTF16(switch_key)); |
320 #elif defined(OS_POSIX) | 320 #elif defined(OS_POSIX) |
321 const std::string& switch_key = switch_string; | 321 const std::string& switch_key = switch_string; |
322 StringType combined_switch_string(switch_key); | 322 StringType combined_switch_string(switch_key); |
323 #endif | 323 #endif |
324 size_t prefix_length = GetSwitchPrefixLength(combined_switch_string); | 324 size_t prefix_length = GetSwitchPrefixLength(combined_switch_string); |
325 auto insertion = | 325 auto insertion = |
326 switches_.insert(make_pair(switch_key.substr(prefix_length), value)); | 326 switches_.insert(make_pair(switch_key.substr(prefix_length), value)); |
327 if (!insertion.second) | 327 if (!insertion.second) |
328 insertion.first->second = value; | 328 insertion.first->second = value; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 return params; | 465 return params; |
466 } | 466 } |
467 | 467 |
468 void CommandLine::ResetStringPieces() { | 468 void CommandLine::ResetStringPieces() { |
469 switches_by_stringpiece_.clear(); | 469 switches_by_stringpiece_.clear(); |
470 for (const auto& entry : switches_) | 470 for (const auto& entry : switches_) |
471 switches_by_stringpiece_[entry.first] = &(entry.second); | 471 switches_by_stringpiece_[entry.first] = &(entry.second); |
472 } | 472 } |
473 | 473 |
474 } // namespace base | 474 } // namespace base |
OLD | NEW |