Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Side by Side Diff: src/platform/update_engine/simple_key_value_store.cc

Issue 2105016: AU: Common code to parse simple key/value store files (Closed) Base URL: ssh://git@chromiumos-git/chromeos
Patch Set: Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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, it->size());
davidjames 2010/05/21 21:40:53 Do you mean just 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
OLDNEW
« no previous file with comments | « src/platform/update_engine/simple_key_value_store.h ('k') | src/platform/update_engine/simple_key_value_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698