diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2025-12-18 14:16:55 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2025-12-18 14:16:55 +0100 |
| commit | b3a7c49c357b740d4005a5faeffae2f3112461e5 (patch) | |
| tree | 7118effd536544b2e9bcf1a0bec2b141f44fd726 /libs | |
| parent | 169af2d2cb062565b3f865fe578b49352e4784b3 (diff) | |
| download | teachos-b3a7c49c357b740d4005a5faeffae2f3112461e5.tar.xz teachos-b3a7c49c357b740d4005a5faeffae2f3112461e5.zip | |
kstd/io: implement c-string formatting
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/kstd/include/kstd/bits/formatter.hpp | 32 |
1 files 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<std::integral T> struct formatter<T> { - 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<std::string_view> { - 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<char const *> + { + 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<std::string_view>{specs}.format(string, context); + } + else + { + formatter<std::string_view>{specs}.format("(null)", context); + } + } + }; + + template<> + struct formatter<char *> : formatter<char const *> + { + }; + struct format_arg { using formatting_function = std::string_view(void const *, std::string_view, format_context &); |
