Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_CHROMEOS_NAME_VALUE_PAIRS_PARSER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_NAME_VALUE_PAIRS_PARSER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <map> | |
| 10 #include <string> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/basictypes.h" | |
| 14 | |
| 15 namespace chromeos { | |
| 16 | |
| 17 // Machine information is represented as a key-value map. | |
| 18 typedef std::map<std::string, std::string> MachineInfo; | |
|
stevenjb
2011/04/25 17:07:33
Now that we are abstracting this, we should rename
Dmitry Polukhin
2011/04/25 18:50:00
Done.
| |
| 19 | |
| 20 // The parser is used to get machine info as name-value pairs. Defined | |
| 21 // here to be accessable by tests. | |
| 22 class NameValuePairsParser { | |
| 23 public: | |
| 24 typedef std::vector<std::pair<std::string, std::string> > NameValuePairs; | |
| 25 | |
| 26 // The obtained machine info will be written into machine_info. | |
| 27 explicit NameValuePairsParser(MachineInfo* machine_info); | |
| 28 | |
| 29 void AddNameValuePair(const std::string& key, const std::string& value); | |
| 30 | |
| 31 // Executes tool and inserts (key, <output>) into name_value_pairs_. | |
| 32 bool GetSingleValueFromTool(int argc, const char* argv[], | |
| 33 const std::string& key); | |
| 34 // Executes tool, parses the output using ParseNameValuePairs, | |
| 35 // and inserts the results into name_value_pairs_. | |
| 36 bool ParseNameValuePairsFromTool(int argc, const char* argv[], | |
| 37 const std::string& eq, | |
| 38 const std::string& delim); | |
| 39 | |
| 40 private: | |
| 41 // This will parse strings with output in the format: | |
| 42 // <key><EQ><value><DELIM>[<key><EQ><value>][...] | |
| 43 // e.g. ParseNameValuePairs("key1=value1 key2=value2", "=", " ") | |
| 44 bool ParseNameValuePairs(const std::string& in_string, | |
| 45 const std::string& eq, | |
| 46 const std::string& delim); | |
| 47 | |
| 48 MachineInfo* machine_info_; | |
| 49 | |
| 50 DISALLOW_COPY_AND_ASSIGN(NameValuePairsParser); | |
| 51 }; | |
| 52 | |
| 53 } // namespace chromeos | |
| 54 | |
| 55 #endif // CHROME_BROWSER_CHROMEOS_NAME_VALUE_PAIRS_PARSER_H_ | |
| OLD | NEW |