From d29fb6f2c48e13e119c86db6bb152e0373c49377 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 24 Jul 2013 22:41:13 +0200 Subject: [PATCH] list,set and tuple options support escaping the separator --- src/option_types.hh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/option_types.hh b/src/option_types.hh index c9a2d7f3..df2295ce 100644 --- a/src/option_types.hh +++ b/src/option_types.hh @@ -38,7 +38,7 @@ String option_to_string(const std::vector& opt) String res; for (size_t i = 0; i < opt.size(); ++i) { - res += option_to_string(opt[i]); + res += escape(option_to_string(opt[i]), list_separator, '\\'); if (i != opt.size() - 1) res += list_separator; } @@ -49,7 +49,7 @@ template void option_from_string(const String& str, std::vector& opt) { opt.clear(); - std::vector elems = split(str, list_separator); + std::vector elems = split(str, list_separator, '\\'); for (auto& elem: elems) { T opt_elem; @@ -73,7 +73,7 @@ String option_to_string(const std::unordered_set& opt) { if (it != begin(opt)) res += list_separator; - res += option_to_string(*it); + res += escape(option_to_string(*it), list_separator, '\\'); } return res; } @@ -82,7 +82,7 @@ template void option_from_string(const String& str, std::unordered_set& opt) { opt.clear(); - std::vector elems = split(str, list_separator); + std::vector elems = split(str, list_separator, '\\'); for (auto& elem: elems) { T opt_elem; @@ -106,7 +106,7 @@ struct TupleOptionDetail static String to_string(const std::tuple& opt) { return TupleOptionDetail::to_string(opt) + - tuple_separator + option_to_string(std::get(opt)); + tuple_separator + escape(option_to_string(std::get(opt)), tuple_separator, '\\'); } static void from_string(const memoryview& elems, std::tuple& opt) @@ -139,7 +139,7 @@ String option_to_string(const std::tuple& opt) template void option_from_string(const String& str, std::tuple& opt) { - auto elems = split(str, tuple_separator); + auto elems = split(str, tuple_separator, '\\'); if (elems.size() != sizeof...(Types)) throw runtime_error("not enough elements in tuple"); TupleOptionDetail::from_string(elems, opt);