From b3a7c49c357b740d4005a5faeffae2f3112461e5 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 18 Dec 2025 14:16:55 +0100 Subject: kstd/io: implement c-string formatting --- libs/kstd/include/kstd/bits/formatter.hpp | 32 +++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/libs/kstd/include/kstd/bits/formatter.hpp b/libs/kstd/include/kstd/bits/formatter.hpp index 895d52b..e10fc0c 100644 --- a/libs/kstd/include/kstd/bits/formatter.hpp +++ b/libs/kstd/include/kstd/bits/formatter.hpp @@ -23,7 +23,7 @@ namespace kstd template struct formatter { - bits::format_specs specs; + bits::format_specs specs{}; constexpr auto parse(std::string_view context) -> std::string_view { @@ -172,7 +172,7 @@ namespace kstd template<> struct formatter { - bits::format_specs specs; + bits::format_specs specs{}; constexpr auto parse(std::string_view context) -> std::string_view { @@ -204,6 +204,34 @@ namespace kstd } }; + template<> + struct formatter + { + bits::format_specs specs{}; + + constexpr auto parse(std::string_view context) -> std::string_view + { + return bits::parse_specs(context, specs); + } + + auto format(char const * string, format_context & context) -> void + { + if (string) + { + formatter{specs}.format(string, context); + } + else + { + formatter{specs}.format("(null)", context); + } + } + }; + + template<> + struct formatter : formatter + { + }; + struct format_arg { using formatting_function = std::string_view(void const *, std::string_view, format_context &); -- cgit v1.2.3