mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 13:27:35 +00:00
AK: Add formatters for Span<T> and Span<T const>
This generalizes the formatter currently used for Vector to be usable for any Span.
This commit is contained in:
parent
c372012842
commit
949f5460fb
2 changed files with 42 additions and 4 deletions
27
AK/Format.h
27
AK/Format.h
|
@ -329,15 +329,16 @@ struct Formatter<StringView> : StandardFormatter {
|
|||
ErrorOr<void> format(FormatBuilder&, StringView);
|
||||
};
|
||||
|
||||
template<typename T, size_t inline_capacity>
|
||||
requires(HasFormatter<T>) struct Formatter<Vector<T, inline_capacity>> : StandardFormatter {
|
||||
|
||||
template<typename T>
|
||||
requires(HasFormatter<T>)
|
||||
struct Formatter<Span<T const>> : StandardFormatter {
|
||||
Formatter() = default;
|
||||
explicit Formatter(StandardFormatter formatter)
|
||||
: StandardFormatter(move(formatter))
|
||||
{
|
||||
}
|
||||
ErrorOr<void> format(FormatBuilder& builder, Vector<T> value)
|
||||
|
||||
ErrorOr<void> format(FormatBuilder& builder, Span<T const> value)
|
||||
{
|
||||
if (m_mode == Mode::Pointer) {
|
||||
Formatter<FlatPtr> formatter { *this };
|
||||
|
@ -375,6 +376,24 @@ requires(HasFormatter<T>) struct Formatter<Vector<T, inline_capacity>> : Standar
|
|||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
requires(HasFormatter<T>)
|
||||
struct Formatter<Span<T>> : Formatter<Span<T const>> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Span<T> value)
|
||||
{
|
||||
return Formatter<Span<T const>>::format(builder, value);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, size_t inline_capacity>
|
||||
requires(HasFormatter<T>)
|
||||
struct Formatter<Vector<T, inline_capacity>> : Formatter<Span<T const>> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Vector<T, inline_capacity> const& value)
|
||||
{
|
||||
return Formatter<Span<T const>>::format(builder, value.span());
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Formatter<ReadonlyBytes> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, ReadonlyBytes value)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue