diff --git a/src/option_types.hh b/src/option_types.hh index 1a2fda97..3c430ca1 100644 --- a/src/option_types.hh +++ b/src/option_types.hh @@ -62,22 +62,15 @@ constexpr char list_separator = ':'; template String option_to_string(const Vector& opt) { - String res; - for (size_t i = 0; i < opt.size(); ++i) - { - res += escape(option_to_string(opt[i]), list_separator, '\\'); - if (i != opt.size() - 1) - res += list_separator; - } - return res; + return join(opt | transform([](const T& t) { return option_to_string(t); }), + list_separator); } template void option_from_string(StringView str, Vector& opt) { opt.clear(); - Vector elems = split(str, list_separator, '\\'); - for (auto& elem: elems) + for (auto& elem : split(str, list_separator, '\\')) { T opt_elem; option_from_string(elem, opt_elem); @@ -90,9 +83,9 @@ bool option_add(Vector& opt, StringView str) { Vector vec; option_from_string(str, vec); - std::copy(std::make_move_iterator(vec.begin()), - std::make_move_iterator(vec.end()), - back_inserter(opt)); + opt.insert(opt.end(), + std::make_move_iterator(vec.begin()), + std::make_move_iterator(vec.end())); return not vec.empty(); } diff --git a/src/string.cc b/src/string.cc index 6fb64098..36beca1e 100644 --- a/src/string.cc +++ b/src/string.cc @@ -222,9 +222,10 @@ String escape(StringView str, StringView characters, char escape) { String res; res.reserve(str.length()); + auto cbeg = characters.begin(), cend = characters.end(); for (auto it = str.begin(), end = str.end(); it != end; ) { - auto next = std::find_if(it, end, [&characters](char c) { return contains(characters, c); }); + auto next = std::find_first_of(it, end, cbeg, cend); if (next != end) { res += StringView{it, next+1};