From 615fe0368ccc47d99334812b00e72fe63741a9cc Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 13 Nov 2017 11:28:22 +0800 Subject: [PATCH] Options: rework conversion to string of prefixed lists * use the list_separator variable instead of hard coding ':' * fix trailing separator when converting empty prefixed list to string * correctly escape the prefix in case it contains a separator --- src/option_types.hh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/option_types.hh b/src/option_types.hh index e1a4a623..219fcc69 100644 --- a/src/option_types.hh +++ b/src/option_types.hh @@ -322,13 +322,17 @@ EnableIfWithBitOps option_add(Flags& opt, StringView str) template inline String option_to_string(const PrefixedList& opt) { - return format("{}:{}", opt.prefix, option_to_string(opt.list)); + if (opt.list.empty()) + return format("{}", escape(option_to_string(opt.prefix), list_separator, '\\')); + else + return format("{}{}{}", escape(option_to_string(opt.prefix), list_separator, '\\'), + list_separator, option_to_string(opt.list)); } template inline void option_from_string(StringView str, PrefixedList& opt) { - auto it = find(str, ':'); + auto it = find(str, list_separator); option_from_string(StringView{str.begin(), it}, opt.prefix); if (it != str.end()) option_from_string({it+1, str.end()}, opt.list);