1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 08:47:34 +00:00

AK: Convert AK::Format formatting helpers to returning ErrorOr<void>

This isn't a complete conversion to ErrorOr<void>, but a good chunk.
The end goal here is to propagate buffer allocation failures to the
caller, and allow the use of TRY() with formatting functions.
This commit is contained in:
Andreas Kling 2021-11-16 01:15:21 +01:00
parent 008355c222
commit 216e21a1fa
87 changed files with 450 additions and 448 deletions

View file

@ -82,7 +82,7 @@ private:
template<>
struct AK::Formatter<Cards::Card> : Formatter<FormatString> {
void format(FormatBuilder& builder, const Cards::Card& card)
ErrorOr<void> format(FormatBuilder& builder, Cards::Card const& card)
{
StringView type;
@ -103,6 +103,6 @@ struct AK::Formatter<Cards::Card> : Formatter<FormatString> {
VERIFY_NOT_REACHED();
}
Formatter<FormatString>::format(builder, "{:>2}{}", Cards::Card::labels[card.value()], type);
return Formatter<FormatString>::format(builder, "{:>2}{}", Cards::Card::labels[card.value()], type);
}
};

View file

@ -98,7 +98,7 @@ private:
template<>
struct AK::Formatter<Cards::CardStack> : Formatter<FormatString> {
void format(FormatBuilder& builder, const Cards::CardStack& stack)
ErrorOr<void> format(FormatBuilder& builder, Cards::CardStack const& stack)
{
StringView type;
@ -130,6 +130,6 @@ struct AK::Formatter<Cards::CardStack> : Formatter<FormatString> {
first_card = false;
}
Formatter<FormatString>::format(builder, "{:<10} {:>16}: {}", type, stack.bounding_box(), cards.build());
return Formatter<FormatString>::format(builder, "{:<10} {:>16}: {}", type, stack.bounding_box(), cards.build());
}
};

View file

