From 43aeee743fe1376ac93073b30b03849f73d7aba3 Mon Sep 17 00:00:00 2001 From: Vinicius Rangel Date: Tue, 24 Sep 2024 23:56:31 -0300 Subject: [PATCH] custom u8string formatter for fmt library --- src/common/logging/formatter.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/common/logging/formatter.h b/src/common/logging/formatter.h index f80905cc3..2ad481b12 100644 --- a/src/common/logging/formatter.h +++ b/src/common/logging/formatter.h @@ -19,3 +19,27 @@ struct fmt::formatter, char>> } }; #endif + +namespace fmt { +template +struct UTF { + T data; + + explicit UTF(const std::u8string_view view) { + data = T{(const char*)&view.front(), (const char*)&view.back()}; + } + + explicit UTF(const std::u8string& str) + : UTF(std::u8string_view{str}) { + } +}; +} + +template <> +struct fmt::formatter, char> + : formatter { + template + auto format(const UTF& wrapper, FormatContext& ctx) const { + return formatter::format(wrapper.data, ctx); + } +}; \ No newline at end of file