diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-10-16 00:10:56 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-10-16 00:10:56 +0100 |
| commit | 5428006e97b37d757a03c14024d7a0fb363bdcc6 (patch) | |
| tree | 6526477293153aae8b2a6174cd017b332fe99558 /src/lib/util.cc | |
| parent | 63b7da59cee71ab2ade744a8b547b5d8f2ff6bfc (diff) | |
Factor out key-value code.
Diffstat (limited to 'src/lib/util.cc')
| -rw-r--r-- | src/lib/util.cc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc index fbe77461e..a14db810f 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -621,3 +621,32 @@ round_up (int a, int t) return a - (a % t); } +multimap<string, string> +read_key_value (istream &s) +{ + multimap<string, string> kv; + + string line; + while (getline (s, line)) { + if (line.empty ()) { + continue; + } + + if (line[0] == '#') { + continue; + } + + if (line[line.size() - 1] == '\r') { + line = line.substr (0, line.size() - 1); + } + + size_t const s = line.find (' '); + if (s == string::npos) { + continue; + } + + kv.insert (make_pair (line.substr (0, s), line.substr (s + 1))); + } + + return kv; +} |
