Index: chromeos/dbus/dbus_command_line_helper.cc |
diff --git a/chromeos/dbus/dbus_command_line_helper.cc b/chromeos/dbus/dbus_command_line_helper.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0174ef4f55c6f8e807d97e06e2e02ff7f8253dce |
--- /dev/null |
+++ b/chromeos/dbus/dbus_command_line_helper.cc |
@@ -0,0 +1,57 @@ |
+// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chromeos/dbus/dbus_command_line_helper.h" |
+ |
+#include "base/command_line.h" |
+#include "base/logging.h" |
+#include "base/strings/string_split.h" |
+#include "base/strings/string_util.h" |
+ |
+namespace { |
+ |
+bool GetOptionArgs(const std::string& option, |
+ std::string* arg0, |
+ std::string* arg1) { |
+ arg0->clear(); |
+ arg1->clear(); |
+ std::vector<std::string> args; |
+ base::SplitString(option, '=', &args); |
+ if (args.size() < 1) { |
+ LOG(WARNING) << " Invalid option: " << option; |
+ return false; |
+ } |
+ *arg0 = args[0]; |
+ if (args.size() >= 2) |
+ *arg1 = args[1]; |
+ VLOG(2) << " Option: " << *arg0 << " = " << *arg1; |
+ return true; |
+} |
+ |
+} // namespace |
+ |
+namespace dbus_command_line_helper { |
+ |
+bool ParseOptions(const std::string& switch_name, |
pneubeck (no reviews)
2014/03/05 18:47:09
If this implementation continues to exist (e.g. in
|
+ const ParseOptionCallback& callback) { |
+ CommandLine* command_line = CommandLine::ForCurrentProcess(); |
+ if (!command_line->HasSwitch(switch_name)) |
+ return false; |
+ |
+ std::string option_str = command_line->GetSwitchValueASCII(switch_name); |
+ VLOG(1) << "ParseOption: " << option_str; |
+ std::vector<std::string> tokens; |
+ base::SplitString(option_str, ',', &tokens); |
+ for (std::vector<std::string>::iterator iter = tokens.begin(); |
+ iter != tokens.end(); ++iter) { |
+ std::string arg0, arg1; |
+ if (!GetOptionArgs(*iter, &arg0, &arg1)) |
+ continue; |
+ if (!callback.Run(arg0, arg1)) |
+ LOG(WARNING) << "Unrecognized option: " << *iter; |
+ } |
+ return true; |
+} |
+ |
+} // namespace dbus_command_line_helper |