Chromium Code Reviews| Index: chrome/browser/chromeos/name_value_pairs_parser.h |
| diff --git a/chrome/browser/chromeos/name_value_pairs_parser.h b/chrome/browser/chromeos/name_value_pairs_parser.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..49f6ffe910b75dfe3b606b268ac23e93b49261a6 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/name_value_pairs_parser.h |
| @@ -0,0 +1,55 @@ |
| +// Copyright (c) 2011 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. |
| + |
| +#ifndef CHROME_BROWSER_CHROMEOS_NAME_VALUE_PAIRS_PARSER_H_ |
| +#define CHROME_BROWSER_CHROMEOS_NAME_VALUE_PAIRS_PARSER_H_ |
| +#pragma once |
| + |
| +#include <map> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| + |
| +namespace chromeos { |
| + |
| +// Machine information is represented as a key-value map. |
| +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.
|
| + |
| +// The parser is used to get machine info as name-value pairs. Defined |
| +// here to be accessable by tests. |
| +class NameValuePairsParser { |
| + public: |
| + typedef std::vector<std::pair<std::string, std::string> > NameValuePairs; |
| + |
| + // The obtained machine info will be written into machine_info. |
| + explicit NameValuePairsParser(MachineInfo* machine_info); |
| + |
| + void AddNameValuePair(const std::string& key, const std::string& value); |
| + |
| + // Executes tool and inserts (key, <output>) into name_value_pairs_. |
| + bool GetSingleValueFromTool(int argc, const char* argv[], |
| + const std::string& key); |
| + // Executes tool, parses the output using ParseNameValuePairs, |
| + // and inserts the results into name_value_pairs_. |
| + bool ParseNameValuePairsFromTool(int argc, const char* argv[], |
| + const std::string& eq, |
| + const std::string& delim); |
| + |
| + private: |
| + // This will parse strings with output in the format: |
| + // <key><EQ><value><DELIM>[<key><EQ><value>][...] |
| + // e.g. ParseNameValuePairs("key1=value1 key2=value2", "=", " ") |
| + bool ParseNameValuePairs(const std::string& in_string, |
| + const std::string& eq, |
| + const std::string& delim); |
| + |
| + MachineInfo* machine_info_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NameValuePairsParser); |
| +}; |
| + |
| +} // namespace chromeos |
| + |
| +#endif // CHROME_BROWSER_CHROMEOS_NAME_VALUE_PAIRS_PARSER_H_ |