 Chromium Code Reviews
 Chromium Code Reviews Issue 2105016:
  AU: Common code to parse simple key/value store files  (Closed) 
  Base URL: ssh://git@chromiumos-git/chromeos
    
  
    Issue 2105016:
  AU: Common code to parse simple key/value store files  (Closed) 
  Base URL: ssh://git@chromiumos-git/chromeos| 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 |