lib/fmt/ToBuffer: add overload with StringBuffer parameter

This commit is contained in:
Max Kellermann 2023-02-23 18:13:01 +01:00 committed by Max Kellermann
parent 3d69f43cff
commit fb2e0f734e
1 changed files with 27 additions and 4 deletions

View File

@ -10,16 +10,39 @@
#include <fmt/format.h> // for the fmt::buffer::flush() implementation
#endif
template<std::size_t size>
StringBuffer<size> &
VFmtToBuffer(StringBuffer<size> &buffer,
fmt::string_view format_str, fmt::format_args args) noexcept
{
auto [p, _] = fmt::vformat_to_n(buffer.begin(), buffer.capacity() - 1,
format_str, args);
*p = 0;
return buffer;
}
template<std::size_t size>
[[nodiscard]] [[gnu::pure]]
auto
VFmtBuffer(fmt::string_view format_str, fmt::format_args args) noexcept
{
StringBuffer<size> buffer;
auto [p, _] = fmt::vformat_to_n(buffer.begin(), buffer.capacity() - 1,
format_str, args);
*p = 0;
return buffer;
return VFmtToBuffer(buffer, format_str, args);
}
template<std::size_t size, typename S, typename... Args>
StringBuffer<size> &
FmtToBuffer(StringBuffer<size> &buffer,
const S &format_str, Args&&... args) noexcept
{
#if FMT_VERSION >= 90000
return VFmtToBuffer(buffer, format_str,
fmt::make_format_args(args...));
#else
return VFmtToBuffer(buffer, fmt::to_string_view(format_str),
fmt::make_args_checked<Args...>(format_str,
args...));
#endif
}
template<std::size_t size, typename S, typename... Args>