Index: base/command_line.cc |
diff --git a/base/command_line.cc b/base/command_line.cc |
index 873da813483651bc9e74b0510e17fa925225b5bd..e5292e34abc3fdb679efcf0fffc7af2d9e0f62e9 100644 |
--- a/base/command_line.cc |
+++ b/base/command_line.cc |
@@ -10,6 +10,7 @@ |
#include "base/files/file_path.h" |
#include "base/logging.h" |
#include "base/macros.h" |
+#include "base/stl_util.h" |
#include "base/strings/string_split.h" |
#include "base/strings/string_tokenizer.h" |
#include "base/strings/string_util.h" |
@@ -148,6 +149,22 @@ string16 QuoteForCommandLineToArgvW(const string16& arg, |
} |
#endif |
+std::string SwitchKey(const std::string& switch_string) { |
Ilya Sherman
2017/06/09 20:19:28
nit: Mebbe "GetSwitchKey"?
|
+#if defined(OS_WIN) |
+ return ToLowerASCII(switch_string); |
+#elif defined(OS_POSIX) |
+ return switch_string; |
+#endif |
+} |
+ |
+CommandLine::StringType CombinedSwitchString(const std::string switch_key) { |
Ilya Sherman
2017/06/09 20:19:28
nit: Mebbe "GetCombinedSwitchString"?
|
+#if defined(OS_WIN) |
+ return ASCIIToUTF16(switch_key); |
+#elif defined(OS_POSIX) |
+ return switch_key; |
+#endif |
+} |
+ |
} // namespace |
CommandLine::CommandLine(NoProgram no_program) |
@@ -334,13 +351,8 @@ void CommandLine::AppendSwitchPath(const std::string& switch_string, |
void CommandLine::AppendSwitchNative(const std::string& switch_string, |
const CommandLine::StringType& value) { |
-#if defined(OS_WIN) |
- const std::string switch_key = ToLowerASCII(switch_string); |
- StringType combined_switch_string(ASCIIToUTF16(switch_key)); |
-#elif defined(OS_POSIX) |
- const std::string& switch_key = switch_string; |
- StringType combined_switch_string(switch_key); |
-#endif |
+ const std::string switch_key = SwitchKey(switch_string); |
+ StringType combined_switch_string = CombinedSwitchString(switch_key); |
size_t prefix_length = GetSwitchPrefixLength(combined_switch_string); |
auto insertion = |
switches_.insert(make_pair(switch_key.substr(prefix_length), value)); |
@@ -365,6 +377,20 @@ void CommandLine::AppendSwitchASCII(const std::string& switch_string, |
#endif |
} |
+void CommandLine::RemoveSwitchForTesting(const std::string& switch_string) { |
+ const std::string switch_key = SwitchKey(switch_string); |
+ StringType combined_switch_string = CombinedSwitchString(switch_key); |
+ size_t prefix_length = GetSwitchPrefixLength(combined_switch_string); |
+ switches_by_stringpiece_.erase(switch_key.substr(prefix_length)); |
+ switches_.erase(switch_string.substr(prefix_length)); |
+ |
+ auto find_switch = [&combined_switch_string](const std::string& s) { |
Ilya Sherman
2017/06/09 20:19:28
nit: What does "s" represent? Please give it a cl
|
+ return s.find(combined_switch_string) != std::string::npos; |
+ }; |
+ |
+ base::EraseIf(argv_, find_switch); |
+} |
+ |
void CommandLine::CopySwitchesFrom(const CommandLine& source, |
const char* const switches[], |
size_t count) { |