Add a format_with format function that takes a FunctionRef append

This commit is contained in:
Maxime Coste 2021-07-31 09:45:05 +10:00
parent a566a22cbc
commit 1728274803
2 changed files with 14 additions and 0 deletions

View File

@ -359,6 +359,11 @@ StringView format_to(ArrayView<char> buffer, StringView fmt, ArrayView<const Str
return { buffer.begin(), ptr }; return { buffer.begin(), ptr };
} }
void format_with(FunctionRef<void (StringView)> append, StringView fmt, ArrayView<const StringView> params)
{
format_impl(fmt, params, append);
}
String format(StringView fmt, ArrayView<const StringView> params) String format(StringView fmt, ArrayView<const StringView> params)
{ {
ByteCount size = fmt.length(); ByteCount size = fmt.length();

View File

@ -6,6 +6,7 @@
#include "vector.hh" #include "vector.hh"
#include "ranges.hh" #include "ranges.hh"
#include "optional.hh" #include "optional.hh"
#include "utils.hh"
namespace Kakoune namespace Kakoune
{ {
@ -161,6 +162,14 @@ StringView format_to(ArrayView<char> buffer, StringView fmt, Types&&... params)
return format_to(buffer, fmt, ArrayView<const StringView>{detail::format_param(std::forward<Types>(params))...}); return format_to(buffer, fmt, ArrayView<const StringView>{detail::format_param(std::forward<Types>(params))...});
} }
void format_with(FunctionRef<void (StringView)> append, StringView fmt, ArrayView<const StringView> params);
template<typename... Types>
void format_with(FunctionRef<void (StringView)> append, StringView fmt, Types&&... params)
{
return format_with(append, fmt, ArrayView<const StringView>{detail::format_param(std::forward<Types>(params))...});
}
String double_up(StringView s, StringView characters); String double_up(StringView s, StringView characters);
inline String quote(StringView s) inline String quote(StringView s)