diff options
| author | Maxime Coste <mawww@kakoune.org> | 2019-06-18 22:18:17 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2019-06-19 23:04:16 +1000 |
| commit | 8b2906a14d3395a6619c7e40d3206b75eef11b25 (patch) | |
| tree | d559789c90745dd538751bd163791860ddfecb48 /src/string_utils.hh | |
| parent | 59e43c8f0c2d125952c8bad3b1b0c9053046926d (diff) | |
Refactor option_to_string quoting support, introduce Quoting::Raw
Diffstat (limited to 'src/string_utils.hh')
| -rw-r--r-- | src/string_utils.hh | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/string_utils.hh b/src/string_utils.hh index 92714a0d..224dffc2 100644 --- a/src/string_utils.hh +++ b/src/string_utils.hh @@ -65,10 +65,6 @@ Vector<StringView> wrap_lines(StringView text, ColumnCount max_width); int str_to_int(StringView str); // throws on error Optional<int> str_to_int_ifp(StringView str); -inline String option_to_string(StringView opt) { return opt.str(); } -inline String option_from_string(Meta::Type<String>, StringView str) { return str.str(); } -inline bool option_add(String& opt, StringView val) { opt += val; return not val.empty(); } - template<size_t N> struct InplaceString { @@ -142,15 +138,27 @@ inline String shell_quote(StringView s) enum class Quoting { + Raw, Kakoune, Shell }; inline auto quoter(Quoting quoting) { - return quoting == Quoting::Kakoune ? "e : &shell_quote; + switch (quoting) + { + case Quoting::Kakoune: return "e; + case Quoting::Shell: return &shell_quote; + case Quoting::Raw: + default: + return +[](StringView s) { return s.str(); }; + } } +inline String option_to_string(StringView opt, Quoting quoting) { return quoter(quoting)(opt); } +inline Vector<String> option_to_strings(StringView opt) { return {opt.str()}; } +inline String option_from_string(Meta::Type<String>, StringView str) { return str.str(); } +inline bool option_add(String& opt, StringView val) { opt += val; return not val.empty(); } } |
