blob: 0315045a99dc4f51b936c8410d4ddcf46f2f558a [file] [log] [blame]
Andrew de los Reyes785bc352010-05-26 12:34:53 -07001// 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
11using std::map;
12using std::string;
13using std::vector;
14
15namespace chromeos_update_engine {
16namespace simple_key_value_store {
17
18// Parses a string.
19map<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
34string 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