| 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/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 const CommandLine::CharType kSwitchTerminator[] = FILE_PATH_LITERAL("--"); | 29 const CommandLine::CharType kSwitchTerminator[] = FILE_PATH_LITERAL("--"); |
| 30 const CommandLine::CharType kSwitchValueSeparator[] = FILE_PATH_LITERAL("="); | 30 const CommandLine::CharType kSwitchValueSeparator[] = FILE_PATH_LITERAL("="); |
| 31 | 31 |
| 32 // Since we use a lazy match, make sure that longer versions (like "--") are | 32 // Since we use a lazy match, make sure that longer versions (like "--") are |
| 33 // listed before shorter versions (like "-") of similar prefixes. | 33 // listed before shorter versions (like "-") of similar prefixes. |
| 34 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
| 35 // By putting slash last, we can control whether it is treaded as a switch | 35 // By putting slash last, we can control whether it is treaded as a switch |
| 36 // value by changing the value of switch_prefix_count to be one less than | 36 // value by changing the value of switch_prefix_count to be one less than |
| 37 // the array size. | 37 // the array size. |
| 38 const CommandLine::CharType* const kSwitchPrefixes[] = {L"--", L"-", L"/"}; | 38 const CommandLine::CharType* const kSwitchPrefixes[] = {L"--", L"-", L"/"}; |
| 39 #elif defined(OS_POSIX) | 39 #elif defined(OS_POSIX) || defined(OS_FUCHSIA) |
| 40 // Unixes don't use slash as a switch. | 40 // Unixes don't use slash as a switch. |
| 41 const CommandLine::CharType* const kSwitchPrefixes[] = {"--", "-"}; | 41 const CommandLine::CharType* const kSwitchPrefixes[] = {"--", "-"}; |
| 42 #endif | 42 #endif |
| 43 size_t switch_prefix_count = arraysize(kSwitchPrefixes); | 43 size_t switch_prefix_count = arraysize(kSwitchPrefixes); |
| 44 | 44 |
| 45 size_t GetSwitchPrefixLength(const CommandLine::StringType& string) { | 45 size_t GetSwitchPrefixLength(const CommandLine::StringType& string) { |
| 46 for (size_t i = 0; i < switch_prefix_count; ++i) { | 46 for (size_t i = 0; i < switch_prefix_count; ++i) { |
| 47 CommandLine::StringType prefix(kSwitchPrefixes[i]); | 47 CommandLine::StringType prefix(kSwitchPrefixes[i]); |
| 48 if (string.compare(0, prefix.length(), prefix) == 0) | 48 if (string.compare(0, prefix.length(), prefix) == 0) |
| 49 return prefix.length(); | 49 return prefix.length(); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 void CommandLine::AppendSwitchPath(const std::string& switch_string, | 329 void CommandLine::AppendSwitchPath(const std::string& switch_string, |
| 330 const FilePath& path) { | 330 const FilePath& path) { |
| 331 AppendSwitchNative(switch_string, path.value()); | 331 AppendSwitchNative(switch_string, path.value()); |
| 332 } | 332 } |
| 333 | 333 |
| 334 void CommandLine::AppendSwitchNative(const std::string& switch_string, | 334 void CommandLine::AppendSwitchNative(const std::string& switch_string, |
| 335 const CommandLine::StringType& value) { | 335 const CommandLine::StringType& value) { |
| 336 #if defined(OS_WIN) | 336 #if defined(OS_WIN) |
| 337 const std::string switch_key = ToLowerASCII(switch_string); | 337 const std::string switch_key = ToLowerASCII(switch_string); |
| 338 StringType combined_switch_string(ASCIIToUTF16(switch_key)); | 338 StringType combined_switch_string(ASCIIToUTF16(switch_key)); |
| 339 #elif defined(OS_POSIX) | 339 #elif defined(OS_POSIX) || defined(OS_FUCHSIA) |
| 340 const std::string& switch_key = switch_string; | 340 const std::string& switch_key = switch_string; |
| 341 StringType combined_switch_string(switch_key); | 341 StringType combined_switch_string(switch_key); |
| 342 #endif | 342 #endif |
| 343 size_t prefix_length = GetSwitchPrefixLength(combined_switch_string); | 343 size_t prefix_length = GetSwitchPrefixLength(combined_switch_string); |
| 344 auto insertion = | 344 auto insertion = |
| 345 switches_.insert(make_pair(switch_key.substr(prefix_length), value)); | 345 switches_.insert(make_pair(switch_key.substr(prefix_length), value)); |
| 346 if (!insertion.second) | 346 if (!insertion.second) |
| 347 insertion.first->second = value; | 347 insertion.first->second = value; |
| 348 switches_by_stringpiece_[insertion.first->first] = &(insertion.first->second); | 348 switches_by_stringpiece_[insertion.first->first] = &(insertion.first->second); |
| 349 // Preserve existing switch prefixes in |argv_|; only append one if necessary. | 349 // Preserve existing switch prefixes in |argv_|; only append one if necessary. |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 return params; | 484 return params; |
| 485 } | 485 } |
| 486 | 486 |
| 487 void CommandLine::ResetStringPieces() { | 487 void CommandLine::ResetStringPieces() { |
| 488 switches_by_stringpiece_.clear(); | 488 switches_by_stringpiece_.clear(); |
| 489 for (const auto& entry : switches_) | 489 for (const auto& entry : switches_) |
| 490 switches_by_stringpiece_[entry.first] = &(entry.second); | 490 switches_by_stringpiece_[entry.first] = &(entry.second); |
| 491 } | 491 } |
| 492 | 492 |
| 493 } // namespace base | 493 } // namespace base |
| OLD | NEW |