Andrew de los Reyes | 785bc35 | 2010-05-26 12:34:53 -0700 | [diff] [blame^] | 1 | // Copyright (c) 2010 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 "update_engine/simple_key_value_store.h" |
| 6 | #include <map> |
| 7 | #include <string> |
| 8 | #include <vector> |
| 9 | #include "base/string_util.h" |
| 10 | |
| 11 | using std::map; |
| 12 | using std::string; |
| 13 | using std::vector; |
| 14 | |
| 15 | namespace chromeos_update_engine { |
| 16 | namespace simple_key_value_store { |
| 17 | |
| 18 | // Parses a string. |
| 19 | map<std::string, std::string> ParseString(const string& str) { |
| 20 | // Split along '\n', then along '=' |
| 21 | std::map<std::string, std::string> ret; |
| 22 | vector<string> lines; |
| 23 | SplitStringDontTrim(str, '\n', &lines); |
| 24 | for (vector<string>::const_iterator it = lines.begin(); |
| 25 | it != lines.end(); ++it) { |
| 26 | string::size_type pos = it->find('='); |
| 27 | if (pos == string::npos) |
| 28 | continue; |
| 29 | ret[it->substr(0, pos)] = it->substr(pos + 1); |
| 30 | } |
| 31 | return ret; |
| 32 | } |
| 33 | |
| 34 | string AssembleString(const std::map<string, string>& data) { |
| 35 | string ret; |
| 36 | for (std::map<string, string>::const_iterator it = data.begin(); |
| 37 | it != data.end(); ++it) { |
| 38 | ret += it->first; |
| 39 | ret += "="; |
| 40 | ret += it->second; |
| 41 | ret += "\n"; |
| 42 | } |
| 43 | return ret; |
| 44 | } |
| 45 | |
| 46 | } // namespace simple_key_value_store |
| 47 | } // namespace chromeos_update_engine |