From 1728274803431581c123bdd3eb0275d1447f7966 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 31 Jul 2021 09:45:05 +1000 Subject: [PATCH] Add a format_with format function that takes a FunctionRef append --- src/string_utils.cc | 5 +++++ src/string_utils.hh | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/string_utils.cc b/src/string_utils.cc index 2ae8ea6f..212cab2e 100644 --- a/src/string_utils.cc +++ b/src/string_utils.cc @@ -359,6 +359,11 @@ StringView format_to(ArrayView buffer, StringView fmt, ArrayView append, StringView fmt, ArrayView params) +{ + format_impl(fmt, params, append); +} + String format(StringView fmt, ArrayView params) { ByteCount size = fmt.length(); diff --git a/src/string_utils.hh b/src/string_utils.hh index 4da7ddc3..e0adc181 100644 --- a/src/string_utils.hh +++ b/src/string_utils.hh @@ -6,6 +6,7 @@ #include "vector.hh" #include "ranges.hh" #include "optional.hh" +#include "utils.hh" namespace Kakoune { @@ -161,6 +162,14 @@ StringView format_to(ArrayView buffer, StringView fmt, Types&&... params) return format_to(buffer, fmt, ArrayView{detail::format_param(std::forward(params))...}); } +void format_with(FunctionRef append, StringView fmt, ArrayView params); + +template +void format_with(FunctionRef append, StringView fmt, Types&&... params) +{ + return format_with(append, fmt, ArrayView{detail::format_param(std::forward(params))...}); +} + String double_up(StringView s, StringView characters); inline String quote(StringView s)