aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/config.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-10-12 23:00:18 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-10-12 23:00:18 +0000
commitbdc772022766e65fa8ea6d29fff0735529ab47f3 (patch)
treed12a08d6a29d929fb646571e65bbd68bf009f3d4 /src/libutil/config.cc
parent6c7b81047f8ead0bb2f8dd588dfcb5f50d1554a9 (diff)
parent20d2140e450b066a521933dd322d089fd6c248fa (diff)
Merge branch 'master' of github.com:NixOS/nix into trustless-remote-builder-simple
Diffstat (limited to 'src/libutil/config.cc')
-rw-r--r--src/libutil/config.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libutil/config.cc b/src/libutil/config.cc
index 5e6a211df..521733025 100644
--- a/src/libutil/config.cc
+++ b/src/libutil/config.cc
@@ -268,6 +268,26 @@ template<> std::string BaseSetting<StringSet>::to_string() const
return concatStringsSep(" ", value);
}
+template<> void BaseSetting<StringMap>::set(const std::string & str)
+{
+ auto kvpairs = tokenizeString<Strings>(str);
+ for (auto & s : kvpairs)
+ {
+ auto eq = s.find_first_of('=');
+ if (std::string::npos != eq)
+ value.emplace(std::string(s, 0, eq), std::string(s, eq + 1));
+ // else ignored
+ }
+}
+
+template<> std::string BaseSetting<StringMap>::to_string() const
+{
+ Strings kvstrs;
+ std::transform(value.begin(), value.end(), back_inserter(kvstrs),
+ [&](auto kvpair){ return kvpair.first + "=" + kvpair.second; });
+ return concatStringsSep(" ", kvstrs);
+}
+
template class BaseSetting<int>;
template class BaseSetting<unsigned int>;
template class BaseSetting<long>;
@@ -278,6 +298,7 @@ template class BaseSetting<bool>;
template class BaseSetting<std::string>;
template class BaseSetting<Strings>;
template class BaseSetting<StringSet>;
+template class BaseSetting<StringMap>;
void PathSetting::set(const std::string & str)
{