diff --git a/AK/Format.h b/AK/Format.h index dd0e75e453..6449b59194 100644 --- a/AK/Format.h +++ b/AK/Format.h @@ -30,6 +30,12 @@ struct Formatter { using __no_formatter_defined = void; }; +template +inline constexpr bool HasFormatter = true; + +template +inline constexpr bool HasFormatter::__no_formatter_defined> = false; + constexpr size_t max_format_arguments = 256; struct TypeErasedParameter { @@ -314,6 +320,49 @@ struct Formatter : StandardFormatter { void format(FormatBuilder&, StringView value); }; +template +requires(HasFormatter) struct Formatter> : StandardFormatter { + + Formatter() = default; + explicit Formatter(StandardFormatter formatter) + : StandardFormatter(formatter) + { + } + void format(FormatBuilder& builder, Vector value) + { + if (m_mode == Mode::Pointer) { + Formatter formatter { *this }; + formatter.format(builder, reinterpret_cast(value.data())); + return; + } + + if (m_sign_mode != FormatBuilder::SignMode::Default) + VERIFY_NOT_REACHED(); + if (m_alternative_form) + VERIFY_NOT_REACHED(); + if (m_zero_pad) + VERIFY_NOT_REACHED(); + if (m_mode != Mode::Default) + VERIFY_NOT_REACHED(); + if (m_width.has_value() && m_precision.has_value()) + VERIFY_NOT_REACHED(); + + m_width = m_width.value_or(0); + m_precision = m_precision.value_or(NumericLimits::max()); + + Formatter content_fmt; + builder.put_literal("[ "); + bool first = true; + for (auto& content : value) { + if (!first) + builder.put_literal(", "); + first = false; + content_fmt.format(builder, content); + } + builder.put_literal(" ]"); + } +}; + template<> struct Formatter : Formatter { void format(FormatBuilder& builder, ReadonlyBytes const& value) @@ -509,12 +558,6 @@ void critical_dmesgln(CheckedFormatString&& fmt, const Parameters } #endif -template -inline constexpr bool HasFormatter = true; - -template -inline constexpr bool HasFormatter::__no_formatter_defined> = false; - template class FormatIfSupported { public: