client/Response: add method Fmt() based on libfmt

This commit is contained in:
Max Kellermann
2021-05-21 20:35:29 +02:00
parent a9c704b76e
commit 0440c41cba
27 changed files with 241 additions and 195 deletions

View File

@@ -23,26 +23,27 @@
#include "client/Response.hxx"
#include "util/StringView.hxx"
#include <fmt/format.h>
void
tag_print_types(Response &r) noexcept
{
const auto tag_mask = global_tag_mask & r.GetTagMask();
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++)
if (tag_mask.Test(TagType(i)))
r.Format("tagtype: %s\n", tag_item_names[i]);
r.Fmt(FMT_STRING("tagtype: {}\n"), tag_item_names[i]);
}
void
tag_print(Response &r, TagType type, StringView value) noexcept
{
r.Format("%s: %.*s\n", tag_item_names[type],
int(value.size), value.data);
r.Fmt(FMT_STRING("{}: {}\n"), tag_item_names[type], value);
}
void
tag_print(Response &r, TagType type, const char *value) noexcept
{
r.Format("%s: %s\n", tag_item_names[type], value);
r.Fmt(FMT_STRING("{}: {}\n"), tag_item_names[type], value);
}
void
@@ -58,10 +59,10 @@ void
tag_print(Response &r, const Tag &tag) noexcept
{
if (!tag.duration.IsNegative())
r.Format("Time: %i\n"
"duration: %1.3f\n",
tag.duration.RoundS(),
tag.duration.ToDoubleS());
r.Fmt(FMT_STRING("Time: {}\n"
"duration: {:1.3}\n"),
tag.duration.RoundS(),
tag.duration.ToDoubleS());
tag_print_values(r, tag);
}