From cf7db48c261ee9c896c813a38ff8c59da5b8fe07 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Sun, 26 Jan 2025 00:40:51 +0100 Subject: Fix line endings --- asl/format.hpp | 216 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 108 insertions(+), 108 deletions(-) (limited to 'asl/format.hpp') diff --git a/asl/format.hpp b/asl/format.hpp index 70ccd09..70de9b9 100644 --- a/asl/format.hpp +++ b/asl/format.hpp @@ -1,109 +1,109 @@ -#pragma once - +#pragma once + #include "asl/integers.hpp" -#include "asl/meta.hpp" -#include "asl/io.hpp" -#include "asl/span.hpp" -#include "asl/string_view.hpp" - -namespace asl -{ - -class Formatter; - -template -concept formattable = requires (Formatter& f, const T& value) -{ - AslFormat(f, value); -}; - -namespace format_internals -{ - -struct type_erased_arg -{ - const void* data; - void (*fn)(Formatter&, const void*); - - template - static constexpr void erased_fn(Formatter& f, const void* data) - { - AslFormat(f, *reinterpret_cast(data)); - } - - template - explicit constexpr type_erased_arg(const T& arg) - : data{&arg} - , fn{erased_fn} - {} -}; - -void format(Writer*, string_view fmt, span args); - -} // namespace internals - -class Formatter -{ - Writer* m_writer; - -public: - explicit constexpr Formatter(Writer* writer) - : m_writer{writer} - {} - - constexpr void write(string_view s) - { - m_writer->write(as_bytes(s.as_span())); - } - - constexpr Writer* writer() const { return m_writer; } -}; - -template -void format(Writer* w, string_view fmt, const Args&... args) -{ - if constexpr (types_count > 0) - { - format_internals::type_erased_arg type_erased_args[] = { - format_internals::type_erased_arg(args)... - }; - - format_internals::format(w, fmt, type_erased_args); - } - else - { - format_internals::format(w, fmt, {}); - } -} - -template -void AslFormat(Formatter& f, const char (&str)[N]) -{ - f.write(string_view(str, N - 1)); -} - -void AslFormat(Formatter& f, const char* str); - -inline void AslFormat(Formatter& f, string_view sv) -{ - f.write(sv); -} - -void AslFormat(Formatter& f, float); -void AslFormat(Formatter& f, double); - -void AslFormat(Formatter& f, bool); - -void AslFormat(Formatter& f, uint8_t); -void AslFormat(Formatter& f, uint16_t); -void AslFormat(Formatter& f, uint32_t); -void AslFormat(Formatter& f, uint64_t); - -void AslFormat(Formatter& f, int8_t); -void AslFormat(Formatter& f, int16_t); -void AslFormat(Formatter& f, int32_t); -void AslFormat(Formatter& f, int64_t); - -string_view format_uint64(uint64_t value, span buffer); - -} // namespace asl +#include "asl/meta.hpp" +#include "asl/io.hpp" +#include "asl/span.hpp" +#include "asl/string_view.hpp" + +namespace asl +{ + +class Formatter; + +template +concept formattable = requires (Formatter& f, const T& value) +{ + AslFormat(f, value); +}; + +namespace format_internals +{ + +struct type_erased_arg +{ + const void* data; + void (*fn)(Formatter&, const void*); + + template + static constexpr void erased_fn(Formatter& f, const void* data) + { + AslFormat(f, *reinterpret_cast(data)); + } + + template + explicit constexpr type_erased_arg(const T& arg) + : data{&arg} + , fn{erased_fn} + {} +}; + +void format(Writer*, string_view fmt, span args); + +} // namespace internals + +class Formatter +{ + Writer* m_writer; + +public: + explicit constexpr Formatter(Writer* writer) + : m_writer{writer} + {} + + constexpr void write(string_view s) + { + m_writer->write(as_bytes(s.as_span())); + } + + constexpr Writer* writer() const { return m_writer; } +}; + +template +void format(Writer* w, string_view fmt, const Args&... args) +{ + if constexpr (types_count > 0) + { + format_internals::type_erased_arg type_erased_args[] = { + format_internals::type_erased_arg(args)... + }; + + format_internals::format(w, fmt, type_erased_args); + } + else + { + format_internals::format(w, fmt, {}); + } +} + +template +void AslFormat(Formatter& f, const char (&str)[N]) +{ + f.write(string_view(str, N - 1)); +} + +void AslFormat(Formatter& f, const char* str); + +inline void AslFormat(Formatter& f, string_view sv) +{ + f.write(sv); +} + +void AslFormat(Formatter& f, float); +void AslFormat(Formatter& f, double); + +void AslFormat(Formatter& f, bool); + +void AslFormat(Formatter& f, uint8_t); +void AslFormat(Formatter& f, uint16_t); +void AslFormat(Formatter& f, uint32_t); +void AslFormat(Formatter& f, uint64_t); + +void AslFormat(Formatter& f, int8_t); +void AslFormat(Formatter& f, int16_t); +void AslFormat(Formatter& f, int32_t); +void AslFormat(Formatter& f, int64_t); + +string_view format_uint64(uint64_t value, span buffer); + +} // namespace asl -- cgit