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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: src/platform/update_engine/simple_key_value_store.cc
diff --git a/src/platform/update_engine/simple_key_value_store.cc b/src/platform/update_engine/simple_key_value_store.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b4961cb7497dc2db947ec4140d23389ed973d329
--- /dev/null
+++ b/src/platform/update_engine/simple_key_value_store.cc
@@ -0,0 +1,47 @@
+// Copyright (c) 2010 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.
+
+#include "update_engine/simple_key_value_store.h"
+#include <map>
+#include <string>
+#include <vector>
+#include "base/string_util.h"
+
+using std::map;
+using std::string;
+using std::vector;
+
+namespace chromeos_update_engine {
+namespace simple_key_value_store {
+
+// Parses a string.
+map<std::string, std::string> ParseString(const string& str) {
+ // Split along '\n', then along '='
+ std::map<std::string, std::string> ret;
+ vector<string> lines;
+ SplitStringDontTrim(str, '\n', &lines);
+ for (vector<string>::const_iterator it = lines.begin();
+ it != lines.end(); ++it) {
+ string::size_type pos = it->find('=');
+ if (pos == string::npos)
+ continue;
+ 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)?
+ }
+ return ret;
+}
+
+string AssembleString(const std::map<string, string>& data) {
+ string ret;
+ for (std::map<string, string>::const_iterator it = data.begin();
+ it != data.end(); ++it) {
+ ret += it->first;
+ ret += "=";
+ ret += it->second;
+ ret += "\n";
+ }
+ return ret;
+}
+
+} // namespace simple_key_value_store
+} // namespace chromeos_update_engine
« 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