@ -85,15 +85,15 @@ namespace AK {
template<>
struct Formatter<Core::FileWatcherEvent> : Formatter<FormatString> {
void format(FormatBuilder& builder, const Core::FileWatcherEvent& value)
ErrorOr<void> format(FormatBuilder& builder, Core::FileWatcherEvent const& value)
{
Formatter<FormatString>::format(builder, "FileWatcherEvent(\"{}\", {})", value.event_path, value.type);
return Formatter<FormatString>::format(builder, "FileWatcherEvent(\"{}\", {})", value.event_path, value.type);
}
};
template<>
struct Formatter<Core::FileWatcherEvent::Type> : Formatter<FormatString> {
void format(FormatBuilder& builder, const Core::FileWatcherEvent::Type& value)
ErrorOr<void> format(FormatBuilder& builder, Core::FileWatcherEvent::Type const& value)
{
char const* type;
switch (value) {
@ -116,7 +116,7 @@ struct Formatter<Core::FileWatcherEvent::Type> : Formatter<FormatString> {
VERIFY_NOT_REACHED();
}
builder.put_string(type);
return builder.put_string(type);
}
};

View file

@ -199,7 +199,7 @@ private:
template<>
struct AK::Formatter<Core::Object> : AK::Formatter<FormatString> {
void format(FormatBuilder& builder, const Core::Object& value)
ErrorOr<void> format(FormatBuilder& builder, const Core::Object& value)
{
return AK::Formatter<FormatString>::format(builder, "{}({})", value.class_name(), &value);
}

View file

@ -94,7 +94,7 @@ private:
template<>
struct AK::Formatter<Core::SocketAddress> : Formatter<String> {
void format(FormatBuilder& builder, const Core::SocketAddress& value)
ErrorOr<void> format(FormatBuilder& builder, Core::SocketAddress const& value)
{
return Formatter<String>::format(builder, value.to_string());
}

View file

@ -395,7 +395,7 @@ void pretty_print(Decoder& decoder, OutputStream& stream, int indent)
}
void AK::Formatter<Crypto::ASN1::DecodeError>::format(FormatBuilder& fmtbuilder, Crypto::ASN1::DecodeError error)
ErrorOr<void> AK::Formatter<Crypto::ASN1::DecodeError>::format(FormatBuilder& fmtbuilder, Crypto::ASN1::DecodeError error)
{
using Crypto::ASN1::DecodeError;

View file

@ -206,5 +206,5 @@ void pretty_print(Decoder&, OutputStream&, int indent = 0);
template<>
struct AK::Formatter<Crypto::ASN1::DecodeError> : Formatter<StringView> {
void format(FormatBuilder&, Crypto::ASN1::DecodeError);
ErrorOr<void> format(FormatBuilder&, Crypto::ASN1::DecodeError);
};

View file

@ -350,14 +350,14 @@ bool UnsignedBigInteger::operator>=(UnsignedBigInteger const& other) const
}
void AK::Formatter<Crypto::UnsignedBigInteger>::format(FormatBuilder& fmtbuilder, const Crypto::UnsignedBigInteger& value)
ErrorOr<void> AK::Formatter<Crypto::UnsignedBigInteger>::format(FormatBuilder& fmtbuilder, const Crypto::UnsignedBigInteger& value)
{
if (value.is_invalid())
return Formatter<StringView>::format(fmtbuilder, "invalid");
StringBuilder builder;
for (int i = value.length() - 1; i >= 0; --i)
builder.appendff("{}|", value.words()[i]);
TRY(builder.try_appendff("{}|", value.words()[i]));
return Formatter<StringView>::format(fmtbuilder, builder.string_view());
}

View file

@ -125,7 +125,7 @@ struct UnsignedDivisionResult {
template<>
struct AK::Formatter<Crypto::UnsignedBigInteger> : Formatter<StringView> {
void format(FormatBuilder&, const Crypto::UnsignedBigInteger&);
ErrorOr<void> format(FormatBuilder&, Crypto::UnsignedBigInteger const&);
};
inline Crypto::UnsignedBigInteger

View file

@ -127,12 +127,11 @@ struct AK::Formatter<LibDSP::ProcessorRangeParameter> : AK::StandardFormatter {
: StandardFormatter(formatter)
{
}
void format(FormatBuilder& builder, LibDSP::ProcessorRangeParameter value)
ErrorOr<void> format(FormatBuilder& builder, LibDSP::ProcessorRangeParameter value)
{
if (m_mode == Mode::Pointer) {
Formatter<FlatPtr> formatter { *this };
formatter.format(builder, reinterpret_cast<FlatPtr>(&value));
return;
return formatter.format(builder, reinterpret_cast<FlatPtr>(&value));
}
if (m_sign_mode != FormatBuilder::SignMode::Default)
@ -149,6 +148,7 @@ struct AK::Formatter<LibDSP::ProcessorRangeParameter> : AK::StandardFormatter {
m_width = m_width.value_or(0);
m_precision = m_precision.value_or(NumericLimits<size_t>::max());
builder.put_literal(String::formatted("[{} - {}]: {}", value.min_value(), value.max_value(), value.value()));
TRY(builder.put_literal(String::formatted("[{} - {}]: {}", value.min_value(), value.max_value(), value.value())));
return {};
}
};

View file

@ -66,12 +66,11 @@ namespace AK {
template<>
struct Formatter<GUI::ModelIndex> : Formatter<FormatString> {
void format(FormatBuilder& builder, const GUI::ModelIndex& value)
ErrorOr<void> format(FormatBuilder& builder, GUI::ModelIndex const& value)
{
if (value.internal_data())
return Formatter<FormatString>::format(builder, "ModelIndex({},{},{})", value.row(), value.column(), value.internal_data());
else
return Formatter<FormatString>::format(builder, "ModelIndex({},{})", value.row(), value.column());
return Formatter<FormatString>::format(builder, "ModelIndex({},{})", value.row(), value.column());
}
};

View file

@ -73,7 +73,7 @@ namespace AK {
template<>
struct Formatter<GUI::PersistentModelIndex> : Formatter<FormatString> {
void format(FormatBuilder& builder, const GUI::PersistentModelIndex& value)
ErrorOr<void> format(FormatBuilder& builder, GUI::PersistentModelIndex const& value)
{
return Formatter<FormatString>::format(builder, "PersistentModelIndex({},{},{})", value.row(), value.column(), value.internal_data());
}

View file

@ -40,11 +40,11 @@ private:
template<>
struct AK::Formatter<GUI::TextPosition> : AK::Formatter<FormatString> {
void format(FormatBuilder& builder, const GUI::TextPosition& value)
ErrorOr<void> format(FormatBuilder& builder, GUI::TextPosition const& value)
{
if (value.is_valid())
Formatter<FormatString>::format(builder, "({},{})", value.line(), value.column());
else
Formatter<FormatString>::format(builder, "GUI::TextPosition(Invalid)");
return Formatter<FormatString>::format(builder, "({},{})", value.line(), value.column());
return Formatter<FormatString>::format(builder, "GUI::TextPosition(Invalid)");
}
};

View file

@ -68,11 +68,10 @@ private:
template<>
struct AK::Formatter<GUI::TextRange> : AK::Formatter<FormatString> {
void format(FormatBuilder& builder, const GUI::TextRange& value)
ErrorOr<void> format(FormatBuilder& builder, GUI::TextRange const& value)
{
if (value.is_valid())
return Formatter<FormatString>::format(builder, "{}-{}", value.start(), value.end());
else
return Formatter<FormatString>::format(builder, "GUI::TextRange(Invalid)");
return Formatter<FormatString>::format(builder, "GUI::TextRange(Invalid)");
}
};

View file

@ -70,7 +70,7 @@ private:
template<>
struct AK::Formatter<Gfx::AffineTransform> : Formatter<FormatString> {
void format(FormatBuilder& builder, Gfx::AffineTransform value)
ErrorOr<void> format(FormatBuilder& builder, Gfx::AffineTransform const& value)
{
return Formatter<FormatString>::format(builder, "[{} {} {} {} {} {}]", value.a(), value.b(), value.c(), value.d(), value.e(), value.f());
}

View file

@ -75,9 +75,9 @@ namespace AK {
template<typename T>
struct Formatter<Gfx::Endpoint<T>> : Formatter<StringView> {
void format(FormatBuilder& builder, const Gfx::Endpoint<T>& value)
ErrorOr<void> format(FormatBuilder& builder, Gfx::Endpoint<T> const& value)
{
Formatter<StringView>::format(builder, String::formatted("({}, {}, {})", value.x, value.y, value.z));
return Formatter<StringView>::format(builder, String::formatted("({}, {}, {})", value.x, value.y, value.z));
}
};

View file

@ -352,7 +352,7 @@ bool IPC::decode(IPC::Decoder& decoder, Color& color)
return true;
}
void AK::Formatter<Gfx::Color>::format(FormatBuilder& builder, Gfx::Color const& value)
ErrorOr<void> AK::Formatter<Gfx::Color>::format(FormatBuilder& builder, Gfx::Color const& value)
{
Formatter<StringView>::format(builder, value.to_string());
return Formatter<StringView>::format(builder, value.to_string());
}

View file

@ -478,7 +478,7 @@ namespace AK {
template<>
struct Formatter<Gfx::Color> : public Formatter<StringView> {
void format(FormatBuilder& builder, Gfx::Color const& value);
ErrorOr<void> format(FormatBuilder&, Gfx::Color const&);
};
}

View file

@ -280,9 +280,9 @@ namespace AK {
template<typename T>
struct Formatter<Gfx::Point<T>> : Formatter<StringView> {
void format(FormatBuilder& builder, Gfx::Point<T> const& value)
ErrorOr<void> format(FormatBuilder& builder, Gfx::Point<T> const& value)
{
Formatter<StringView>::format(builder, value.to_string());
return Formatter<StringView>::format(builder, value.to_string());
}
};

View file

@ -726,9 +726,9 @@ namespace AK {
template<typename T>
struct Formatter<Gfx::Rect<T>> : Formatter<StringView> {
void format(FormatBuilder& builder, const Gfx::Rect<T>& value)
ErrorOr<void> format(FormatBuilder& builder, Gfx::Rect<T> const& value)
{
Formatter<StringView>::format(builder, value.to_string());
return Formatter<StringView>::format(builder, value.to_string());
}
};

View file

@ -178,9 +178,9 @@ namespace AK {
template<typename T>
struct Formatter<Gfx::Size<T>> : Formatter<StringView> {
void format(FormatBuilder& builder, Gfx::Size<T> const& value)
ErrorOr<void> format(FormatBuilder& builder, Gfx::Size<T> const& value)
{
Formatter<StringView>::format(builder, value.to_string());
return Formatter<StringView>::format(builder, value.to_string());
}
};

View file

@ -127,9 +127,9 @@ namespace AK {
template<typename T>
struct Formatter<Gfx::Vector2<T>> : Formatter<StringView> {
void format(FormatBuilder& builder, const Gfx::Vector2<T>& value)
ErrorOr<void> format(FormatBuilder& builder, Gfx::Vector2<T> const& value)
{
Formatter<StringView>::format(builder, value.to_string());
return Formatter<StringView>::format(builder, value.to_string());
}
};

View file

@ -144,9 +144,9 @@ namespace AK {
template<typename T>
struct Formatter<Gfx::Vector3<T>> : Formatter<StringView> {
void format(FormatBuilder& builder, const Gfx::Vector3<T>& value)
ErrorOr<void> format(FormatBuilder& builder, Gfx::Vector3<T> const& value)
{
Formatter<StringView>::format(builder, value.to_string());
return Formatter<StringView>::format(builder, value.to_string());
}
};

View file

@ -145,9 +145,9 @@ namespace AK {
template<typename T>
struct Formatter<Gfx::Vector4<T>> : Formatter<StringView> {
void format(FormatBuilder& builder, const Gfx::Vector4<T>& value)
ErrorOr<void> format(FormatBuilder& builder, Gfx::Vector4<T> const& value)
{
Formatter<StringView>::format(builder, value.to_string());
return Formatter<StringView>::format(builder, value.to_string());
}
};

View file

@ -28,7 +28,7 @@ private:
template<>
struct AK::Formatter<JS::Bytecode::Label> : AK::Formatter<FormatString> {
void format(FormatBuilder& builder, JS::Bytecode::Label const& value)
ErrorOr<void> format(FormatBuilder& builder, JS::Bytecode::Label const& value)
{
return AK::Formatter<FormatString>::format(builder, "@{}", value.block().name());
}

View file

@ -42,7 +42,7 @@ private:
template<>
struct AK::Formatter<JS::Bytecode::Register> : AK::Formatter<FormatString> {
void format(FormatBuilder& builder, JS::Bytecode::Register const& value)
ErrorOr<void> format(FormatBuilder& builder, JS::Bytecode::Register const& value)
{
if (value.index() == JS::Bytecode::Register::accumulator_index)
return AK::Formatter<FormatString>::format(builder, "acc");

View file

@ -75,11 +75,11 @@ private:
template<>
struct AK::Formatter<JS::Cell> : AK::Formatter<FormatString> {
void format(FormatBuilder& builder, const JS::Cell* cell)
ErrorOr<void> format(FormatBuilder& builder, JS::Cell const* cell)
{
if (!cell)
Formatter<FormatString>::format(builder, "Cell{nullptr}");
return Formatter<FormatString>::format(builder, "Cell{nullptr}");
else
Formatter<FormatString>::format(builder, "{}({})", cell->class_name(), cell);
return Formatter<FormatString>::format(builder, "{}({})", cell->class_name(), cell);
}
};

View file

@ -75,13 +75,13 @@ namespace AK {
template<>
struct Formatter<JS::PropertyAttributes> : Formatter<StringView> {
void format(FormatBuilder& builder, JS::PropertyAttributes const& property_attributes)
ErrorOr<void> format(FormatBuilder& builder, JS::PropertyAttributes const& property_attributes)
{
Vector<String> parts;
parts.append(String::formatted("[[Writable]]: {}", property_attributes.is_writable()));
parts.append(String::formatted("[[Enumerable]]: {}", property_attributes.is_enumerable()));
parts.append(String::formatted("[[Configurable]]: {}", property_attributes.is_configurable()));
Formatter<StringView>::format(builder, String::formatted("PropertyAttributes {{ {} }}", String::join(", ", parts)));
return Formatter<StringView>::format(builder, String::formatted("PropertyAttributes {{ {} }}", String::join(", ", parts)));
}
};

View file

@ -47,7 +47,7 @@ namespace AK {
template<>
struct Formatter<JS::PropertyDescriptor> : Formatter<StringView> {
void format(FormatBuilder& builder, JS::PropertyDescriptor const& property_descriptor)
ErrorOr<void> format(FormatBuilder& builder, JS::PropertyDescriptor const& property_descriptor)
{
Vector<String> parts;
if (property_descriptor.value.has_value())
@ -62,7 +62,7 @@ struct Formatter<JS::PropertyDescriptor> : Formatter<StringView> {
parts.append(String::formatted("[[Enumerable]]: {}", *property_descriptor.enumerable));
if (property_descriptor.configurable.has_value())
parts.append(String::formatted("[[Configurable]]: {}", *property_descriptor.configurable));
Formatter<StringView>::format(builder, String::formatted("PropertyDescriptor {{ {} }}", String::join(", ", parts)));
return Formatter<StringView>::format(builder, String::formatted("PropertyDescriptor {{ {} }}", String::join(", ", parts)));
}
};

View file

@ -225,14 +225,13 @@ struct Traits<JS::PropertyKey> : public GenericTraits<JS::PropertyKey> {
template<>
struct Formatter<JS::PropertyKey> : Formatter<StringView> {
void format(FormatBuilder& builder, JS::PropertyKey const& property_name)
ErrorOr<void> format(FormatBuilder& builder, JS::PropertyKey const& property_name)
{
if (!property_name.is_valid())
Formatter<StringView>::format(builder, "<invalid PropertyKey>");
else if (property_name.is_number())
Formatter<StringView>::format(builder, String::number(property_name.as_number()));
else
Formatter<StringView>::format(builder, property_name.to_string_or_symbol().to_display_string());
return Formatter<StringView>::format(builder, "<invalid PropertyKey>");
if (property_name.is_number())
return Formatter<StringView>::format(builder, String::number(property_name.as_number()));
return Formatter<StringView>::format(builder, property_name.to_string_or_symbol().to_display_string());
}
};

View file

@ -458,9 +458,9 @@ namespace AK {
template<>
struct Formatter<JS::Value> : Formatter<StringView> {
void format(FormatBuilder& builder, const JS::Value& value)
ErrorOr<void> format(FormatBuilder& builder, JS::Value value)
{
Formatter<StringView>::format(builder, value.is_empty() ? "<empty>" : value.to_string_without_side_effects());
return Formatter<StringView>::format(builder, value.is_empty() ? "<empty>" : value.to_string_without_side_effects());
}
};

View file

@ -166,7 +166,7 @@ namespace AK {
template<>
struct Formatter<PDF::Command> : Formatter<StringView> {
void format(FormatBuilder& format_builder, PDF::Command const& command)
ErrorOr<void> format(FormatBuilder& format_builder, PDF::Command const& command)
{
StringBuilder builder;
builder.appendff("{} ({})",
@ -180,7 +180,7 @@ struct Formatter<PDF::Command> : Formatter<StringView> {
builder.append(" ]");
}
Formatter<StringView>::format(format_builder, builder.to_string());
return Formatter<StringView>::format(format_builder, builder.to_string());
}
};

View file

@ -143,9 +143,9 @@ namespace AK {
template<>
struct Formatter<PDF::Rectangle> : Formatter<StringView> {
void format(FormatBuilder& builder, PDF::Rectangle const& rectangle)
ErrorOr<void> format(FormatBuilder& builder, PDF::Rectangle const& rectangle)
{
Formatter<StringView>::format(builder,
return Formatter<StringView>::format(builder,
String::formatted("Rectangle {{ ll=({}, {}), ur=({}, {}) }}",
rectangle.lower_left_x,
rectangle.lower_left_y,
@ -156,7 +156,7 @@ struct Formatter<PDF::Rectangle> : Formatter<StringView> {
template<>
struct Formatter<PDF::Page> : Formatter<StringView> {
void format(FormatBuilder& builder, PDF::Page const& page)
ErrorOr<void> format(FormatBuilder& builder, PDF::Page const& page)
{
constexpr auto fmt_string = "Page {{\n resources={}\n contents={}\n media_box={}\n crop_box={}\n user_unit={}\n rotate={}\n}}";
auto str = String::formatted(fmt_string,
@ -166,13 +166,13 @@ struct Formatter<PDF::Page> : Formatter<StringView> {
page.crop_box,
page.user_unit,
page.rotate);
Formatter<StringView>::format(builder, str);
return Formatter<StringView>::format(builder, str);
}
};
template<>
struct Formatter<PDF::Destination> : Formatter<StringView> {
void format(FormatBuilder& builder, PDF::Destination const& destination)
ErrorOr<void> format(FormatBuilder& builder, PDF::Destination const& destination)
{
String type_str;
switch (destination.type) {
@ -207,21 +207,21 @@ struct Formatter<PDF::Destination> : Formatter<StringView> {
param_builder.appendff("{} ", param);
auto str = String::formatted("{{ type={} page={} params={} }}", type_str, destination.page, param_builder.to_string());
Formatter<StringView>::format(builder, str);
return Formatter<StringView>::format(builder, str);
}
};
template<>
struct Formatter<PDF::OutlineItem> : Formatter<StringView> {
void format(FormatBuilder& builder, PDF::OutlineItem const& item)
ErrorOr<void> format(FormatBuilder& builder, PDF::OutlineItem const& item)
{
Formatter<StringView>::format(builder, item.to_string(0));
return Formatter<StringView>::format(builder, item.to_string(0));
}
};
template<>
struct Formatter<PDF::OutlineDict> : Formatter<StringView> {
void format(FormatBuilder& builder, PDF::OutlineDict const& dict)
ErrorOr<void> format(FormatBuilder& builder, PDF::OutlineDict const& dict)
{
StringBuilder child_builder;
child_builder.append('[');
@ -229,7 +229,7 @@ struct Formatter<PDF::OutlineDict> : Formatter<StringView> {
child_builder.appendff("{}\n", child.to_string(2));
child_builder.append(" ]");
Formatter<StringView>::format(builder,
return Formatter<StringView>::format(builder,
String::formatted("OutlineDict {{\n count={}\n children={}\n}}", dict.count, child_builder.to_string()));
}
};

View file

@ -63,17 +63,17 @@ namespace AK {
template<PDF::IsObject T>
struct Formatter<T> : Formatter<StringView> {
void format(FormatBuilder& builder, T const& object)
ErrorOr<void> format(FormatBuilder& builder, T const& object)
{
Formatter<StringView>::format(builder, object.to_string(0));
return Formatter<StringView>::format(builder, object.to_string(0));
}
};
template<PDF::IsObject T>
struct Formatter<NonnullRefPtr<T>> : Formatter<T> {
void format(FormatBuilder& builder, NonnullRefPtr<T> const& object)
ErrorOr<void> format(FormatBuilder& builder, NonnullRefPtr<T> const& object)
{
Formatter<T>::format(builder, *object);
return Formatter<T>::format(builder, *object);
}
};

View file

@ -1187,7 +1187,7 @@ namespace AK {
template<>
struct Formatter<PDF::Parser::LinearizationDictionary> : Formatter<StringView> {
void format(FormatBuilder& format_builder, PDF::Parser::LinearizationDictionary const& dict)
ErrorOr<void> format(FormatBuilder& format_builder, PDF::Parser::LinearizationDictionary const& dict)
{
StringBuilder builder;
builder.append("{\n");
@ -1202,13 +1202,13 @@ struct Formatter<PDF::Parser::LinearizationDictionary> : Formatter<StringView> {
builder.appendff(" offset_of_main_xref_table={}\n", dict.offset_of_main_xref_table);
builder.appendff(" first_page={}\n", dict.first_page);
builder.append('}');
Formatter<StringView>::format(format_builder, builder.to_string());
return Formatter<StringView>::format(format_builder, builder.to_string());
}
};
template<>
struct Formatter<PDF::Parser::PageOffsetHintTable> : Formatter<StringView> {
void format(FormatBuilder& format_builder, PDF::Parser::PageOffsetHintTable const& table)
ErrorOr<void> format(FormatBuilder& format_builder, PDF::Parser::PageOffsetHintTable const& table)
{
StringBuilder builder;
builder.append("{\n");
@ -1226,13 +1226,13 @@ struct Formatter<PDF::Parser::PageOffsetHintTable> : Formatter<StringView> {
builder.appendff(" bits_required_for_fraction_numerator={}\n", table.bits_required_for_fraction_numerator);
builder.appendff(" shared_object_reference_fraction_denominator={}\n", table.shared_object_reference_fraction_denominator);
builder.append('}');
Formatter<StringView>::format(format_builder, builder.to_string());
return Formatter<StringView>::format(format_builder, builder.to_string());
}
};
template<>
struct Formatter<PDF::Parser::PageOffsetHintTableEntry> : Formatter<StringView> {
void format(FormatBuilder& format_builder, PDF::Parser::PageOffsetHintTableEntry const& entry)
ErrorOr<void> format(FormatBuilder& format_builder, PDF::Parser::PageOffsetHintTableEntry const& entry)
{
StringBuilder builder;
builder.append("{\n");
@ -1250,7 +1250,7 @@ struct Formatter<PDF::Parser::PageOffsetHintTableEntry> : Formatter<StringView>
builder.appendff(" page_content_stream_offset_number={}\n", entry.page_content_stream_offset_number);
builder.appendff(" page_content_stream_length_number={}\n", entry.page_content_stream_length_number);
builder.append('}');
Formatter<StringView>::format(format_builder, builder.to_string());
return Formatter<StringView>::format(format_builder, builder.to_string());
}
};

View file

@ -135,43 +135,37 @@ namespace AK {
template<>
struct Formatter<PDF::LineCapStyle> : Formatter<StringView> {
void format(FormatBuilder& builder, PDF::LineCapStyle const& style)
ErrorOr<void> format(FormatBuilder& builder, PDF::LineCapStyle const& style)
{
switch (style) {
case PDF::LineCapStyle::ButtCap:
Formatter<StringView>::format(builder, "LineCapStyle::ButtCap");
break;
return Formatter<StringView>::format(builder, "LineCapStyle::ButtCap");
case PDF::LineCapStyle::RoundCap:
Formatter<StringView>::format(builder, "LineCapStyle::RoundCap");
break;
return Formatter<StringView>::format(builder, "LineCapStyle::RoundCap");
case PDF::LineCapStyle::SquareCap:
Formatter<StringView>::format(builder, "LineCapStyle::SquareCap");
break;
return Formatter<StringView>::format(builder, "LineCapStyle::SquareCap");
}
}
};
template<>
struct Formatter<PDF::LineJoinStyle> : Formatter<StringView> {
void format(FormatBuilder& builder, PDF::LineJoinStyle const& style)
ErrorOr<void> format(FormatBuilder& builder, PDF::LineJoinStyle const& style)
{
switch (style) {
case PDF::LineJoinStyle::Miter:
Formatter<StringView>::format(builder, "LineJoinStyle::Miter");
break;
return Formatter<StringView>::format(builder, "LineJoinStyle::Miter");
case PDF::LineJoinStyle::Round:
Formatter<StringView>::format(builder, "LineJoinStyle::Round");
break;
return Formatter<StringView>::format(builder, "LineJoinStyle::Round");
case PDF::LineJoinStyle::Bevel:
Formatter<StringView>::format(builder, "LineJoinStyle::Bevel");
break;
return Formatter<StringView>::format(builder, "LineJoinStyle::Bevel");
}
}
};
template<>
struct Formatter<PDF::LineDashPattern> : Formatter<StringView> {
void format(FormatBuilder& format_builder, PDF::LineDashPattern const& pattern)
ErrorOr<void> format(FormatBuilder& format_builder, PDF::LineDashPattern const& pattern)
{
StringBuilder builder;
builder.append("[");
@ -191,40 +185,32 @@ struct Formatter<PDF::LineDashPattern> : Formatter<StringView> {
template<>
struct Formatter<PDF::TextRenderingMode> : Formatter<StringView> {
void format(FormatBuilder& builder, PDF::TextRenderingMode const& style)
ErrorOr<void> format(FormatBuilder& builder, PDF::TextRenderingMode const& style)
{
switch (style) {
case PDF::TextRenderingMode::Fill:
Formatter<StringView>::format(builder, "TextRenderingMode::Fill");
break;
return Formatter<StringView>::format(builder, "TextRenderingMode::Fill");
case PDF::TextRenderingMode::Stroke:
Formatter<StringView>::format(builder, "TextRenderingMode::Stroke");
break;
return Formatter<StringView>::format(builder, "TextRenderingMode::Stroke");
case PDF::TextRenderingMode::FillThenStroke:
Formatter<StringView>::format(builder, "TextRenderingMode::FillThenStroke");
break;
return Formatter<StringView>::format(builder, "TextRenderingMode::FillThenStroke");
case PDF::TextRenderingMode::Invisible:
Formatter<StringView>::format(builder, "TextRenderingMode::Invisible");
break;
return Formatter<StringView>::format(builder, "TextRenderingMode::Invisible");
case PDF::TextRenderingMode::FillAndClip:
Formatter<StringView>::format(builder, "TextRenderingMode::FillAndClip");
break;
return Formatter<StringView>::format(builder, "TextRenderingMode::FillAndClip");
case PDF::TextRenderingMode::StrokeAndClip:
Formatter<StringView>::format(builder, "TextRenderingMode::StrokeAndClip");
break;
return Formatter<StringView>::format(builder, "TextRenderingMode::StrokeAndClip");
case PDF::TextRenderingMode::FillStrokeAndClip:
Formatter<StringView>::format(builder, "TextRenderingMode::FillStrokeAndClip");
break;
return Formatter<StringView>::format(builder, "TextRenderingMode::FillStrokeAndClip");
case PDF::TextRenderingMode::Clip:
Formatter<StringView>::format(builder, "TextRenderingMode::Clip");
break;
return Formatter<StringView>::format(builder, "TextRenderingMode::Clip");
}
}
};
template<>
struct Formatter<PDF::TextState> : Formatter<StringView> {
void format(FormatBuilder& format_builder, PDF::TextState const& state)
ErrorOr<void> format(FormatBuilder& format_builder, PDF::TextState const& state)
{
StringBuilder builder;
builder.append("TextState {\n");
@ -239,13 +225,13 @@ struct Formatter<PDF::TextState> : Formatter<StringView> {
builder.appendff(" rise={}\n", state.rise);
builder.appendff(" knockout={}\n", state.knockout);
builder.append(" }");
Formatter<StringView>::format(format_builder, builder.to_string());
return Formatter<StringView>::format(format_builder, builder.to_string());
}
};
template<>
struct Formatter<PDF::GraphicsState> : Formatter<StringView> {
void format(FormatBuilder& format_builder, PDF::GraphicsState const& state)
ErrorOr<void> format(FormatBuilder& format_builder, PDF::GraphicsState const& state)
{
StringBuilder builder;
builder.append("GraphicsState {\n");
@ -259,7 +245,7 @@ struct Formatter<PDF::GraphicsState> : Formatter<StringView> {
builder.appendff(" line_dash_pattern={}\n", state.line_dash_pattern);
builder.appendff(" text_state={}\n", state.text_state);
builder.append("}");
Formatter<StringView>::format(format_builder, builder.to_string());
return Formatter<StringView>::format(format_builder, builder.to_string());
}
};

View file

@ -85,9 +85,9 @@ namespace AK {
template<>
struct Formatter<PDF::Value> : Formatter<StringView> {
void format(FormatBuilder& builder, PDF::Value const& value)
ErrorOr<void> format(FormatBuilder& builder, PDF::Value const& value)
{
Formatter<StringView>::format(builder, value.to_string());
return Formatter<StringView>::format(builder, value.to_string());
}
};

View file

@ -101,9 +101,9 @@ namespace AK {
template<>
struct Formatter<PDF::XRefEntry> : Formatter<StringView> {
void format(FormatBuilder& builder, PDF::XRefEntry const& entry)
ErrorOr<void> format(FormatBuilder& builder, PDF::XRefEntry const& entry)
{
Formatter<StringView>::format(builder,
return Formatter<StringView>::format(builder,
String::formatted("XRefEntry {{ offset={} generation={} used={} }}",
entry.byte_offset,
entry.generation_number,
@ -113,14 +113,14 @@ struct Formatter<PDF::XRefEntry> : Formatter<StringView> {
template<>
struct Formatter<PDF::XRefTable> : Formatter<StringView> {
void format(FormatBuilder& format_builder, PDF::XRefTable const& table)
ErrorOr<void> format(FormatBuilder& format_builder, PDF::XRefTable const& table)
{
StringBuilder builder;
builder.append("XRefTable {");
for (auto& entry : table.m_entries)
builder.appendff("\n {}", entry);
builder.append("\n}");
Formatter<StringView>::format(format_builder, builder.to_string());
return Formatter<StringView>::format(format_builder, builder.to_string());
}
};

View file

@ -536,7 +536,7 @@ using regex::RegexStringView;
template<>
struct AK::Formatter<regex::RegexStringView> : Formatter<StringView> {
void format(FormatBuilder& builder, regex::RegexStringView value)
ErrorOr<void> format(FormatBuilder& builder, regex::RegexStringView value)
{
auto string = value.to_string();
return Formatter<StringView>::format(builder, string);

View file

@ -286,27 +286,27 @@ private:
template<>
struct AK::Formatter<Wasm::Validator::StackEntry> : public AK::Formatter<StringView> {
void format(FormatBuilder& builder, Wasm::Validator::StackEntry const& value)
ErrorOr<void> format(FormatBuilder& builder, Wasm::Validator::StackEntry const& value)
{
if (value.is_known)
return Formatter<StringView>::format(builder, Wasm::ValueType::kind_name(value.concrete_type.kind()));
Formatter<StringView>::format(builder, "<unknown>"sv);
return Formatter<StringView>::format(builder, "<unknown>"sv);
}
};
template<>
struct AK::Formatter<Wasm::ValueType> : public AK::Formatter<StringView> {
void format(FormatBuilder& builder, Wasm::ValueType const& value)
ErrorOr<void> format(FormatBuilder& builder, Wasm::ValueType const& value)
{
Formatter<StringView>::format(builder, Wasm::ValueType::kind_name(value.kind()));
return Formatter<StringView>::format(builder, Wasm::ValueType::kind_name(value.kind()));
}
};
template<>
struct AK::Formatter<Wasm::ValidationError> : public AK::Formatter<StringView> {
void format(FormatBuilder& builder, Wasm::ValidationError const& error)
ErrorOr<void> format(FormatBuilder& builder, Wasm::ValidationError const& error)
{
Formatter<StringView>::format(builder, error.error_string);
return Formatter<StringView>::format(builder, error.error_string);
}
};

View file

@ -101,25 +101,25 @@ namespace AK {
template<>
struct Formatter<Web::CSS::MediaQuery::MediaFeature> : Formatter<StringView> {
void format(FormatBuilder& builder, Web::CSS::MediaQuery::MediaFeature const& media_feature)
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::MediaQuery::MediaFeature const& media_feature)
{
Formatter<StringView>::format(builder, media_feature.to_string());
return Formatter<StringView>::format(builder, media_feature.to_string());
}
};
template<>
struct Formatter<Web::CSS::MediaQuery::MediaCondition> : Formatter<StringView> {
void format(FormatBuilder& builder, Web::CSS::MediaQuery::MediaCondition const& media_condition)
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::MediaQuery::MediaCondition const& media_condition)
{
Formatter<StringView>::format(builder, media_condition.to_string());
return Formatter<StringView>::format(builder, media_condition.to_string());
}
};
template<>
struct Formatter<Web::CSS::MediaQuery> : Formatter<StringView> {
void format(FormatBuilder& builder, Web::CSS::MediaQuery const& media_query)
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::MediaQuery const& media_query)
{
Formatter<StringView>::format(builder, media_query.to_string());
return Formatter<StringView>::format(builder, media_query.to_string());
}
};

View file

@ -151,9 +151,9 @@ namespace AK {
template<>
struct Formatter<Web::CSS::Selector> : Formatter<StringView> {
void format(FormatBuilder& builder, Web::CSS::Selector const& selector)
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Selector const& selector)
{
Formatter<StringView>::format(builder, selector.serialize());
return Formatter<StringView>::format(builder, selector.serialize());
}
};

View file

@ -51,9 +51,9 @@ private:
namespace AK {
template<>
struct Formatter<Web::DOM::Position> : Formatter<StringView> {
void format(FormatBuilder& builder, const Web::DOM::Position& value)
ErrorOr<void> format(FormatBuilder& builder, Web::DOM::Position const& value)
{
Formatter<StringView>::format(builder, value.to_string());
return Formatter<StringView>::format(builder, value.to_string());
}
};