Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chromeos/dbus/dbus_command_line_helper.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/strings/string_split.h" | |
| 10 #include "base/strings/string_util.h" | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 bool GetOptionArgs(const std::string& option, | |
| 15 std::string* arg0, | |
| 16 std::string* arg1) { | |
| 17 arg0->clear(); | |
| 18 arg1->clear(); | |
| 19 std::vector<std::string> args; | |
| 20 base::SplitString(option, '=', &args); | |
| 21 if (args.size() < 1) { | |
| 22 LOG(WARNING) << " Invalid option: " << option; | |
| 23 return false; | |
| 24 } | |
| 25 *arg0 = args[0]; | |
| 26 if (args.size() >= 2) | |
| 27 *arg1 = args[1]; | |
| 28 VLOG(2) << " Option: " << *arg0 << " = " << *arg1; | |
| 29 return true; | |
| 30 } | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 34 namespace dbus_command_line_helper { | |
| 35 | |
| 36 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
| |
| 37 const ParseOptionCallback& callback) { | |
| 38 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 39 if (!command_line->HasSwitch(switch_name)) | |
| 40 return false; | |
| 41 | |
| 42 std::string option_str = command_line->GetSwitchValueASCII(switch_name); | |
| 43 VLOG(1) << "ParseOption: " << option_str; | |
| 44 std::vector<std::string> tokens; | |
| 45 base::SplitString(option_str, ',', &tokens); | |
| 46 for (std::vector<std::string>::iterator iter = tokens.begin(); | |
| 47 iter != tokens.end(); ++iter) { | |
| 48 std::string arg0, arg1; | |
| 49 if (!GetOptionArgs(*iter, &arg0, &arg1)) | |
| 50 continue; | |
| 51 if (!callback.Run(arg0, arg1)) | |
| 52 LOG(WARNING) << "Unrecognized option: " << *iter; | |
| 53 } | |
| 54 return true; | |
| 55 } | |
| 56 | |
| 57 } // namespace dbus_command_line_helper | |
| OLD | NEW |