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

Unified Diff: base/command_line.cc

Issue 3012021: CommandLine: add a CopySwitchesFrom() for copying from another CommandLine (Closed)
Patch Set: minor cleanups Created 10 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/command_line.h ('k') | chrome/browser/browser_main.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/command_line.cc
diff --git a/base/command_line.cc b/base/command_line.cc
index b11902bc11f055de77429c26b4a2bc0988bcaf5c..19f508a6e3cfe7d271c934d6c41d6887dd70ce0b 100644
--- a/base/command_line.cc
+++ b/base/command_line.cc
@@ -291,10 +291,10 @@ std::string CommandLine::GetSwitchValueASCII(
FilePath CommandLine::GetSwitchValuePath(
const std::string& switch_string) const {
- return FilePath::FromWStringHack(GetSwitchValue(switch_string));
+ return FilePath(GetSwitchValueNative(switch_string));
}
-std::wstring CommandLine::GetSwitchValue(
+CommandLine::StringType CommandLine::GetSwitchValueNative(
const std::string& switch_string) const {
std::string lowercased_switch(switch_string);
#if defined(OS_WIN)
@@ -305,18 +305,26 @@ std::wstring CommandLine::GetSwitchValue(
switches_.find(lowercased_switch);
if (result == switches_.end()) {
- return L"";
+ return CommandLine::StringType();
} else {
-#if defined(OS_WIN)
return result->second;
+ }
+}
+
+std::wstring CommandLine::GetSwitchValue(
+ const std::string& switch_string) const {
+ // TODO(evanm): deprecate.
+ CommandLine::StringType value = GetSwitchValueNative(switch_string);
+#if defined(OS_WIN)
+ return value;
#else
- return base::SysNativeMBToWide(result->second);
+ return base::SysNativeMBToWide(value);
#endif
- }
}
std::wstring CommandLine::GetSwitchValue(
const std::wstring& switch_string) const {
+ // TODO(evanm): deprecate.
return GetSwitchValue(WideToASCII(switch_string));
}
@@ -377,6 +385,11 @@ void CommandLine::AppendSwitch(const std::string& switch_string) {
void CommandLine::AppendSwitchWithValue(const std::string& switch_string,
const std::wstring& value_string) {
+ AppendSwitchNative(switch_string, value_string);
+}
+
+void CommandLine::AppendSwitchNative(const std::string& switch_string,
+ const std::wstring& value_string) {
std::wstring value_string_edit;
// NOTE(jhughes): If the value contains a quotation mark at one
@@ -433,13 +446,18 @@ void CommandLine::AppendSwitch(const std::string& switch_string) {
switches_[switch_string] = "";
}
+void CommandLine::AppendSwitchNative(const std::string& switch_string,
+ const std::string& value) {
+ argv_.push_back(kSwitchPrefixes[0] + switch_string +
+ kSwitchValueSeparator + value);
+ switches_[switch_string] = value;
+}
+
void CommandLine::AppendSwitchWithValue(const std::string& switch_string,
const std::wstring& value_string) {
+ // TODO(evanm): deprecate.
std::string mb_value = base::SysWideToNativeMB(value_string);
-
- argv_.push_back(kSwitchPrefixes[0] + switch_string +
- kSwitchValueSeparator + mb_value);
- switches_[switch_string] = mb_value;
+ AppendSwitchNative(switch_string, mb_value);
}
void CommandLine::AppendLooseValue(const std::wstring& value) {
@@ -470,11 +488,27 @@ void CommandLine::PrependWrapper(const std::wstring& wrapper_wide) {
#endif
+void CommandLine::AppendSwitchPath(const std::string& switch_string,
+ const FilePath& path) {
+ AppendSwitchNative(switch_string, path.value());
+}
+
void CommandLine::AppendSwitchWithValue(const std::string& switch_string,
const std::string& value_string) {
AppendSwitchWithValue(switch_string, ASCIIToWide(value_string));
}
+void CommandLine::CopySwitchesFrom(const CommandLine& source,
+ const char* const switches[],
+ size_t count) {
+ for (size_t i = 0; i < count; ++i) {
+ if (source.HasSwitch(switches[i])) {
+ StringType value = source.GetSwitchValueNative(switches[i]);
+ AppendSwitchNative(switches[i], value);
+ }
+ }
+}
+
// private
CommandLine::CommandLine() {
}
« no previous file with comments | « base/command_line.h ('k') | chrome/browser/browser_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698