1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-19 01:11:36 +03:00

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
This commit is contained in:
Maxime Coste 2017-11-13 11:28:22 +08:00
parent 078f0b5c90
commit 615fe0368c

View File

@ -322,13 +322,17 @@ EnableIfWithBitOps<Flags, bool> option_add(Flags& opt, StringView str)
template<typename P, typename T>
inline String option_to_string(const PrefixedList<P, T>& 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<typename P, typename T>
inline void option_from_string(StringView str, PrefixedList<P, T>& 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);