mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +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:
parent
008355c222
commit
216e21a1fa
Notes:
sideshowbarker
2024-07-18 01:03:43 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/216e21a1fa9
87 changed files with 450 additions and 448 deletions
|
@ -271,7 +271,7 @@ private:
|
||||||
|
|
||||||
template<typename T, typename X, bool Incr, bool Cmp, bool Bool, bool Flags, bool Shift, bool Arith>
|
template<typename T, typename X, bool Incr, bool Cmp, bool Bool, bool Flags, bool Shift, bool Arith>
|
||||||
struct Formatter<DistinctNumeric<T, X, Incr, Cmp, Bool, Flags, Shift, Arith>> : Formatter<T> {
|
struct Formatter<DistinctNumeric<T, X, Incr, Cmp, Bool, Flags, Shift, Arith>> : Formatter<T> {
|
||||||
void format(FormatBuilder& builder, DistinctNumeric<T, X, Incr, Cmp, Bool, Flags, Shift, Arith> value)
|
ErrorOr<void> format(FormatBuilder& builder, DistinctNumeric<T, X, Incr, Cmp, Bool, Flags, Shift, Arith> value)
|
||||||
{
|
{
|
||||||
return Formatter<T>::format(builder, value.value());
|
return Formatter<T>::format(builder, value.value());
|
||||||
}
|
}
|
||||||
|
|
11
AK/Error.h
11
AK/Error.h
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Format.h>
|
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <AK/Try.h>
|
#include <AK/Try.h>
|
||||||
|
@ -131,16 +130,6 @@ private:
|
||||||
Optional<ErrorType> m_error;
|
Optional<ErrorType> m_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
|
||||||
struct Formatter<Error> : Formatter<FormatString> {
|
|
||||||
void format(FormatBuilder& builder, Error const& error)
|
|
||||||
{
|
|
||||||
if (error.is_errno())
|
|
||||||
return Formatter<FormatString>::format(builder, "Error(errno={})", error.code());
|
|
||||||
return Formatter<FormatString>::format(builder, "Error({})", error.string_literal());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using AK::Error;
|
using AK::Error;
|
||||||
|
|
|
@ -322,10 +322,10 @@ struct Formatter<FixedPoint<precision, Underlying>> : StandardFormatter {
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void format(FormatBuilder& builder, FixedPoint<precision, Underlying> value)
|
ErrorOr<void> format(FormatBuilder& builder, FixedPoint<precision, Underlying> value)
|
||||||
{
|
{
|
||||||
Formatter<double> formatter { *this };
|
Formatter<double> formatter { *this };
|
||||||
formatter.format(builder, (double)value);
|
return formatter.format(builder, (double)value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
226
AK/Format.cpp
226
AK/Format.cpp
|
@ -75,15 +75,15 @@ static constexpr size_t convert_unsigned_to_string(u64 value, Array<u8, 128>& bu
|
||||||
return used;
|
return used;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vformat_impl(TypeErasedFormatParams& params, FormatBuilder& builder, FormatParser& parser)
|
ErrorOr<void> vformat_impl(TypeErasedFormatParams& params, FormatBuilder& builder, FormatParser& parser)
|
||||||
{
|
{
|
||||||
const auto literal = parser.consume_literal();
|
const auto literal = parser.consume_literal();
|
||||||
builder.put_literal(literal);
|
TRY(builder.put_literal(literal));
|
||||||
|
|
||||||
FormatParser::FormatSpecifier specifier;
|
FormatParser::FormatSpecifier specifier;
|
||||||
if (!parser.consume_specifier(specifier)) {
|
if (!parser.consume_specifier(specifier)) {
|
||||||
VERIFY(parser.is_eof());
|
VERIFY(parser.is_eof());
|
||||||
return;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (specifier.index == use_next_index)
|
if (specifier.index == use_next_index)
|
||||||
|
@ -92,9 +92,9 @@ void vformat_impl(TypeErasedFormatParams& params, FormatBuilder& builder, Format
|
||||||
auto& parameter = params.parameters().at(specifier.index);
|
auto& parameter = params.parameters().at(specifier.index);
|
||||||
|
|
||||||
FormatParser argparser { specifier.flags };
|
FormatParser argparser { specifier.flags };
|
||||||
parameter.formatter(params, builder, argparser, parameter.value);
|
TRY(parameter.formatter(params, builder, argparser, parameter.value));
|
||||||
|
TRY(vformat_impl(params, builder, parser));
|
||||||
vformat_impl(params, builder, parser);
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace AK::{anonymous}
|
} // namespace AK::{anonymous}
|
||||||
|
@ -189,20 +189,23 @@ bool FormatParser::consume_replacement_field(size_t& index)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormatBuilder::put_padding(char fill, size_t amount)
|
ErrorOr<void> FormatBuilder::put_padding(char fill, size_t amount)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < amount; ++i)
|
for (size_t i = 0; i < amount; ++i)
|
||||||
m_builder.append(fill);
|
TRY(m_builder.try_append(fill));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
void FormatBuilder::put_literal(StringView value)
|
ErrorOr<void> FormatBuilder::put_literal(StringView value)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < value.length(); ++i) {
|
for (size_t i = 0; i < value.length(); ++i) {
|
||||||
m_builder.append(value[i]);
|
TRY(m_builder.try_append(value[i]));
|
||||||
if (value[i] == '{' || value[i] == '}')
|
if (value[i] == '{' || value[i] == '}')
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
void FormatBuilder::put_string(
|
|
||||||
|
ErrorOr<void> FormatBuilder::put_string(
|
||||||
StringView value,
|
StringView value,
|
||||||
Align align,
|
Align align,
|
||||||
size_t min_width,
|
size_t min_width,
|
||||||
|
@ -216,21 +219,23 @@ void FormatBuilder::put_string(
|
||||||
value = value.substring_view(0, used_by_string);
|
value = value.substring_view(0, used_by_string);
|
||||||
|
|
||||||
if (align == Align::Left || align == Align::Default) {
|
if (align == Align::Left || align == Align::Default) {
|
||||||
m_builder.append(value);
|
TRY(m_builder.try_append(value));
|
||||||
put_padding(fill, used_by_padding);
|
TRY(put_padding(fill, used_by_padding));
|
||||||
} else if (align == Align::Center) {
|
} else if (align == Align::Center) {
|
||||||
const auto used_by_left_padding = used_by_padding / 2;
|
const auto used_by_left_padding = used_by_padding / 2;
|
||||||
const auto used_by_right_padding = ceil_div<size_t, size_t>(used_by_padding, 2);
|
const auto used_by_right_padding = ceil_div<size_t, size_t>(used_by_padding, 2);
|
||||||
|
|
||||||
put_padding(fill, used_by_left_padding);
|
TRY(put_padding(fill, used_by_left_padding));
|
||||||
m_builder.append(value);
|
TRY(m_builder.try_append(value));
|
||||||
put_padding(fill, used_by_right_padding);
|
TRY(put_padding(fill, used_by_right_padding));
|
||||||
} else if (align == Align::Right) {
|
} else if (align == Align::Right) {
|
||||||
put_padding(fill, used_by_padding);
|
TRY(put_padding(fill, used_by_padding));
|
||||||
m_builder.append(value);
|
TRY(m_builder.try_append(value));
|
||||||
}
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
void FormatBuilder::put_u64(
|
|
||||||
|
ErrorOr<void> FormatBuilder::put_u64(
|
||||||
u64 value,
|
u64 value,
|
||||||
u8 base,
|
u8 base,
|
||||||
bool prefix,
|
bool prefix,
|
||||||
|
@ -271,64 +276,69 @@ void FormatBuilder::put_u64(
|
||||||
const auto used_by_field = used_by_prefix + used_by_digits;
|
const auto used_by_field = used_by_prefix + used_by_digits;
|
||||||
const auto used_by_padding = max(used_by_field, min_width) - used_by_field;
|
const auto used_by_padding = max(used_by_field, min_width) - used_by_field;
|
||||||
|
|
||||||
const auto put_prefix = [&]() {
|
const auto put_prefix = [&]() -> ErrorOr<void> {
|
||||||
if (is_negative)
|
if (is_negative)
|
||||||
m_builder.append('-');
|
TRY(m_builder.try_append('-'));
|
||||||
else if (sign_mode == SignMode::Always)
|
else if (sign_mode == SignMode::Always)
|
||||||
m_builder.append('+');
|
TRY(m_builder.try_append('+'));
|
||||||
else if (sign_mode == SignMode::Reserved)
|
else if (sign_mode == SignMode::Reserved)
|
||||||
m_builder.append(' ');
|
TRY(m_builder.try_append(' '));
|
||||||
|
|
||||||
if (prefix) {
|
if (prefix) {
|
||||||
if (base == 2) {
|
if (base == 2) {
|
||||||
if (upper_case)
|
if (upper_case)
|
||||||
m_builder.append("0B");
|
TRY(m_builder.try_append("0B"));
|
||||||
else
|
else
|
||||||
m_builder.append("0b");
|
TRY(m_builder.try_append("0b"));
|
||||||
} else if (base == 8) {
|
} else if (base == 8) {
|
||||||
m_builder.append("0");
|
TRY(m_builder.try_append("0"));
|
||||||
} else if (base == 16) {
|
} else if (base == 16) {
|
||||||
if (upper_case)
|
if (upper_case)
|
||||||
m_builder.append("0X");
|
TRY(m_builder.try_append("0X"));
|
||||||
else
|
else
|
||||||
m_builder.append("0x");
|
TRY(m_builder.try_append("0x"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return {};
|
||||||
};
|
};
|
||||||
const auto put_digits = [&]() {
|
|
||||||
|
const auto put_digits = [&]() -> ErrorOr<void> {
|
||||||
for (size_t i = 0; i < used_by_digits; ++i)
|
for (size_t i = 0; i < used_by_digits; ++i)
|
||||||
m_builder.append(buffer[i]);
|
TRY(m_builder.try_append(buffer[i]));
|
||||||
|
return {};
|
||||||
};
|
};
|
||||||
|
|
||||||
if (align == Align::Left) {
|
if (align == Align::Left) {
|
||||||
const auto used_by_right_padding = used_by_padding;
|
const auto used_by_right_padding = used_by_padding;
|
||||||
|
|
||||||
put_prefix();
|
TRY(put_prefix());
|
||||||
put_digits();
|
TRY(put_digits());
|
||||||
put_padding(fill, used_by_right_padding);
|
TRY(put_padding(fill, used_by_right_padding));
|
||||||
} else if (align == Align::Center) {
|
} else if (align == Align::Center) {
|
||||||
const auto used_by_left_padding = used_by_padding / 2;
|
const auto used_by_left_padding = used_by_padding / 2;
|
||||||
const auto used_by_right_padding = ceil_div<size_t, size_t>(used_by_padding, 2);
|
const auto used_by_right_padding = ceil_div<size_t, size_t>(used_by_padding, 2);
|
||||||
|
|
||||||
put_padding(fill, used_by_left_padding);
|
TRY(put_padding(fill, used_by_left_padding));
|
||||||
put_prefix();
|
TRY(put_prefix());
|
||||||
put_digits();
|
TRY(put_digits());
|
||||||
put_padding(fill, used_by_right_padding);
|
TRY(put_padding(fill, used_by_right_padding));
|
||||||
} else if (align == Align::Right) {
|
} else if (align == Align::Right) {
|
||||||
const auto used_by_left_padding = used_by_padding;
|
const auto used_by_left_padding = used_by_padding;
|
||||||
|
|
||||||
if (zero_pad) {
|
if (zero_pad) {
|
||||||
put_prefix();
|
TRY(put_prefix());
|
||||||
put_padding('0', used_by_left_padding);
|
TRY(put_padding('0', used_by_left_padding));
|
||||||
put_digits();
|
TRY(put_digits());
|
||||||
} else {
|
} else {
|
||||||
put_padding(fill, used_by_left_padding);
|
TRY(put_padding(fill, used_by_left_padding));
|
||||||
put_prefix();
|
TRY(put_prefix());
|
||||||
put_digits();
|
TRY(put_digits());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
void FormatBuilder::put_i64(
|
|
||||||
|
ErrorOr<void> FormatBuilder::put_i64(
|
||||||
i64 value,
|
i64 value,
|
||||||
u8 base,
|
u8 base,
|
||||||
bool prefix,
|
bool prefix,
|
||||||
|
@ -342,11 +352,12 @@ void FormatBuilder::put_i64(
|
||||||
const auto is_negative = value < 0;
|
const auto is_negative = value < 0;
|
||||||
value = is_negative ? -value : value;
|
value = is_negative ? -value : value;
|
||||||
|
|
||||||
put_u64(static_cast<u64>(value), base, prefix, upper_case, zero_pad, align, min_width, fill, sign_mode, is_negative);
|
TRY(put_u64(static_cast<u64>(value), base, prefix, upper_case, zero_pad, align, min_width, fill, sign_mode, is_negative));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
void FormatBuilder::put_f64(
|
ErrorOr<void> FormatBuilder::put_f64(
|
||||||
double value,
|
double value,
|
||||||
u8 base,
|
u8 base,
|
||||||
bool upper_case,
|
bool upper_case,
|
||||||
|
@ -362,25 +373,25 @@ void FormatBuilder::put_f64(
|
||||||
|
|
||||||
if (isnan(value) || isinf(value)) [[unlikely]] {
|
if (isnan(value) || isinf(value)) [[unlikely]] {
|
||||||
if (value < 0.0)
|
if (value < 0.0)
|
||||||
string_builder.append('-');
|
TRY(string_builder.try_append('-'));
|
||||||
else if (sign_mode == SignMode::Always)
|
else if (sign_mode == SignMode::Always)
|
||||||
string_builder.append('+');
|
TRY(string_builder.try_append('+'));
|
||||||
else if (sign_mode == SignMode::Reserved)
|
else if (sign_mode == SignMode::Reserved)
|
||||||
string_builder.append(' ');
|
TRY(string_builder.try_append(' '));
|
||||||
|
|
||||||
if (isnan(value))
|
if (isnan(value))
|
||||||
string_builder.append(upper_case ? "NAN"sv : "nan"sv);
|
TRY(string_builder.try_append(upper_case ? "NAN"sv : "nan"sv));
|
||||||
else
|
else
|
||||||
string_builder.append(upper_case ? "INF"sv : "inf"sv);
|
TRY(string_builder.try_append(upper_case ? "INF"sv : "inf"sv));
|
||||||
put_string(string_builder.string_view(), align, min_width, NumericLimits<size_t>::max(), fill);
|
TRY(put_string(string_builder.string_view(), align, min_width, NumericLimits<size_t>::max(), fill));
|
||||||
return;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_negative = value < 0.0;
|
bool is_negative = value < 0.0;
|
||||||
if (is_negative)
|
if (is_negative)
|
||||||
value = -value;
|
value = -value;
|
||||||
|
|
||||||
format_builder.put_u64(static_cast<u64>(value), base, false, upper_case, false, Align::Right, 0, ' ', sign_mode, is_negative);
|
TRY(format_builder.put_u64(static_cast<u64>(value), base, false, upper_case, false, Align::Right, 0, ' ', sign_mode, is_negative));
|
||||||
|
|
||||||
if (precision > 0) {
|
if (precision > 0) {
|
||||||
// FIXME: This is a terrible approximation but doing it properly would be a lot of work. If someone is up for that, a good
|
// FIXME: This is a terrible approximation but doing it properly would be a lot of work. If someone is up for that, a good
|
||||||
|
@ -401,19 +412,20 @@ void FormatBuilder::put_f64(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zero_pad || visible_precision > 0)
|
if (zero_pad || visible_precision > 0)
|
||||||
string_builder.append('.');
|
TRY(string_builder.try_append('.'));
|
||||||
|
|
||||||
if (visible_precision > 0)
|
if (visible_precision > 0)
|
||||||
format_builder.put_u64(static_cast<u64>(value), base, false, upper_case, true, Align::Right, visible_precision);
|
TRY(format_builder.put_u64(static_cast<u64>(value), base, false, upper_case, true, Align::Right, visible_precision));
|
||||||
|
|
||||||
if (zero_pad && (precision - visible_precision) > 0)
|
if (zero_pad && (precision - visible_precision) > 0)
|
||||||
format_builder.put_u64(0, base, false, false, true, Align::Right, precision - visible_precision);
|
TRY(format_builder.put_u64(0, base, false, false, true, Align::Right, precision - visible_precision));
|
||||||
}
|
}
|
||||||
|
|
||||||
put_string(string_builder.string_view(), align, min_width, NumericLimits<size_t>::max(), fill);
|
TRY(put_string(string_builder.string_view(), align, min_width, NumericLimits<size_t>::max(), fill));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormatBuilder::put_f80(
|
ErrorOr<void> FormatBuilder::put_f80(
|
||||||
long double value,
|
long double value,
|
||||||
u8 base,
|
u8 base,
|
||||||
bool upper_case,
|
bool upper_case,
|
||||||
|
@ -428,25 +440,25 @@ void FormatBuilder::put_f80(
|
||||||
|
|
||||||
if (isnan(value) || isinf(value)) [[unlikely]] {
|
if (isnan(value) || isinf(value)) [[unlikely]] {
|
||||||
if (value < 0.0l)
|
if (value < 0.0l)
|
||||||
string_builder.append('-');
|
TRY(string_builder.try_append('-'));
|
||||||
else if (sign_mode == SignMode::Always)
|
else if (sign_mode == SignMode::Always)
|
||||||
string_builder.append('+');
|
TRY(string_builder.try_append('+'));
|
||||||
else if (sign_mode == SignMode::Reserved)
|
else if (sign_mode == SignMode::Reserved)
|
||||||
string_builder.append(' ');
|
TRY(string_builder.try_append(' '));
|
||||||
|
|
||||||
if (isnan(value))
|
if (isnan(value))
|
||||||
string_builder.append(upper_case ? "NAN"sv : "nan"sv);
|
TRY(string_builder.try_append(upper_case ? "NAN"sv : "nan"sv));
|
||||||
else
|
else
|
||||||
string_builder.append(upper_case ? "INF"sv : "inf"sv);
|
TRY(string_builder.try_append(upper_case ? "INF"sv : "inf"sv));
|
||||||
put_string(string_builder.string_view(), align, min_width, NumericLimits<size_t>::max(), fill);
|
TRY(put_string(string_builder.string_view(), align, min_width, NumericLimits<size_t>::max(), fill));
|
||||||
return;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_negative = value < 0.0l;
|
bool is_negative = value < 0.0l;
|
||||||
if (is_negative)
|
if (is_negative)
|
||||||
value = -value;
|
value = -value;
|
||||||
|
|
||||||
format_builder.put_u64(static_cast<u64>(value), base, false, upper_case, false, Align::Right, 0, ' ', sign_mode, is_negative);
|
TRY(format_builder.put_u64(static_cast<u64>(value), base, false, upper_case, false, Align::Right, 0, ' ', sign_mode, is_negative));
|
||||||
|
|
||||||
if (precision > 0) {
|
if (precision > 0) {
|
||||||
// FIXME: This is a terrible approximation but doing it properly would be a lot of work. If someone is up for that, a good
|
// FIXME: This is a terrible approximation but doing it properly would be a lot of work. If someone is up for that, a good
|
||||||
|
@ -468,44 +480,50 @@ void FormatBuilder::put_f80(
|
||||||
|
|
||||||
if (visible_precision > 0) {
|
if (visible_precision > 0) {
|
||||||
string_builder.append('.');
|
string_builder.append('.');
|
||||||
format_builder.put_u64(static_cast<u64>(value), base, false, upper_case, true, Align::Right, visible_precision);
|
TRY(format_builder.put_u64(static_cast<u64>(value), base, false, upper_case, true, Align::Right, visible_precision));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
put_string(string_builder.string_view(), align, min_width, NumericLimits<size_t>::max(), fill);
|
TRY(put_string(string_builder.string_view(), align, min_width, NumericLimits<size_t>::max(), fill));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void FormatBuilder::put_hexdump(ReadonlyBytes bytes, size_t width, char fill)
|
ErrorOr<void> FormatBuilder::put_hexdump(ReadonlyBytes bytes, size_t width, char fill)
|
||||||
{
|
{
|
||||||
auto put_char_view = [&](auto i) {
|
auto put_char_view = [&](auto i) -> ErrorOr<void> {
|
||||||
put_padding(fill, 4);
|
TRY(put_padding(fill, 4));
|
||||||
for (size_t j = i - width; j < i; ++j) {
|
for (size_t j = i - width; j < i; ++j) {
|
||||||
auto ch = bytes[j];
|
auto ch = bytes[j];
|
||||||
m_builder.append(ch >= 32 && ch <= 127 ? ch : '.'); // silly hack
|
TRY(m_builder.try_append(ch >= 32 && ch <= 127 ? ch : '.')); // silly hack
|
||||||
}
|
}
|
||||||
|
return {};
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i < bytes.size(); ++i) {
|
for (size_t i = 0; i < bytes.size(); ++i) {
|
||||||
if (width > 0) {
|
if (width > 0) {
|
||||||
if (i % width == 0 && i) {
|
if (i % width == 0 && i) {
|
||||||
put_char_view(i);
|
TRY(put_char_view(i));
|
||||||
put_literal("\n"sv);
|
TRY(put_literal("\n"sv));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
put_u64(bytes[i], 16, false, false, true, Align::Right, 2);
|
TRY(put_u64(bytes[i], 16, false, false, true, Align::Right, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (width > 0 && bytes.size() && bytes.size() % width == 0)
|
if (width > 0 && bytes.size() && bytes.size() % width == 0)
|
||||||
put_char_view(bytes.size());
|
TRY(put_char_view(bytes.size()));
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void vformat(StringBuilder& builder, StringView fmtstr, TypeErasedFormatParams& params)
|
ErrorOr<void> vformat(StringBuilder& builder, StringView fmtstr, TypeErasedFormatParams& params)
|
||||||
{
|
{
|
||||||
FormatBuilder fmtbuilder { builder };
|
FormatBuilder fmtbuilder { builder };
|
||||||
FormatParser parser { fmtstr };
|
FormatParser parser { fmtstr };
|
||||||
|
|
||||||
vformat_impl(params, fmtbuilder, parser);
|
TRY(vformat_impl(params, fmtbuilder, parser));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void StandardFormatter::parse(TypeErasedFormatParams& params, FormatParser& parser)
|
void StandardFormatter::parse(TypeErasedFormatParams& params, FormatParser& parser)
|
||||||
|
@ -588,7 +606,7 @@ void StandardFormatter::parse(TypeErasedFormatParams& params, FormatParser& pars
|
||||||
VERIFY(parser.is_eof());
|
VERIFY(parser.is_eof());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Formatter<StringView>::format(FormatBuilder& builder, StringView value)
|
ErrorOr<void> Formatter<StringView>::format(FormatBuilder& builder, StringView value)
|
||||||
{
|
{
|
||||||
if (m_sign_mode != FormatBuilder::SignMode::Default)
|
if (m_sign_mode != FormatBuilder::SignMode::Default)
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
|
@ -603,20 +621,20 @@ void Formatter<StringView>::format(FormatBuilder& builder, StringView value)
|
||||||
m_precision = m_precision.value_or(NumericLimits<size_t>::max());
|
m_precision = m_precision.value_or(NumericLimits<size_t>::max());
|
||||||
|
|
||||||
if (m_mode == Mode::HexDump)
|
if (m_mode == Mode::HexDump)
|
||||||
builder.put_hexdump(value.bytes(), m_width.value(), m_fill);
|
return builder.put_hexdump(value.bytes(), m_width.value(), m_fill);
|
||||||
else
|
return builder.put_string(value, m_align, m_width.value(), m_precision.value(), m_fill);
|
||||||
builder.put_string(value, m_align, m_width.value(), m_precision.value(), m_fill);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Formatter<FormatString>::vformat(FormatBuilder& builder, StringView fmtstr, TypeErasedFormatParams& params)
|
ErrorOr<void> Formatter<FormatString>::vformat(FormatBuilder& builder, StringView fmtstr, TypeErasedFormatParams& params)
|
||||||
{
|
{
|
||||||
StringBuilder string_builder;
|
StringBuilder string_builder;
|
||||||
AK::vformat(string_builder, fmtstr, params);
|
TRY(AK::vformat(string_builder, fmtstr, params));
|
||||||
return Formatter<StringView>::format(builder, string_builder.string_view());
|
TRY(Formatter<StringView>::format(builder, string_builder.string_view()));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void Formatter<T, typename EnableIf<IsIntegral<T>>::Type>::format(FormatBuilder& builder, T value)
|
ErrorOr<void> Formatter<T, typename EnableIf<IsIntegral<T>>::Type>::format(FormatBuilder& builder, T value)
|
||||||
{
|
{
|
||||||
if (m_mode == Mode::Character) {
|
if (m_mode == Mode::Character) {
|
||||||
// FIXME: We just support ASCII for now, in the future maybe unicode?
|
// FIXME: We just support ASCII for now, in the future maybe unicode?
|
||||||
|
@ -665,8 +683,7 @@ void Formatter<T, typename EnableIf<IsIntegral<T>>::Type>::format(FormatBuilder&
|
||||||
upper_case = true;
|
upper_case = true;
|
||||||
} else if (m_mode == Mode::HexDump) {
|
} else if (m_mode == Mode::HexDump) {
|
||||||
m_width = m_width.value_or(32);
|
m_width = m_width.value_or(32);
|
||||||
builder.put_hexdump({ &value, sizeof(value) }, m_width.value(), m_fill);
|
return builder.put_hexdump({ &value, sizeof(value) }, m_width.value(), m_fill);
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
@ -674,12 +691,12 @@ void Formatter<T, typename EnableIf<IsIntegral<T>>::Type>::format(FormatBuilder&
|
||||||
m_width = m_width.value_or(0);
|
m_width = m_width.value_or(0);
|
||||||
|
|
||||||
if constexpr (IsSame<MakeUnsigned<T>, T>)
|
if constexpr (IsSame<MakeUnsigned<T>, T>)
|
||||||
builder.put_u64(value, base, m_alternative_form, upper_case, m_zero_pad, m_align, m_width.value(), m_fill, m_sign_mode);
|
return builder.put_u64(value, base, m_alternative_form, upper_case, m_zero_pad, m_align, m_width.value(), m_fill, m_sign_mode);
|
||||||
else
|
else
|
||||||
builder.put_i64(value, base, m_alternative_form, upper_case, m_zero_pad, m_align, m_width.value(), m_fill, m_sign_mode);
|
return builder.put_i64(value, base, m_alternative_form, upper_case, m_zero_pad, m_align, m_width.value(), m_fill, m_sign_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Formatter<char>::format(FormatBuilder& builder, char value)
|
ErrorOr<void> Formatter<char>::format(FormatBuilder& builder, char value)
|
||||||
{
|
{
|
||||||
if (m_mode == Mode::Binary || m_mode == Mode::BinaryUppercase || m_mode == Mode::Decimal || m_mode == Mode::Octal || m_mode == Mode::Hexadecimal || m_mode == Mode::HexadecimalUppercase) {
|
if (m_mode == Mode::Binary || m_mode == Mode::BinaryUppercase || m_mode == Mode::Decimal || m_mode == Mode::Octal || m_mode == Mode::Hexadecimal || m_mode == Mode::HexadecimalUppercase) {
|
||||||
// Trick: signed char != char. (Sometimes weird features are actually helpful.)
|
// Trick: signed char != char. (Sometimes weird features are actually helpful.)
|
||||||
|
@ -690,7 +707,7 @@ void Formatter<char>::format(FormatBuilder& builder, char value)
|
||||||
return formatter.format(builder, { &value, 1 });
|
return formatter.format(builder, { &value, 1 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Formatter<wchar_t>::format(FormatBuilder& builder, wchar_t value)
|
ErrorOr<void> Formatter<wchar_t>::format(FormatBuilder& builder, wchar_t value)
|
||||||
{
|
{
|
||||||
if (m_mode == Mode::Binary || m_mode == Mode::BinaryUppercase || m_mode == Mode::Decimal || m_mode == Mode::Octal || m_mode == Mode::Hexadecimal || m_mode == Mode::HexadecimalUppercase) {
|
if (m_mode == Mode::Binary || m_mode == Mode::BinaryUppercase || m_mode == Mode::Decimal || m_mode == Mode::Octal || m_mode == Mode::Hexadecimal || m_mode == Mode::HexadecimalUppercase) {
|
||||||
Formatter<u32> formatter { *this };
|
Formatter<u32> formatter { *this };
|
||||||
|
@ -703,7 +720,7 @@ void Formatter<wchar_t>::format(FormatBuilder& builder, wchar_t value)
|
||||||
return formatter.format(builder, codepoint.to_string());
|
return formatter.format(builder, codepoint.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Formatter<bool>::format(FormatBuilder& builder, bool value)
|
ErrorOr<void> Formatter<bool>::format(FormatBuilder& builder, bool value)
|
||||||
{
|
{
|
||||||
if (m_mode == Mode::Binary || m_mode == Mode::BinaryUppercase || m_mode == Mode::Decimal || m_mode == Mode::Octal || m_mode == Mode::Hexadecimal || m_mode == Mode::HexadecimalUppercase) {
|
if (m_mode == Mode::Binary || m_mode == Mode::BinaryUppercase || m_mode == Mode::Decimal || m_mode == Mode::Octal || m_mode == Mode::Hexadecimal || m_mode == Mode::HexadecimalUppercase) {
|
||||||
Formatter<u8> formatter { *this };
|
Formatter<u8> formatter { *this };
|
||||||
|
@ -716,7 +733,7 @@ void Formatter<bool>::format(FormatBuilder& builder, bool value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
void Formatter<long double>::format(FormatBuilder& builder, long double value)
|
ErrorOr<void> Formatter<long double>::format(FormatBuilder& builder, long double value)
|
||||||
{
|
{
|
||||||
u8 base;
|
u8 base;
|
||||||
bool upper_case;
|
bool upper_case;
|
||||||
|
@ -736,10 +753,10 @@ void Formatter<long double>::format(FormatBuilder& builder, long double value)
|
||||||
m_width = m_width.value_or(0);
|
m_width = m_width.value_or(0);
|
||||||
m_precision = m_precision.value_or(6);
|
m_precision = m_precision.value_or(6);
|
||||||
|
|
||||||
builder.put_f80(value, base, upper_case, m_align, m_width.value(), m_precision.value(), m_fill, m_sign_mode);
|
return builder.put_f80(value, base, upper_case, m_align, m_width.value(), m_precision.value(), m_fill, m_sign_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Formatter<double>::format(FormatBuilder& builder, double value)
|
ErrorOr<void> Formatter<double>::format(FormatBuilder& builder, double value)
|
||||||
{
|
{
|
||||||
u8 base;
|
u8 base;
|
||||||
bool upper_case;
|
bool upper_case;
|
||||||
|
@ -759,12 +776,13 @@ void Formatter<double>::format(FormatBuilder& builder, double value)
|
||||||
m_width = m_width.value_or(0);
|
m_width = m_width.value_or(0);
|
||||||
m_precision = m_precision.value_or(6);
|
m_precision = m_precision.value_or(6);
|
||||||
|
|
||||||
builder.put_f64(value, base, upper_case, m_zero_pad, m_align, m_width.value(), m_precision.value(), m_fill, m_sign_mode);
|
return builder.put_f64(value, base, upper_case, m_zero_pad, m_align, m_width.value(), m_precision.value(), m_fill, m_sign_mode);
|
||||||
}
|
}
|
||||||
void Formatter<float>::format(FormatBuilder& builder, float value)
|
|
||||||
|
ErrorOr<void> Formatter<float>::format(FormatBuilder& builder, float value)
|
||||||
{
|
{
|
||||||
Formatter<double> formatter { *this };
|
Formatter<double> formatter { *this };
|
||||||
formatter.format(builder, value);
|
return formatter.format(builder, value);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -772,7 +790,7 @@ void Formatter<float>::format(FormatBuilder& builder, float value)
|
||||||
void vout(FILE* file, StringView fmtstr, TypeErasedFormatParams& params, bool newline)
|
void vout(FILE* file, StringView fmtstr, TypeErasedFormatParams& params, bool newline)
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
vformat(builder, fmtstr, params);
|
MUST(vformat(builder, fmtstr, params));
|
||||||
|
|
||||||
if (newline)
|
if (newline)
|
||||||
builder.append('\n');
|
builder.append('\n');
|
||||||
|
@ -832,7 +850,7 @@ void vdbgln(StringView fmtstr, TypeErasedFormatParams& params)
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vformat(builder, fmtstr, params);
|
MUST(vformat(builder, fmtstr, params));
|
||||||
builder.append('\n');
|
builder.append('\n');
|
||||||
|
|
||||||
const auto string = builder.string_view();
|
const auto string = builder.string_view();
|
||||||
|
@ -866,7 +884,7 @@ void vdmesgln(StringView fmtstr, TypeErasedFormatParams& params)
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
vformat(builder, fmtstr, params);
|
MUST(vformat(builder, fmtstr, params));
|
||||||
builder.append('\n');
|
builder.append('\n');
|
||||||
|
|
||||||
const auto string = builder.string_view();
|
const auto string = builder.string_view();
|
||||||
|
@ -888,7 +906,7 @@ void v_critical_dmesgln(StringView fmtstr, TypeErasedFormatParams& params)
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
vformat(builder, fmtstr, params);
|
MUST(vformat(builder, fmtstr, params));
|
||||||
builder.append('\n');
|
builder.append('\n');
|
||||||
|
|
||||||
const auto string = builder.string_view();
|
const auto string = builder.string_view();
|
||||||
|
|
115
AK/Format.h
115
AK/Format.h
|
@ -11,6 +11,8 @@
|
||||||
#include <AK/AllOf.h>
|
#include <AK/AllOf.h>
|
||||||
#include <AK/AnyOf.h>
|
#include <AK/AnyOf.h>
|
||||||
#include <AK/Array.h>
|
#include <AK/Array.h>
|
||||||
|
#include <AK/Error.h>
|
||||||
|
#include <AK/Forward.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
|
|
||||||
|
@ -125,7 +127,7 @@ struct TypeErasedParameter {
|
||||||
|
|
||||||
const void* value;
|
const void* value;
|
||||||
Type type;
|
Type type;
|
||||||
void (*formatter)(TypeErasedFormatParams&, FormatBuilder&, FormatParser&, const void* value);
|
ErrorOr<void> (*formatter)(TypeErasedFormatParams&, FormatBuilder&, FormatParser&, void const* value);
|
||||||
};
|
};
|
||||||
|
|
||||||
class FormatBuilder {
|
class FormatBuilder {
|
||||||
|
@ -148,18 +150,18 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void put_padding(char fill, size_t amount);
|
ErrorOr<void> put_padding(char fill, size_t amount);
|
||||||
|
|
||||||
void put_literal(StringView value);
|
ErrorOr<void> put_literal(StringView value);
|
||||||
|
|
||||||
void put_string(
|
ErrorOr<void> put_string(
|
||||||
StringView value,
|
StringView value,
|
||||||
Align align = Align::Left,
|
Align align = Align::Left,
|
||||||
size_t min_width = 0,
|
size_t min_width = 0,
|
||||||
size_t max_width = NumericLimits<size_t>::max(),
|
size_t max_width = NumericLimits<size_t>::max(),
|
||||||
char fill = ' ');
|
char fill = ' ');
|
||||||
|
|
||||||
void put_u64(
|
ErrorOr<void> put_u64(
|
||||||
u64 value,
|
u64 value,
|
||||||
u8 base = 10,
|
u8 base = 10,
|
||||||
bool prefix = false,
|
bool prefix = false,
|
||||||
|
@ -171,7 +173,7 @@ public:
|
||||||
SignMode sign_mode = SignMode::OnlyIfNeeded,
|
SignMode sign_mode = SignMode::OnlyIfNeeded,
|
||||||
bool is_negative = false);
|
bool is_negative = false);
|
||||||
|
|
||||||
void put_i64(
|
ErrorOr<void> put_i64(
|
||||||
i64 value,
|
i64 value,
|
||||||
u8 base = 10,
|
u8 base = 10,
|
||||||
bool prefix = false,
|
bool prefix = false,
|
||||||
|
@ -183,7 +185,7 @@ public:
|
||||||
SignMode sign_mode = SignMode::OnlyIfNeeded);
|
SignMode sign_mode = SignMode::OnlyIfNeeded);
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
void put_f80(
|
ErrorOr<void> put_f80(
|
||||||
long double value,
|
long double value,
|
||||||
u8 base = 10,
|
u8 base = 10,
|
||||||
bool upper_case = false,
|
bool upper_case = false,
|
||||||
|
@ -193,7 +195,7 @@ public:
|
||||||
char fill = ' ',
|
char fill = ' ',
|
||||||
SignMode sign_mode = SignMode::OnlyIfNeeded);
|
SignMode sign_mode = SignMode::OnlyIfNeeded);
|
||||||
|
|
||||||
void put_f64(
|
ErrorOr<void> put_f64(
|
||||||
double value,
|
double value,
|
||||||
u8 base = 10,
|
u8 base = 10,
|
||||||
bool upper_case = false,
|
bool upper_case = false,
|
||||||
|
@ -205,7 +207,7 @@ public:
|
||||||
SignMode sign_mode = SignMode::OnlyIfNeeded);
|
SignMode sign_mode = SignMode::OnlyIfNeeded);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void put_hexdump(
|
ErrorOr<void> put_hexdump(
|
||||||
ReadonlyBytes,
|
ReadonlyBytes,
|
||||||
size_t width,
|
size_t width,
|
||||||
char fill = ' ');
|
char fill = ' ');
|
||||||
|
@ -233,12 +235,12 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void __format_value(TypeErasedFormatParams& params, FormatBuilder& builder, FormatParser& parser, const void* value)
|
ErrorOr<void> __format_value(TypeErasedFormatParams& params, FormatBuilder& builder, FormatParser& parser, const void* value)
|
||||||
{
|
{
|
||||||
Formatter<T> formatter;
|
Formatter<T> formatter;
|
||||||
|
|
||||||
formatter.parse(params, parser);
|
formatter.parse(params, parser);
|
||||||
formatter.format(builder, *static_cast<const T*>(value));
|
return formatter.format(builder, *static_cast<const T*>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Parameters>
|
template<typename... Parameters>
|
||||||
|
@ -298,7 +300,7 @@ struct Formatter<T, typename EnableIf<IsIntegral<T>>::Type> : StandardFormatter
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void format(FormatBuilder&, T value);
|
ErrorOr<void> format(FormatBuilder&, T);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
@ -309,7 +311,7 @@ struct Formatter<StringView> : StandardFormatter {
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void format(FormatBuilder&, StringView value);
|
ErrorOr<void> format(FormatBuilder&, StringView);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -320,12 +322,12 @@ requires(HasFormatter<T>) struct Formatter<Vector<T>> : StandardFormatter {
|
||||||
: StandardFormatter(move(formatter))
|
: StandardFormatter(move(formatter))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void format(FormatBuilder& builder, Vector<T> value)
|
ErrorOr<void> format(FormatBuilder& builder, Vector<T> value)
|
||||||
{
|
{
|
||||||
if (m_mode == Mode::Pointer) {
|
if (m_mode == Mode::Pointer) {
|
||||||
Formatter<FlatPtr> formatter { *this };
|
Formatter<FlatPtr> formatter { *this };
|
||||||
formatter.format(builder, reinterpret_cast<FlatPtr>(value.data()));
|
TRY(formatter.format(builder, reinterpret_cast<FlatPtr>(value.data())));
|
||||||
return;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_sign_mode != FormatBuilder::SignMode::Default)
|
if (m_sign_mode != FormatBuilder::SignMode::Default)
|
||||||
|
@ -343,33 +345,34 @@ requires(HasFormatter<T>) struct Formatter<Vector<T>> : StandardFormatter {
|
||||||
m_precision = m_precision.value_or(NumericLimits<size_t>::max());
|
m_precision = m_precision.value_or(NumericLimits<size_t>::max());
|
||||||
|
|
||||||
Formatter<T> content_fmt;
|
Formatter<T> content_fmt;
|
||||||
builder.put_literal("[ "sv);
|
TRY(builder.put_literal("[ "sv));
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto& content : value) {
|
for (auto& content : value) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
builder.put_literal(", "sv);
|
TRY(builder.put_literal(", "sv));
|
||||||
content_fmt = Formatter<T> {};
|
content_fmt = Formatter<T> {};
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
content_fmt.format(builder, content);
|
TRY(content_fmt.format(builder, content));
|
||||||
}
|
}
|
||||||
builder.put_literal(" ]"sv);
|
TRY(builder.put_literal(" ]"sv));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<ReadonlyBytes> : Formatter<StringView> {
|
struct Formatter<ReadonlyBytes> : Formatter<StringView> {
|
||||||
void format(FormatBuilder& builder, ReadonlyBytes value)
|
ErrorOr<void> format(FormatBuilder& builder, ReadonlyBytes value)
|
||||||
{
|
{
|
||||||
if (m_mode == Mode::Pointer) {
|
if (m_mode == Mode::Pointer) {
|
||||||
Formatter<FlatPtr> formatter { *this };
|
Formatter<FlatPtr> formatter { *this };
|
||||||
formatter.format(builder, reinterpret_cast<FlatPtr>(value.data()));
|
return formatter.format(builder, reinterpret_cast<FlatPtr>(value.data()));
|
||||||
} else if (m_mode == Mode::Default || m_mode == Mode::HexDump) {
|
|
||||||
m_mode = Mode::HexDump;
|
|
||||||
Formatter<StringView>::format(builder, value);
|
|
||||||
} else {
|
|
||||||
Formatter<StringView>::format(builder, value);
|
|
||||||
}
|
}
|
||||||
|
if (m_mode == Mode::Default || m_mode == Mode::HexDump) {
|
||||||
|
m_mode = Mode::HexDump;
|
||||||
|
return Formatter<StringView>::format(builder, value);
|
||||||
|
}
|
||||||
|
return Formatter<StringView>::format(builder, value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -379,14 +382,13 @@ struct Formatter<Bytes> : Formatter<ReadonlyBytes> {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<const char*> : Formatter<StringView> {
|
struct Formatter<const char*> : Formatter<StringView> {
|
||||||
void format(FormatBuilder& builder, const char* value)
|
ErrorOr<void> format(FormatBuilder& builder, const char* value)
|
||||||
{
|
{
|
||||||
if (m_mode == Mode::Pointer) {
|
if (m_mode == Mode::Pointer) {
|
||||||
Formatter<FlatPtr> formatter { *this };
|
Formatter<FlatPtr> formatter { *this };
|
||||||
formatter.format(builder, reinterpret_cast<FlatPtr>(value));
|
return formatter.format(builder, reinterpret_cast<FlatPtr>(value));
|
||||||
} else {
|
|
||||||
Formatter<StringView>::format(builder, value);
|
|
||||||
}
|
}
|
||||||
|
return Formatter<StringView>::format(builder, value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
template<>
|
template<>
|
||||||
|
@ -397,14 +399,13 @@ struct Formatter<char[Size]> : Formatter<const char*> {
|
||||||
};
|
};
|
||||||
template<size_t Size>
|
template<size_t Size>
|
||||||
struct Formatter<unsigned char[Size]> : Formatter<StringView> {
|
struct Formatter<unsigned char[Size]> : Formatter<StringView> {
|
||||||
void format(FormatBuilder& builder, const unsigned char* value)
|
ErrorOr<void> format(FormatBuilder& builder, const unsigned char* value)
|
||||||
{
|
{
|
||||||
if (m_mode == Mode::Pointer) {
|
if (m_mode == Mode::Pointer) {
|
||||||
Formatter<FlatPtr> formatter { *this };
|
Formatter<FlatPtr> formatter { *this };
|
||||||
formatter.format(builder, reinterpret_cast<FlatPtr>(value));
|
return formatter.format(builder, reinterpret_cast<FlatPtr>(value));
|
||||||
} else {
|
|
||||||
Formatter<StringView>::format(builder, { value, Size });
|
|
||||||
}
|
}
|
||||||
|
Formatter<StringView>::format(builder, { value, Size });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
template<>
|
template<>
|
||||||
|
@ -416,33 +417,33 @@ struct Formatter<FlyString> : Formatter<StringView> {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Formatter<T*> : StandardFormatter {
|
struct Formatter<T*> : StandardFormatter {
|
||||||
void format(FormatBuilder& builder, T* value)
|
ErrorOr<void> format(FormatBuilder& builder, T* value)
|
||||||
{
|
{
|
||||||
if (m_mode == Mode::Default)
|
if (m_mode == Mode::Default)
|
||||||
m_mode = Mode::Pointer;
|
m_mode = Mode::Pointer;
|
||||||
|
|
||||||
Formatter<FlatPtr> formatter { *this };
|
Formatter<FlatPtr> formatter { *this };
|
||||||
formatter.format(builder, reinterpret_cast<FlatPtr>(value));
|
return formatter.format(builder, reinterpret_cast<FlatPtr>(value));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<char> : StandardFormatter {
|
struct Formatter<char> : StandardFormatter {
|
||||||
void format(FormatBuilder&, char value);
|
ErrorOr<void> format(FormatBuilder&, char);
|
||||||
};
|
};
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<wchar_t> : StandardFormatter {
|
struct Formatter<wchar_t> : StandardFormatter {
|
||||||
void format(FormatBuilder& builder, wchar_t value);
|
ErrorOr<void> format(FormatBuilder& builder, wchar_t);
|
||||||
};
|
};
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<bool> : StandardFormatter {
|
struct Formatter<bool> : StandardFormatter {
|
||||||
void format(FormatBuilder&, bool value);
|
ErrorOr<void> format(FormatBuilder&, bool);
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<float> : StandardFormatter {
|
struct Formatter<float> : StandardFormatter {
|
||||||
void format(FormatBuilder&, float value);
|
ErrorOr<void> format(FormatBuilder&, float value);
|
||||||
};
|
};
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<double> : StandardFormatter {
|
struct Formatter<double> : StandardFormatter {
|
||||||
|
@ -452,7 +453,7 @@ struct Formatter<double> : StandardFormatter {
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void format(FormatBuilder&, double value);
|
ErrorOr<void> format(FormatBuilder&, double);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
@ -463,13 +464,13 @@ struct Formatter<long double> : StandardFormatter {
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void format(FormatBuilder&, long double value);
|
ErrorOr<void> format(FormatBuilder&, long double value);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<std::nullptr_t> : Formatter<FlatPtr> {
|
struct Formatter<std::nullptr_t> : Formatter<FlatPtr> {
|
||||||
void format(FormatBuilder& builder, std::nullptr_t)
|
ErrorOr<void> format(FormatBuilder& builder, std::nullptr_t)
|
||||||
{
|
{
|
||||||
if (m_mode == Mode::Default)
|
if (m_mode == Mode::Default)
|
||||||
m_mode = Mode::Pointer;
|
m_mode = Mode::Pointer;
|
||||||
|
@ -478,7 +479,7 @@ struct Formatter<std::nullptr_t> : Formatter<FlatPtr> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void vformat(StringBuilder&, StringView fmtstr, TypeErasedFormatParams&);
|
ErrorOr<void> vformat(StringBuilder&, StringView fmtstr, TypeErasedFormatParams&);
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
void vout(FILE*, StringView fmtstr, TypeErasedFormatParams&, bool newline = false);
|
void vout(FILE*, StringView fmtstr, TypeErasedFormatParams&, bool newline = false);
|
||||||
|
@ -582,16 +583,16 @@ private:
|
||||||
};
|
};
|
||||||
template<typename T, bool Supported = false>
|
template<typename T, bool Supported = false>
|
||||||
struct __FormatIfSupported : Formatter<StringView> {
|
struct __FormatIfSupported : Formatter<StringView> {
|
||||||
void format(FormatBuilder& builder, const FormatIfSupported<T>&)
|
ErrorOr<void> format(FormatBuilder& builder, FormatIfSupported<T> const&)
|
||||||
{
|
{
|
||||||
Formatter<StringView>::format(builder, "?");
|
return Formatter<StringView>::format(builder, "?");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct __FormatIfSupported<T, true> : Formatter<T> {
|
struct __FormatIfSupported<T, true> : Formatter<T> {
|
||||||
void format(FormatBuilder& builder, const FormatIfSupported<T>& value)
|
ErrorOr<void> format(FormatBuilder& builder, FormatIfSupported<T> const& value)
|
||||||
{
|
{
|
||||||
Formatter<T>::format(builder, value.value());
|
return Formatter<T>::format(builder, value.value());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -605,12 +606,22 @@ struct FormatString {
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<FormatString> : Formatter<StringView> {
|
struct Formatter<FormatString> : Formatter<StringView> {
|
||||||
template<typename... Parameters>
|
template<typename... Parameters>
|
||||||
void format(FormatBuilder& builder, StringView fmtstr, const Parameters&... parameters)
|
ErrorOr<void> format(FormatBuilder& builder, StringView fmtstr, const Parameters&... parameters)
|
||||||
{
|
{
|
||||||
VariadicFormatParams variadic_format_params { parameters... };
|
VariadicFormatParams variadic_format_params { parameters... };
|
||||||
vformat(builder, fmtstr, variadic_format_params);
|
return vformat(builder, fmtstr, variadic_format_params);
|
||||||
|
}
|
||||||
|
ErrorOr<void> vformat(FormatBuilder& builder, StringView fmtstr, TypeErasedFormatParams& params);
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct Formatter<Error> : Formatter<FormatString> {
|
||||||
|
ErrorOr<void> format(FormatBuilder& builder, Error const& error)
|
||||||
|
{
|
||||||
|
if (error.is_errno())
|
||||||
|
return Formatter<FormatString>::format(builder, "Error(errno={})", error.code());
|
||||||
|
return Formatter<FormatString>::format(builder, "Error({})", error.string_literal());
|
||||||
}
|
}
|
||||||
void vformat(FormatBuilder& builder, StringView fmtstr, TypeErasedFormatParams& params);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace AK
|
} // namespace AK
|
||||||
|
|
|
@ -133,7 +133,7 @@ struct Traits<IPv4Address> : public GenericTraits<IPv4Address> {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<IPv4Address> : Formatter<String> {
|
struct Formatter<IPv4Address> : Formatter<String> {
|
||||||
void format(FormatBuilder& builder, IPv4Address value)
|
ErrorOr<void> format(FormatBuilder& builder, IPv4Address value)
|
||||||
{
|
{
|
||||||
return Formatter<String>::format(builder, value.to_string());
|
return Formatter<String>::format(builder, value.to_string());
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,9 +245,9 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<JsonValue> : Formatter<StringView> {
|
struct Formatter<JsonValue> : Formatter<StringView> {
|
||||||
void format(FormatBuilder& builder, const JsonValue& value)
|
ErrorOr<void> format(FormatBuilder& builder, JsonValue const& value)
|
||||||
{
|
{
|
||||||
Formatter<StringView>::format(builder, value.to_string());
|
return Formatter<StringView>::format(builder, value.to_string());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -81,9 +81,9 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<LexicalPath> : Formatter<StringView> {
|
struct Formatter<LexicalPath> : Formatter<StringView> {
|
||||||
void format(FormatBuilder& builder, LexicalPath const& value)
|
ErrorOr<void> format(FormatBuilder& builder, LexicalPath const& value)
|
||||||
{
|
{
|
||||||
Formatter<StringView>::format(builder, value.string());
|
return Formatter<StringView>::format(builder, value.string());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -190,9 +190,9 @@ inline void swap(NonnullOwnPtr<T>& a, NonnullOwnPtr<U>& b)
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Formatter<NonnullOwnPtr<T>> : Formatter<const T*> {
|
struct Formatter<NonnullOwnPtr<T>> : Formatter<const T*> {
|
||||||
void format(FormatBuilder& builder, const NonnullOwnPtr<T>& value)
|
ErrorOr<void> format(FormatBuilder& builder, NonnullOwnPtr<T> const& value)
|
||||||
{
|
{
|
||||||
Formatter<const T*>::format(builder, value.ptr());
|
return Formatter<const T*>::format(builder, value.ptr());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -237,9 +237,9 @@ inline NonnullRefPtr<T> adopt_ref(T& object)
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Formatter<NonnullRefPtr<T>> : Formatter<const T*> {
|
struct Formatter<NonnullRefPtr<T>> : Formatter<const T*> {
|
||||||
void format(FormatBuilder& builder, const NonnullRefPtr<T>& value)
|
ErrorOr<void> format(FormatBuilder& builder, NonnullRefPtr<T> const& value)
|
||||||
{
|
{
|
||||||
Formatter<const T*>::format(builder, value.ptr());
|
return Formatter<const T*>::format(builder, value.ptr());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -295,9 +295,9 @@ private:
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Formatter<RefPtr<T>> : Formatter<const T*> {
|
struct Formatter<RefPtr<T>> : Formatter<const T*> {
|
||||||
void format(FormatBuilder& builder, const RefPtr<T>& value)
|
ErrorOr<void> format(FormatBuilder& builder, RefPtr<T> const& value)
|
||||||
{
|
{
|
||||||
Formatter<const T*>::format(builder, value.ptr());
|
return Formatter<const T*>::format(builder, value.ptr());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<AK::SourceLocation> : AK::Formatter<FormatString> {
|
struct AK::Formatter<AK::SourceLocation> : AK::Formatter<FormatString> {
|
||||||
void format(FormatBuilder& builder, AK::SourceLocation location)
|
ErrorOr<void> format(FormatBuilder& builder, AK::SourceLocation location)
|
||||||
{
|
{
|
||||||
return AK::Formatter<FormatString>::format(builder, "[{} @ {}:{}]", location.function_name(), location.filename(), location.line_number());
|
return AK::Formatter<FormatString>::format(builder, "[{} @ {}:{}]", location.function_name(), location.filename(), location.line_number());
|
||||||
}
|
}
|
||||||
|
|
|
@ -475,7 +475,7 @@ InputStream& operator>>(InputStream& stream, String& string)
|
||||||
String String::vformatted(StringView fmtstr, TypeErasedFormatParams& params)
|
String String::vformatted(StringView fmtstr, TypeErasedFormatParams& params)
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
vformat(builder, fmtstr, params);
|
MUST(vformat(builder, fmtstr, params));
|
||||||
return builder.to_string();
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
void appendff(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
|
void appendff(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
|
||||||
{
|
{
|
||||||
VariadicFormatParams variadic_format_params { parameters... };
|
VariadicFormatParams variadic_format_params { parameters... };
|
||||||
vformat(*this, fmtstr.view(), variadic_format_params);
|
MUST(vformat(*this, fmtstr.view(), variadic_format_params));
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] String build() const;
|
[[nodiscard]] String build() const;
|
||||||
|
|
|
@ -109,9 +109,9 @@ inline size_t allocation_size_for_stringimpl(size_t length)
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<StringImpl> : Formatter<StringView> {
|
struct Formatter<StringImpl> : Formatter<StringView> {
|
||||||
void format(FormatBuilder& builder, const StringImpl& value)
|
ErrorOr<void> format(FormatBuilder& builder, StringImpl const& value)
|
||||||
{
|
{
|
||||||
Formatter<StringView>::format(builder, { value.characters(), value.length() });
|
return Formatter<StringView>::format(builder, { value.characters(), value.length() });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -714,7 +714,7 @@ struct Formatter<UFixedBigInt<T>> : StandardFormatter {
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void format(FormatBuilder& builder, UFixedBigInt<T> value)
|
ErrorOr<void> format(FormatBuilder& builder, UFixedBigInt<T> value)
|
||||||
{
|
{
|
||||||
if (m_precision.has_value())
|
if (m_precision.has_value())
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
|
@ -751,12 +751,13 @@ struct Formatter<UFixedBigInt<T>> : StandardFormatter {
|
||||||
ssize_t lower_length = ceil_div(sizeof(T) * 8, (ssize_t)base);
|
ssize_t lower_length = ceil_div(sizeof(T) * 8, (ssize_t)base);
|
||||||
Formatter<T> formatter { *this };
|
Formatter<T> formatter { *this };
|
||||||
formatter.m_width = max(width - lower_length, (ssize_t)0);
|
formatter.m_width = max(width - lower_length, (ssize_t)0);
|
||||||
formatter.format(builder, value.high());
|
TRY(formatter.format(builder, value.high()));
|
||||||
builder.put_literal("'"sv);
|
TRY(builder.put_literal("'"sv));
|
||||||
formatter.m_zero_pad = true;
|
formatter.m_zero_pad = true;
|
||||||
formatter.m_alternative_form = false;
|
formatter.m_alternative_form = false;
|
||||||
formatter.m_width = lower_length;
|
formatter.m_width = lower_length;
|
||||||
formatter.format(builder, value.low());
|
TRY(formatter.format(builder, value.low()));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
4
AK/URL.h
4
AK/URL.h
|
@ -147,9 +147,9 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<URL> : Formatter<StringView> {
|
struct Formatter<URL> : Formatter<StringView> {
|
||||||
void format(FormatBuilder& builder, URL const& value)
|
ErrorOr<void> format(FormatBuilder& builder, URL const& value)
|
||||||
{
|
{
|
||||||
Formatter<StringView>::format(builder, value.serialize());
|
return Formatter<StringView>::format(builder, value.serialize());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -123,9 +123,9 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<AK::Utf16View> : Formatter<FormatString> {
|
struct AK::Formatter<AK::Utf16View> : Formatter<FormatString> {
|
||||||
void format(FormatBuilder& builder, AK::Utf16View const& value)
|
ErrorOr<void> format(FormatBuilder& builder, AK::Utf16View const& value)
|
||||||
{
|
{
|
||||||
return builder.builder().append(value);
|
return builder.builder().try_append(value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -191,9 +191,9 @@ inline WeakPtr<U> Weakable<T>::make_weak_ptr() const
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Formatter<WeakPtr<T>> : Formatter<const T*> {
|
struct Formatter<WeakPtr<T>> : Formatter<const T*> {
|
||||||
void format(FormatBuilder& builder, const WeakPtr<T>& value)
|
ErrorOr<void> format(FormatBuilder& builder, WeakPtr<T> const& value)
|
||||||
{
|
{
|
||||||
Formatter<const T*>::format(builder, value.ptr());
|
return Formatter<const T*>::format(builder, value.ptr());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<IOAddress> : AK::Formatter<FormatString> {
|
struct AK::Formatter<IOAddress> : AK::Formatter<FormatString> {
|
||||||
void format(FormatBuilder& builder, IOAddress value)
|
ErrorOr<void> format(FormatBuilder& builder, IOAddress value)
|
||||||
{
|
{
|
||||||
return Formatter<FormatString>::format(builder, "IO {:x}", value.get());
|
return Formatter<FormatString>::format(builder, "IO {:x}", value.get());
|
||||||
}
|
}
|
||||||
|
|
|
@ -298,7 +298,7 @@ class Device;
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<Kernel::PCI::Address> : Formatter<FormatString> {
|
struct AK::Formatter<Kernel::PCI::Address> : Formatter<FormatString> {
|
||||||
void format(FormatBuilder& builder, Kernel::PCI::Address value)
|
ErrorOr<void> format(FormatBuilder& builder, Kernel::PCI::Address value)
|
||||||
{
|
{
|
||||||
return Formatter<FormatString>::format(
|
return Formatter<FormatString>::format(
|
||||||
builder,
|
builder,
|
||||||
|
@ -308,7 +308,7 @@ struct AK::Formatter<Kernel::PCI::Address> : Formatter<FormatString> {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<Kernel::PCI::HardwareID> : Formatter<FormatString> {
|
struct AK::Formatter<Kernel::PCI::HardwareID> : Formatter<FormatString> {
|
||||||
void format(FormatBuilder& builder, Kernel::PCI::HardwareID value)
|
ErrorOr<void> format(FormatBuilder& builder, Kernel::PCI::HardwareID value)
|
||||||
{
|
{
|
||||||
return Formatter<FormatString>::format(
|
return Formatter<FormatString>::format(
|
||||||
builder,
|
builder,
|
||||||
|
|
|
@ -53,7 +53,7 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<Kernel::InodeIdentifier> : AK::Formatter<FormatString> {
|
struct AK::Formatter<Kernel::InodeIdentifier> : AK::Formatter<FormatString> {
|
||||||
void format(FormatBuilder& builder, Kernel::InodeIdentifier value)
|
ErrorOr<void> format(FormatBuilder& builder, Kernel::InodeIdentifier value)
|
||||||
{
|
{
|
||||||
return AK::Formatter<FormatString>::format(builder, "{}:{}", value.fsid(), value.index());
|
return AK::Formatter<FormatString>::format(builder, "{}:{}", value.fsid(), value.index());
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
// FIXME: This really not ideal, but vformat expects StringBuilder.
|
// FIXME: This really not ideal, but vformat expects StringBuilder.
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
AK::VariadicFormatParams variadic_format_params { parameters... };
|
AK::VariadicFormatParams variadic_format_params { parameters... };
|
||||||
vformat(builder, fmtstr.view(), variadic_format_params);
|
TRY(vformat(builder, fmtstr.view(), variadic_format_params));
|
||||||
return append_bytes(builder.string_view().bytes());
|
return append_bytes(builder.string_view().bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,28 +46,27 @@ namespace AK {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<Kernel::KString> : Formatter<StringView> {
|
struct Formatter<Kernel::KString> : Formatter<StringView> {
|
||||||
void format(FormatBuilder& builder, Kernel::KString const& value)
|
ErrorOr<void> format(FormatBuilder& builder, Kernel::KString const& value)
|
||||||
{
|
{
|
||||||
Formatter<StringView>::format(builder, value.view());
|
return Formatter<StringView>::format(builder, value.view());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<OwnPtr<Kernel::KString>> : Formatter<StringView> {
|
struct Formatter<OwnPtr<Kernel::KString>> : Formatter<StringView> {
|
||||||
void format(FormatBuilder& builder, OwnPtr<Kernel::KString> const& value)
|
ErrorOr<void> format(FormatBuilder& builder, OwnPtr<Kernel::KString> const& value)
|
||||||
{
|
{
|
||||||
if (value)
|
if (value)
|
||||||
Formatter<StringView>::format(builder, value->view());
|
return Formatter<StringView>::format(builder, value->view());
|
||||||
else
|
return Formatter<StringView>::format(builder, "[out of memory]"sv);
|
||||||
Formatter<StringView>::format(builder, "[out of memory]"sv);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<NonnullOwnPtr<Kernel::KString>> : Formatter<StringView> {
|
struct Formatter<NonnullOwnPtr<Kernel::KString>> : Formatter<StringView> {
|
||||||
void format(FormatBuilder& builder, NonnullOwnPtr<Kernel::KString> const& value)
|
ErrorOr<void> format(FormatBuilder& builder, NonnullOwnPtr<Kernel::KString> const& value)
|
||||||
{
|
{
|
||||||
Formatter<StringView>::format(builder, value->view());
|
return Formatter<StringView>::format(builder, value->view());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -322,9 +322,9 @@ inline NonnullRefPtr<T> adopt_ref(T& object)
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Formatter<NonnullRefPtr<T>> : Formatter<const T*> {
|
struct Formatter<NonnullRefPtr<T>> : Formatter<const T*> {
|
||||||
void format(FormatBuilder& builder, const NonnullRefPtr<T>& value)
|
ErrorOr<void> format(FormatBuilder& builder, const NonnullRefPtr<T>& value)
|
||||||
{
|
{
|
||||||
Formatter<const T*>::format(builder, value.ptr());
|
return Formatter<const T*>::format(builder, value.ptr());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -445,9 +445,9 @@ private:
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Formatter<RefPtr<T>> : Formatter<const T*> {
|
struct Formatter<RefPtr<T>> : Formatter<const T*> {
|
||||||
void format(FormatBuilder& builder, const RefPtr<T>& value)
|
ErrorOr<void> format(FormatBuilder& builder, RefPtr<T> const& value)
|
||||||
{
|
{
|
||||||
Formatter<const T*>::format(builder, value.ptr());
|
return Formatter<const T*>::format(builder, value.ptr());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -217,13 +217,13 @@ inline WeakPtr<U> Weakable<T>::make_weak_ptr() const
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Formatter<WeakPtr<T>> : Formatter<const T*> {
|
struct Formatter<WeakPtr<T>> : Formatter<const T*> {
|
||||||
void format(FormatBuilder& builder, const WeakPtr<T>& value)
|
ErrorOr<void> format(FormatBuilder& builder, WeakPtr<T> const& value)
|
||||||
{
|
{
|
||||||
#ifdef KERNEL
|
#ifdef KERNEL
|
||||||
auto ref = value.strong_ref();
|
auto ref = value.strong_ref();
|
||||||
Formatter<const T*>::format(builder, ref.ptr());
|
return Formatter<const T*>::format(builder, ref.ptr());
|
||||||
#else
|
#else
|
||||||
Formatter<const T*>::format(builder, value.ptr());
|
return Formatter<const T*>::format(builder, value.ptr());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,7 +62,7 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<Kernel::Memory::VirtualRange> : Formatter<FormatString> {
|
struct AK::Formatter<Kernel::Memory::VirtualRange> : Formatter<FormatString> {
|
||||||
void format(FormatBuilder& builder, Kernel::Memory::VirtualRange value)
|
ErrorOr<void> format(FormatBuilder& builder, Kernel::Memory::VirtualRange value)
|
||||||
{
|
{
|
||||||
return Formatter<FormatString>::format(builder, "{} - {} (size {:p})", value.base().as_ptr(), value.base().offset(value.size() - 1).as_ptr(), value.size());
|
return Formatter<FormatString>::format(builder, "{} - {} (size {:p})", value.base().as_ptr(), value.base().offset(value.size() - 1).as_ptr(), value.size());
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<PhysicalAddress> : AK::Formatter<FormatString> {
|
struct AK::Formatter<PhysicalAddress> : AK::Formatter<FormatString> {
|
||||||
void format(FormatBuilder& builder, PhysicalAddress value)
|
ErrorOr<void> format(FormatBuilder& builder, PhysicalAddress value)
|
||||||
{
|
{
|
||||||
if constexpr (sizeof(PhysicalPtr) == sizeof(u64))
|
if constexpr (sizeof(PhysicalPtr) == sizeof(u64))
|
||||||
return AK::Formatter<FormatString>::format(builder, "P{:016x}", value.get());
|
return AK::Formatter<FormatString>::format(builder, "P{:016x}", value.get());
|
||||||
|
|
|
@ -980,7 +980,7 @@ inline static ErrorOr<NonnullOwnPtr<KString>> try_copy_kstring_from_user(const K
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<Kernel::Process> : AK::Formatter<FormatString> {
|
struct AK::Formatter<Kernel::Process> : AK::Formatter<FormatString> {
|
||||||
void format(FormatBuilder& builder, const Kernel::Process& value)
|
ErrorOr<void> format(FormatBuilder& builder, Kernel::Process const& value)
|
||||||
{
|
{
|
||||||
return AK::Formatter<FormatString>::format(builder, "{}({})", value.name(), value.pid().value());
|
return AK::Formatter<FormatString>::format(builder, "{}({})", value.name(), value.pid().value());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1279,7 +1279,7 @@ void Thread::track_lock_release(LockRank rank)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AK::Formatter<Kernel::Thread>::format(FormatBuilder& builder, const Kernel::Thread& value)
|
ErrorOr<void> AK::Formatter<Kernel::Thread>::format(FormatBuilder& builder, Kernel::Thread const& value)
|
||||||
{
|
{
|
||||||
return AK::Formatter<FormatString>::format(
|
return AK::Formatter<FormatString>::format(
|
||||||
builder,
|
builder,
|
||||||
|
|
|
@ -1432,5 +1432,5 @@ inline IterationDecision Thread::for_each_in_state(State state, Callback callbac
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<Kernel::Thread> : AK::Formatter<FormatString> {
|
struct AK::Formatter<Kernel::Thread> : AK::Formatter<FormatString> {
|
||||||
void format(FormatBuilder&, const Kernel::Thread&);
|
ErrorOr<void> format(FormatBuilder&, Kernel::Thread const&);
|
||||||
};
|
};
|
||||||
|
|
|
@ -54,7 +54,7 @@ inline VirtualAddress operator-(const VirtualAddress& a, const VirtualAddress& b
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<VirtualAddress> : AK::Formatter<FormatString> {
|
struct AK::Formatter<VirtualAddress> : AK::Formatter<FormatString> {
|
||||||
void format(FormatBuilder& builder, const VirtualAddress& value)
|
ErrorOr<void> format(FormatBuilder& builder, const VirtualAddress& value)
|
||||||
{
|
{
|
||||||
return AK::Formatter<FormatString>::format(builder, "V{}", value.as_ptr());
|
return AK::Formatter<FormatString>::format(builder, "V{}", value.as_ptr());
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,9 +201,9 @@ struct B {
|
||||||
};
|
};
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<B> : Formatter<StringView> {
|
struct AK::Formatter<B> : Formatter<StringView> {
|
||||||
void format(FormatBuilder& builder, B)
|
ErrorOr<void> format(FormatBuilder& builder, B)
|
||||||
{
|
{
|
||||||
Formatter<StringView>::format(builder, "B");
|
return Formatter<StringView>::format(builder, "B");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ struct C {
|
||||||
};
|
};
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<C> : AK::Formatter<FormatString> {
|
struct AK::Formatter<C> : AK::Formatter<FormatString> {
|
||||||
void format(FormatBuilder& builder, C c)
|
ErrorOr<void> format(FormatBuilder& builder, C c)
|
||||||
{
|
{
|
||||||
return AK::Formatter<FormatString>::format(builder, "C(i={})", c.i);
|
return AK::Formatter<FormatString>::format(builder, "C(i={})", c.i);
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ TEST_CASE(long_long_regression)
|
||||||
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
AK::FormatBuilder fmtbuilder { builder };
|
AK::FormatBuilder fmtbuilder { builder };
|
||||||
fmtbuilder.put_i64(0x0123456789abcdefLL);
|
MUST(fmtbuilder.put_i64(0x0123456789abcdefLL));
|
||||||
|
|
||||||
EXPECT_EQ(builder.string_view(), "81985529216486895");
|
EXPECT_EQ(builder.string_view(), "81985529216486895");
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,15 +128,16 @@ union Extractor {
|
||||||
namespace AK {
|
namespace AK {
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<Extractor> : StandardFormatter {
|
struct Formatter<Extractor> : StandardFormatter {
|
||||||
void format(FormatBuilder& builder, const Extractor& value)
|
ErrorOr<void> format(FormatBuilder& builder, Extractor const& value)
|
||||||
{
|
{
|
||||||
builder.put_literal("{");
|
TRY(builder.put_literal("{"));
|
||||||
builder.put_u64(value.sign);
|
TRY(builder.put_u64(value.sign));
|
||||||
builder.put_literal(", ");
|
TRY(builder.put_literal(", "));
|
||||||
builder.put_u64(value.exponent, 16, true);
|
TRY(builder.put_u64(value.exponent, 16, true));
|
||||||
builder.put_literal(", ");
|
TRY(builder.put_literal(", "));
|
||||||
builder.put_u64(value.mantissa, 16, true);
|
TRY(builder.put_u64(value.mantissa, 16, true));
|
||||||
builder.put_literal("}");
|
TRY(builder.put_literal("}"));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,7 +172,7 @@ inline void ValueAndShadowReference<T>::operator=(const ValueWithShadow<T>& othe
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct AK::Formatter<UserspaceEmulator::ValueWithShadow<T>> : AK::Formatter<T> {
|
struct AK::Formatter<UserspaceEmulator::ValueWithShadow<T>> : AK::Formatter<T> {
|
||||||
void format(FormatBuilder& builder, UserspaceEmulator::ValueWithShadow<T> value)
|
ErrorOr<void> format(FormatBuilder& builder, UserspaceEmulator::ValueWithShadow<T> value)
|
||||||
{
|
{
|
||||||
return Formatter<T>::format(builder, value.value());
|
return Formatter<T>::format(builder, value.value());
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,8 +63,8 @@ public:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<Hearts::Player> : Formatter<FormatString> {
|
struct AK::Formatter<Hearts::Player> : Formatter<FormatString> {
|
||||||
void format(FormatBuilder& builder, Hearts::Player const& player)
|
ErrorOr<void> format(FormatBuilder& builder, Hearts::Player const& player)
|
||||||
{
|
{
|
||||||
builder.put_string(player.name);
|
return builder.put_string(player.name);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -82,7 +82,7 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<Cards::Card> : Formatter<FormatString> {
|
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;
|
StringView type;
|
||||||
|
|
||||||
|
@ -103,6 +103,6 @@ struct AK::Formatter<Cards::Card> : Formatter<FormatString> {
|
||||||
VERIFY_NOT_REACHED();
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -98,7 +98,7 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<Cards::CardStack> : Formatter<FormatString> {
|
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;
|
StringView type;
|
||||||
|
|
||||||
|
@ -130,6 +130,6 @@ struct AK::Formatter<Cards::CardStack> : Formatter<FormatString> {
|
||||||
first_card = false;
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -85,15 +85,15 @@ namespace AK {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<Core::FileWatcherEvent> : Formatter<FormatString> {
|
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<>
|
template<>
|
||||||
struct Formatter<Core::FileWatcherEvent::Type> : Formatter<FormatString> {
|
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;
|
char const* type;
|
||||||
switch (value) {
|
switch (value) {
|
||||||
|
@ -116,7 +116,7 @@ struct Formatter<Core::FileWatcherEvent::Type> : Formatter<FormatString> {
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.put_string(type);
|
return builder.put_string(type);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -199,7 +199,7 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<Core::Object> : AK::Formatter<FormatString> {
|
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);
|
return AK::Formatter<FormatString>::format(builder, "{}({})", value.class_name(), &value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<Core::SocketAddress> : Formatter<String> {
|
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());
|
return Formatter<String>::format(builder, value.to_string());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
using Crypto::ASN1::DecodeError;
|
||||||
|
|
||||||
|
|
|
@ -206,5 +206,5 @@ void pretty_print(Decoder&, OutputStream&, int indent = 0);
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<Crypto::ASN1::DecodeError> : Formatter<StringView> {
|
struct AK::Formatter<Crypto::ASN1::DecodeError> : Formatter<StringView> {
|
||||||
void format(FormatBuilder&, Crypto::ASN1::DecodeError);
|
ErrorOr<void> format(FormatBuilder&, Crypto::ASN1::DecodeError);
|
||||||
};
|
};
|
||||||
|
|
|
@ -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())
|
if (value.is_invalid())
|
||||||
return Formatter<StringView>::format(fmtbuilder, "invalid");
|
return Formatter<StringView>::format(fmtbuilder, "invalid");
|
||||||
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
for (int i = value.length() - 1; i >= 0; --i)
|
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());
|
return Formatter<StringView>::format(fmtbuilder, builder.string_view());
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ struct UnsignedDivisionResult {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<Crypto::UnsignedBigInteger> : Formatter<StringView> {
|
struct AK::Formatter<Crypto::UnsignedBigInteger> : Formatter<StringView> {
|
||||||
void format(FormatBuilder&, const Crypto::UnsignedBigInteger&);
|
ErrorOr<void> format(FormatBuilder&, Crypto::UnsignedBigInteger const&);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Crypto::UnsignedBigInteger
|
inline Crypto::UnsignedBigInteger
|
||||||
|
|
|
@ -127,12 +127,11 @@ struct AK::Formatter<LibDSP::ProcessorRangeParameter> : AK::StandardFormatter {
|
||||||
: StandardFormatter(formatter)
|
: StandardFormatter(formatter)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void format(FormatBuilder& builder, LibDSP::ProcessorRangeParameter value)
|
ErrorOr<void> format(FormatBuilder& builder, LibDSP::ProcessorRangeParameter value)
|
||||||
{
|
{
|
||||||
if (m_mode == Mode::Pointer) {
|
if (m_mode == Mode::Pointer) {
|
||||||
Formatter<FlatPtr> formatter { *this };
|
Formatter<FlatPtr> formatter { *this };
|
||||||
formatter.format(builder, reinterpret_cast<FlatPtr>(&value));
|
return formatter.format(builder, reinterpret_cast<FlatPtr>(&value));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_sign_mode != FormatBuilder::SignMode::Default)
|
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_width = m_width.value_or(0);
|
||||||
m_precision = m_precision.value_or(NumericLimits<size_t>::max());
|
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 {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -66,12 +66,11 @@ namespace AK {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<GUI::ModelIndex> : Formatter<FormatString> {
|
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())
|
if (value.internal_data())
|
||||||
return Formatter<FormatString>::format(builder, "ModelIndex({},{},{})", value.row(), value.column(), 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());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ namespace AK {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<GUI::PersistentModelIndex> : Formatter<FormatString> {
|
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());
|
return Formatter<FormatString>::format(builder, "PersistentModelIndex({},{},{})", value.row(), value.column(), value.internal_data());
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,11 +40,11 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<GUI::TextPosition> : AK::Formatter<FormatString> {
|
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())
|
if (value.is_valid())
|
||||||
Formatter<FormatString>::format(builder, "({},{})", value.line(), value.column());
|
return Formatter<FormatString>::format(builder, "({},{})", value.line(), value.column());
|
||||||
else
|
|
||||||
Formatter<FormatString>::format(builder, "GUI::TextPosition(Invalid)");
|
return Formatter<FormatString>::format(builder, "GUI::TextPosition(Invalid)");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -68,11 +68,10 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<GUI::TextRange> : AK::Formatter<FormatString> {
|
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())
|
if (value.is_valid())
|
||||||
return Formatter<FormatString>::format(builder, "{}-{}", value.start(), value.end());
|
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)");
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -70,7 +70,7 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<Gfx::AffineTransform> : Formatter<FormatString> {
|
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());
|
return Formatter<FormatString>::format(builder, "[{} {} {} {} {} {}]", value.a(), value.b(), value.c(), value.d(), value.e(), value.f());
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,9 +75,9 @@ namespace AK {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Formatter<Gfx::Endpoint<T>> : Formatter<StringView> {
|
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));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -352,7 +352,7 @@ bool IPC::decode(IPC::Decoder& decoder, Color& color)
|
||||||
return true;
|
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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -478,7 +478,7 @@ namespace AK {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<Gfx::Color> : public Formatter<StringView> {
|
struct Formatter<Gfx::Color> : public Formatter<StringView> {
|
||||||
void format(FormatBuilder& builder, Gfx::Color const& value);
|
ErrorOr<void> format(FormatBuilder&, Gfx::Color const&);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -280,9 +280,9 @@ namespace AK {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Formatter<Gfx::Point<T>> : Formatter<StringView> {
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -726,9 +726,9 @@ namespace AK {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Formatter<Gfx::Rect<T>> : Formatter<StringView> {
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -178,9 +178,9 @@ namespace AK {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Formatter<Gfx::Size<T>> : Formatter<StringView> {
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -127,9 +127,9 @@ namespace AK {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Formatter<Gfx::Vector2<T>> : Formatter<StringView> {
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -144,9 +144,9 @@ namespace AK {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Formatter<Gfx::Vector3<T>> : Formatter<StringView> {
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -145,9 +145,9 @@ namespace AK {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Formatter<Gfx::Vector4<T>> : Formatter<StringView> {
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<JS::Bytecode::Label> : AK::Formatter<FormatString> {
|
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());
|
return AK::Formatter<FormatString>::format(builder, "@{}", value.block().name());
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<JS::Bytecode::Register> : AK::Formatter<FormatString> {
|
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)
|
if (value.index() == JS::Bytecode::Register::accumulator_index)
|
||||||
return AK::Formatter<FormatString>::format(builder, "acc");
|
return AK::Formatter<FormatString>::format(builder, "acc");
|
||||||
|
|
|
@ -75,11 +75,11 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<JS::Cell> : AK::Formatter<FormatString> {
|
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)
|
if (!cell)
|
||||||
Formatter<FormatString>::format(builder, "Cell{nullptr}");
|
return Formatter<FormatString>::format(builder, "Cell{nullptr}");
|
||||||
else
|
else
|
||||||
Formatter<FormatString>::format(builder, "{}({})", cell->class_name(), cell);
|
return Formatter<FormatString>::format(builder, "{}({})", cell->class_name(), cell);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -75,13 +75,13 @@ namespace AK {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<JS::PropertyAttributes> : Formatter<StringView> {
|
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;
|
Vector<String> parts;
|
||||||
parts.append(String::formatted("[[Writable]]: {}", property_attributes.is_writable()));
|
parts.append(String::formatted("[[Writable]]: {}", property_attributes.is_writable()));
|
||||||
parts.append(String::formatted("[[Enumerable]]: {}", property_attributes.is_enumerable()));
|
parts.append(String::formatted("[[Enumerable]]: {}", property_attributes.is_enumerable()));
|
||||||
parts.append(String::formatted("[[Configurable]]: {}", property_attributes.is_configurable()));
|
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)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace AK {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<JS::PropertyDescriptor> : Formatter<StringView> {
|
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;
|
Vector<String> parts;
|
||||||
if (property_descriptor.value.has_value())
|
if (property_descriptor.value.has_value())
|
||||||
|
@ -62,7 +62,7 @@ struct Formatter<JS::PropertyDescriptor> : Formatter<StringView> {
|
||||||
parts.append(String::formatted("[[Enumerable]]: {}", *property_descriptor.enumerable));
|
parts.append(String::formatted("[[Enumerable]]: {}", *property_descriptor.enumerable));
|
||||||
if (property_descriptor.configurable.has_value())
|
if (property_descriptor.configurable.has_value())
|
||||||
parts.append(String::formatted("[[Configurable]]: {}", *property_descriptor.configurable));
|
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)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -225,14 +225,13 @@ struct Traits<JS::PropertyKey> : public GenericTraits<JS::PropertyKey> {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<JS::PropertyKey> : Formatter<StringView> {
|
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())
|
if (!property_name.is_valid())
|
||||||
Formatter<StringView>::format(builder, "<invalid PropertyKey>");
|
return Formatter<StringView>::format(builder, "<invalid PropertyKey>");
|
||||||
else if (property_name.is_number())
|
if (property_name.is_number())
|
||||||
Formatter<StringView>::format(builder, String::number(property_name.as_number()));
|
return Formatter<StringView>::format(builder, String::number(property_name.as_number()));
|
||||||
else
|
return Formatter<StringView>::format(builder, property_name.to_string_or_symbol().to_display_string());
|
||||||
Formatter<StringView>::format(builder, property_name.to_string_or_symbol().to_display_string());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -458,9 +458,9 @@ namespace AK {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<JS::Value> : Formatter<StringView> {
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -166,7 +166,7 @@ namespace AK {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<PDF::Command> : Formatter<StringView> {
|
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;
|
StringBuilder builder;
|
||||||
builder.appendff("{} ({})",
|
builder.appendff("{} ({})",
|
||||||
|
@ -180,7 +180,7 @@ struct Formatter<PDF::Command> : Formatter<StringView> {
|
||||||
builder.append(" ]");
|
builder.append(" ]");
|
||||||
}
|
}
|
||||||
|
|
||||||
Formatter<StringView>::format(format_builder, builder.to_string());
|
return Formatter<StringView>::format(format_builder, builder.to_string());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -143,9 +143,9 @@ namespace AK {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<PDF::Rectangle> : Formatter<StringView> {
|
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=({}, {}) }}",
|
String::formatted("Rectangle {{ ll=({}, {}), ur=({}, {}) }}",
|
||||||
rectangle.lower_left_x,
|
rectangle.lower_left_x,
|
||||||
rectangle.lower_left_y,
|
rectangle.lower_left_y,
|
||||||
|
@ -156,7 +156,7 @@ struct Formatter<PDF::Rectangle> : Formatter<StringView> {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<PDF::Page> : Formatter<StringView> {
|
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}}";
|
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,
|
auto str = String::formatted(fmt_string,
|
||||||
|
@ -166,13 +166,13 @@ struct Formatter<PDF::Page> : Formatter<StringView> {
|
||||||
page.crop_box,
|
page.crop_box,
|
||||||
page.user_unit,
|
page.user_unit,
|
||||||
page.rotate);
|
page.rotate);
|
||||||
Formatter<StringView>::format(builder, str);
|
return Formatter<StringView>::format(builder, str);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<PDF::Destination> : Formatter<StringView> {
|
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;
|
String type_str;
|
||||||
switch (destination.type) {
|
switch (destination.type) {
|
||||||
|
@ -207,21 +207,21 @@ struct Formatter<PDF::Destination> : Formatter<StringView> {
|
||||||
param_builder.appendff("{} ", param);
|
param_builder.appendff("{} ", param);
|
||||||
|
|
||||||
auto str = String::formatted("{{ type={} page={} params={} }}", type_str, destination.page, param_builder.to_string());
|
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<>
|
template<>
|
||||||
struct Formatter<PDF::OutlineItem> : Formatter<StringView> {
|
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<>
|
template<>
|
||||||
struct Formatter<PDF::OutlineDict> : Formatter<StringView> {
|
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;
|
StringBuilder child_builder;
|
||||||
child_builder.append('[');
|
child_builder.append('[');
|
||||||
|
@ -229,7 +229,7 @@ struct Formatter<PDF::OutlineDict> : Formatter<StringView> {
|
||||||
child_builder.appendff("{}\n", child.to_string(2));
|
child_builder.appendff("{}\n", child.to_string(2));
|
||||||
child_builder.append(" ]");
|
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()));
|
String::formatted("OutlineDict {{\n count={}\n children={}\n}}", dict.count, child_builder.to_string()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -63,17 +63,17 @@ namespace AK {
|
||||||
|
|
||||||
template<PDF::IsObject T>
|
template<PDF::IsObject T>
|
||||||
struct Formatter<T> : Formatter<StringView> {
|
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>
|
template<PDF::IsObject T>
|
||||||
struct Formatter<NonnullRefPtr<T>> : Formatter<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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1187,7 +1187,7 @@ namespace AK {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<PDF::Parser::LinearizationDictionary> : Formatter<StringView> {
|
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;
|
StringBuilder builder;
|
||||||
builder.append("{\n");
|
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(" offset_of_main_xref_table={}\n", dict.offset_of_main_xref_table);
|
||||||
builder.appendff(" first_page={}\n", dict.first_page);
|
builder.appendff(" first_page={}\n", dict.first_page);
|
||||||
builder.append('}');
|
builder.append('}');
|
||||||
Formatter<StringView>::format(format_builder, builder.to_string());
|
return Formatter<StringView>::format(format_builder, builder.to_string());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<PDF::Parser::PageOffsetHintTable> : Formatter<StringView> {
|
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;
|
StringBuilder builder;
|
||||||
builder.append("{\n");
|
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(" 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.appendff(" shared_object_reference_fraction_denominator={}\n", table.shared_object_reference_fraction_denominator);
|
||||||
builder.append('}');
|
builder.append('}');
|
||||||
Formatter<StringView>::format(format_builder, builder.to_string());
|
return Formatter<StringView>::format(format_builder, builder.to_string());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<PDF::Parser::PageOffsetHintTableEntry> : Formatter<StringView> {
|
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;
|
StringBuilder builder;
|
||||||
builder.append("{\n");
|
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_offset_number={}\n", entry.page_content_stream_offset_number);
|
||||||
builder.appendff(" page_content_stream_length_number={}\n", entry.page_content_stream_length_number);
|
builder.appendff(" page_content_stream_length_number={}\n", entry.page_content_stream_length_number);
|
||||||
builder.append('}');
|
builder.append('}');
|
||||||
Formatter<StringView>::format(format_builder, builder.to_string());
|
return Formatter<StringView>::format(format_builder, builder.to_string());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -135,43 +135,37 @@ namespace AK {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<PDF::LineCapStyle> : Formatter<StringView> {
|
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) {
|
switch (style) {
|
||||||
case PDF::LineCapStyle::ButtCap:
|
case PDF::LineCapStyle::ButtCap:
|
||||||
Formatter<StringView>::format(builder, "LineCapStyle::ButtCap");
|
return Formatter<StringView>::format(builder, "LineCapStyle::ButtCap");
|
||||||
break;
|
|
||||||
case PDF::LineCapStyle::RoundCap:
|
case PDF::LineCapStyle::RoundCap:
|
||||||
Formatter<StringView>::format(builder, "LineCapStyle::RoundCap");
|
return Formatter<StringView>::format(builder, "LineCapStyle::RoundCap");
|
||||||
break;
|
|
||||||
case PDF::LineCapStyle::SquareCap:
|
case PDF::LineCapStyle::SquareCap:
|
||||||
Formatter<StringView>::format(builder, "LineCapStyle::SquareCap");
|
return Formatter<StringView>::format(builder, "LineCapStyle::SquareCap");
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<PDF::LineJoinStyle> : Formatter<StringView> {
|
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) {
|
switch (style) {
|
||||||
case PDF::LineJoinStyle::Miter:
|
case PDF::LineJoinStyle::Miter:
|
||||||
Formatter<StringView>::format(builder, "LineJoinStyle::Miter");
|
return Formatter<StringView>::format(builder, "LineJoinStyle::Miter");
|
||||||
break;
|
|
||||||
case PDF::LineJoinStyle::Round:
|
case PDF::LineJoinStyle::Round:
|
||||||
Formatter<StringView>::format(builder, "LineJoinStyle::Round");
|
return Formatter<StringView>::format(builder, "LineJoinStyle::Round");
|
||||||
break;
|
|
||||||
case PDF::LineJoinStyle::Bevel:
|
case PDF::LineJoinStyle::Bevel:
|
||||||
Formatter<StringView>::format(builder, "LineJoinStyle::Bevel");
|
return Formatter<StringView>::format(builder, "LineJoinStyle::Bevel");
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<PDF::LineDashPattern> : Formatter<StringView> {
|
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;
|
StringBuilder builder;
|
||||||
builder.append("[");
|
builder.append("[");
|
||||||
|
@ -191,40 +185,32 @@ struct Formatter<PDF::LineDashPattern> : Formatter<StringView> {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<PDF::TextRenderingMode> : Formatter<StringView> {
|
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) {
|
switch (style) {
|
||||||
case PDF::TextRenderingMode::Fill:
|
case PDF::TextRenderingMode::Fill:
|
||||||
Formatter<StringView>::format(builder, "TextRenderingMode::Fill");
|
return Formatter<StringView>::format(builder, "TextRenderingMode::Fill");
|
||||||
break;
|
|
||||||
case PDF::TextRenderingMode::Stroke:
|
case PDF::TextRenderingMode::Stroke:
|
||||||
Formatter<StringView>::format(builder, "TextRenderingMode::Stroke");
|
return Formatter<StringView>::format(builder, "TextRenderingMode::Stroke");
|
||||||
break;
|
|
||||||
case PDF::TextRenderingMode::FillThenStroke:
|
case PDF::TextRenderingMode::FillThenStroke:
|
||||||
Formatter<StringView>::format(builder, "TextRenderingMode::FillThenStroke");
|
return Formatter<StringView>::format(builder, "TextRenderingMode::FillThenStroke");
|
||||||
break;
|
|
||||||
case PDF::TextRenderingMode::Invisible:
|
case PDF::TextRenderingMode::Invisible:
|
||||||
Formatter<StringView>::format(builder, "TextRenderingMode::Invisible");
|
return Formatter<StringView>::format(builder, "TextRenderingMode::Invisible");
|
||||||
break;
|
|
||||||
case PDF::TextRenderingMode::FillAndClip:
|
case PDF::TextRenderingMode::FillAndClip:
|
||||||
Formatter<StringView>::format(builder, "TextRenderingMode::FillAndClip");
|
return Formatter<StringView>::format(builder, "TextRenderingMode::FillAndClip");
|
||||||
break;
|
|
||||||
case PDF::TextRenderingMode::StrokeAndClip:
|
case PDF::TextRenderingMode::StrokeAndClip:
|
||||||
Formatter<StringView>::format(builder, "TextRenderingMode::StrokeAndClip");
|
return Formatter<StringView>::format(builder, "TextRenderingMode::StrokeAndClip");
|
||||||
break;
|
|
||||||
case PDF::TextRenderingMode::FillStrokeAndClip:
|
case PDF::TextRenderingMode::FillStrokeAndClip:
|
||||||
Formatter<StringView>::format(builder, "TextRenderingMode::FillStrokeAndClip");
|
return Formatter<StringView>::format(builder, "TextRenderingMode::FillStrokeAndClip");
|
||||||
break;
|
|
||||||
case PDF::TextRenderingMode::Clip:
|
case PDF::TextRenderingMode::Clip:
|
||||||
Formatter<StringView>::format(builder, "TextRenderingMode::Clip");
|
return Formatter<StringView>::format(builder, "TextRenderingMode::Clip");
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<PDF::TextState> : Formatter<StringView> {
|
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;
|
StringBuilder builder;
|
||||||
builder.append("TextState {\n");
|
builder.append("TextState {\n");
|
||||||
|
@ -239,13 +225,13 @@ struct Formatter<PDF::TextState> : Formatter<StringView> {
|
||||||
builder.appendff(" rise={}\n", state.rise);
|
builder.appendff(" rise={}\n", state.rise);
|
||||||
builder.appendff(" knockout={}\n", state.knockout);
|
builder.appendff(" knockout={}\n", state.knockout);
|
||||||
builder.append(" }");
|
builder.append(" }");
|
||||||
Formatter<StringView>::format(format_builder, builder.to_string());
|
return Formatter<StringView>::format(format_builder, builder.to_string());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<PDF::GraphicsState> : Formatter<StringView> {
|
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;
|
StringBuilder builder;
|
||||||
builder.append("GraphicsState {\n");
|
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(" line_dash_pattern={}\n", state.line_dash_pattern);
|
||||||
builder.appendff(" text_state={}\n", state.text_state);
|
builder.appendff(" text_state={}\n", state.text_state);
|
||||||
builder.append("}");
|
builder.append("}");
|
||||||
Formatter<StringView>::format(format_builder, builder.to_string());
|
return Formatter<StringView>::format(format_builder, builder.to_string());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -85,9 +85,9 @@ namespace AK {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<PDF::Value> : Formatter<StringView> {
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -101,9 +101,9 @@ namespace AK {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<PDF::XRefEntry> : Formatter<StringView> {
|
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={} }}",
|
String::formatted("XRefEntry {{ offset={} generation={} used={} }}",
|
||||||
entry.byte_offset,
|
entry.byte_offset,
|
||||||
entry.generation_number,
|
entry.generation_number,
|
||||||
|
@ -113,14 +113,14 @@ struct Formatter<PDF::XRefEntry> : Formatter<StringView> {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<PDF::XRefTable> : Formatter<StringView> {
|
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;
|
StringBuilder builder;
|
||||||
builder.append("XRefTable {");
|
builder.append("XRefTable {");
|
||||||
for (auto& entry : table.m_entries)
|
for (auto& entry : table.m_entries)
|
||||||
builder.appendff("\n {}", entry);
|
builder.appendff("\n {}", entry);
|
||||||
builder.append("\n}");
|
builder.append("\n}");
|
||||||
Formatter<StringView>::format(format_builder, builder.to_string());
|
return Formatter<StringView>::format(format_builder, builder.to_string());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -536,7 +536,7 @@ using regex::RegexStringView;
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<regex::RegexStringView> : Formatter<StringView> {
|
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();
|
auto string = value.to_string();
|
||||||
return Formatter<StringView>::format(builder, string);
|
return Formatter<StringView>::format(builder, string);
|
||||||
|
|
|
@ -286,27 +286,27 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<Wasm::Validator::StackEntry> : public AK::Formatter<StringView> {
|
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)
|
if (value.is_known)
|
||||||
return Formatter<StringView>::format(builder, Wasm::ValueType::kind_name(value.concrete_type.kind()));
|
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<>
|
template<>
|
||||||
struct AK::Formatter<Wasm::ValueType> : public AK::Formatter<StringView> {
|
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<>
|
template<>
|
||||||
struct AK::Formatter<Wasm::ValidationError> : public AK::Formatter<StringView> {
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -101,25 +101,25 @@ namespace AK {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<Web::CSS::MediaQuery::MediaFeature> : Formatter<StringView> {
|
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<>
|
template<>
|
||||||
struct Formatter<Web::CSS::MediaQuery::MediaCondition> : Formatter<StringView> {
|
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<>
|
template<>
|
||||||
struct Formatter<Web::CSS::MediaQuery> : Formatter<StringView> {
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -151,9 +151,9 @@ namespace AK {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<Web::CSS::Selector> : Formatter<StringView> {
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -51,9 +51,9 @@ private:
|
||||||
namespace AK {
|
namespace AK {
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<Web::DOM::Position> : Formatter<StringView> {
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -28,50 +28,42 @@ bool DNSAnswer::has_expired() const
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AK::Formatter<LookupServer::DNSRecordType>::format(AK::FormatBuilder& builder, LookupServer::DNSRecordType value)
|
ErrorOr<void> AK::Formatter<LookupServer::DNSRecordType>::format(AK::FormatBuilder& builder, LookupServer::DNSRecordType value)
|
||||||
{
|
{
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case LookupServer::DNSRecordType::A:
|
case LookupServer::DNSRecordType::A:
|
||||||
builder.put_string("A");
|
return builder.put_string("A");
|
||||||
return;
|
|
||||||
case LookupServer::DNSRecordType::NS:
|
case LookupServer::DNSRecordType::NS:
|
||||||
builder.put_string("NS");
|
return builder.put_string("NS");
|
||||||
return;
|
|
||||||
case LookupServer::DNSRecordType::CNAME:
|
case LookupServer::DNSRecordType::CNAME:
|
||||||
builder.put_string("CNAME");
|
return builder.put_string("CNAME");
|
||||||
return;
|
|
||||||
case LookupServer::DNSRecordType::SOA:
|
case LookupServer::DNSRecordType::SOA:
|
||||||
builder.put_string("SOA");
|
return builder.put_string("SOA");
|
||||||
return;
|
|
||||||
case LookupServer::DNSRecordType::PTR:
|
case LookupServer::DNSRecordType::PTR:
|
||||||
builder.put_string("PTR");
|
return builder.put_string("PTR");
|
||||||
return;
|
|
||||||
case LookupServer::DNSRecordType::MX:
|
case LookupServer::DNSRecordType::MX:
|
||||||
builder.put_string("MX");
|
return builder.put_string("MX");
|
||||||
return;
|
|
||||||
case LookupServer::DNSRecordType::TXT:
|
case LookupServer::DNSRecordType::TXT:
|
||||||
builder.put_string("TXT");
|
return builder.put_string("TXT");
|
||||||
return;
|
|
||||||
case LookupServer::DNSRecordType::AAAA:
|
case LookupServer::DNSRecordType::AAAA:
|
||||||
builder.put_string("AAAA");
|
return builder.put_string("AAAA");
|
||||||
return;
|
|
||||||
case LookupServer::DNSRecordType::SRV:
|
case LookupServer::DNSRecordType::SRV:
|
||||||
builder.put_string("SRV");
|
return builder.put_string("SRV");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.put_string("DNS record type ");
|
TRY(builder.put_string("DNS record type "));
|
||||||
builder.put_u64((u16)value);
|
TRY(builder.put_u64((u16)value));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void AK::Formatter<LookupServer::DNSRecordClass>::format(AK::FormatBuilder& builder, LookupServer::DNSRecordClass value)
|
ErrorOr<void> AK::Formatter<LookupServer::DNSRecordClass>::format(AK::FormatBuilder& builder, LookupServer::DNSRecordClass value)
|
||||||
{
|
{
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case LookupServer::DNSRecordClass::IN:
|
case LookupServer::DNSRecordClass::IN:
|
||||||
builder.put_string("IN");
|
return builder.put_string("IN");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.put_string("DNS record class ");
|
TRY(builder.put_string("DNS record class "));
|
||||||
builder.put_u64((u16)value);
|
TRY(builder.put_u64((u16)value));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ struct AK::Formatter<LookupServer::DNSRecordType> : StandardFormatter {
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void format(AK::FormatBuilder&, LookupServer::DNSRecordType);
|
ErrorOr<void> format(AK::FormatBuilder&, LookupServer::DNSRecordType);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
@ -76,5 +76,5 @@ struct AK::Formatter<LookupServer::DNSRecordClass> : StandardFormatter {
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void format(AK::FormatBuilder&, LookupServer::DNSRecordClass);
|
ErrorOr<void> format(AK::FormatBuilder&, LookupServer::DNSRecordClass);
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,7 +41,7 @@ OutputStream& operator<<(OutputStream& stream, const DNSName&);
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<LookupServer::DNSName> : Formatter<StringView> {
|
struct AK::Formatter<LookupServer::DNSName> : Formatter<StringView> {
|
||||||
void format(FormatBuilder& builder, const LookupServer::DNSName& value)
|
ErrorOr<void> format(FormatBuilder& builder, LookupServer::DNSName const& value)
|
||||||
{
|
{
|
||||||
return Formatter<StringView>::format(builder, value.as_string());
|
return Formatter<StringView>::format(builder, value.as_string());
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
void AK::Formatter<Shell::AST::Command>::format(FormatBuilder& builder, const Shell::AST::Command& value)
|
ErrorOr<void> AK::Formatter<Shell::AST::Command>::format(FormatBuilder& builder, Shell::AST::Command const& value)
|
||||||
{
|
{
|
||||||
if (m_sign_mode != FormatBuilder::SignMode::Default)
|
if (m_sign_mode != FormatBuilder::SignMode::Default)
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
|
@ -35,46 +35,46 @@ void AK::Formatter<Shell::AST::Command>::format(FormatBuilder& builder, const Sh
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
|
|
||||||
if (value.argv.is_empty()) {
|
if (value.argv.is_empty()) {
|
||||||
builder.put_literal("(ShellInternal)");
|
TRY(builder.put_literal("(ShellInternal)"));
|
||||||
} else {
|
} else {
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto& arg : value.argv) {
|
for (auto& arg : value.argv) {
|
||||||
if (!first)
|
if (!first)
|
||||||
builder.put_literal(" ");
|
TRY(builder.put_literal(" "));
|
||||||
first = false;
|
first = false;
|
||||||
builder.put_literal(arg);
|
TRY(builder.put_literal(arg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& redir : value.redirections) {
|
for (auto& redir : value.redirections) {
|
||||||
builder.put_padding(' ', 1);
|
TRY(builder.put_padding(' ', 1));
|
||||||
if (redir.is_path_redirection()) {
|
if (redir.is_path_redirection()) {
|
||||||
auto path_redir = (const Shell::AST::PathRedirection*)&redir;
|
auto path_redir = (const Shell::AST::PathRedirection*)&redir;
|
||||||
builder.put_i64(path_redir->fd);
|
TRY(builder.put_i64(path_redir->fd));
|
||||||
switch (path_redir->direction) {
|
switch (path_redir->direction) {
|
||||||
case Shell::AST::PathRedirection::Read:
|
case Shell::AST::PathRedirection::Read:
|
||||||
builder.put_literal("<");
|
TRY(builder.put_literal("<"));
|
||||||
break;
|
break;
|
||||||
case Shell::AST::PathRedirection::Write:
|
case Shell::AST::PathRedirection::Write:
|
||||||
builder.put_literal(">");
|
TRY(builder.put_literal(">"));
|
||||||
break;
|
break;
|
||||||
case Shell::AST::PathRedirection::WriteAppend:
|
case Shell::AST::PathRedirection::WriteAppend:
|
||||||
builder.put_literal(">>");
|
TRY(builder.put_literal(">>"));
|
||||||
break;
|
break;
|
||||||
case Shell::AST::PathRedirection::ReadWrite:
|
case Shell::AST::PathRedirection::ReadWrite:
|
||||||
builder.put_literal("<>");
|
TRY(builder.put_literal("<>"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
builder.put_literal(path_redir->path);
|
TRY(builder.put_literal(path_redir->path));
|
||||||
} else if (redir.is_fd_redirection()) {
|
} else if (redir.is_fd_redirection()) {
|
||||||
auto* fdredir = (const Shell::AST::FdRedirection*)&redir;
|
auto* fdredir = (const Shell::AST::FdRedirection*)&redir;
|
||||||
builder.put_i64(fdredir->new_fd);
|
TRY(builder.put_i64(fdredir->new_fd));
|
||||||
builder.put_literal(">");
|
TRY(builder.put_literal(">"));
|
||||||
builder.put_i64(fdredir->old_fd);
|
TRY(builder.put_i64(fdredir->old_fd));
|
||||||
} else if (redir.is_close_redirection()) {
|
} else if (redir.is_close_redirection()) {
|
||||||
auto close_redir = (const Shell::AST::CloseRedirection*)&redir;
|
auto close_redir = (const Shell::AST::CloseRedirection*)&redir;
|
||||||
builder.put_i64(close_redir->fd);
|
TRY(builder.put_i64(close_redir->fd));
|
||||||
builder.put_literal(">&-");
|
TRY(builder.put_literal(">&-"));
|
||||||
} else {
|
} else {
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
@ -84,23 +84,24 @@ void AK::Formatter<Shell::AST::Command>::format(FormatBuilder& builder, const Sh
|
||||||
for (auto& command : value.next_chain) {
|
for (auto& command : value.next_chain) {
|
||||||
switch (command.action) {
|
switch (command.action) {
|
||||||
case Shell::AST::NodeWithAction::And:
|
case Shell::AST::NodeWithAction::And:
|
||||||
builder.put_literal(" && ");
|
TRY(builder.put_literal(" && "));
|
||||||
break;
|
break;
|
||||||
case Shell::AST::NodeWithAction::Or:
|
case Shell::AST::NodeWithAction::Or:
|
||||||
builder.put_literal(" || ");
|
TRY(builder.put_literal(" || "));
|
||||||
break;
|
break;
|
||||||
case Shell::AST::NodeWithAction::Sequence:
|
case Shell::AST::NodeWithAction::Sequence:
|
||||||
builder.put_literal("; ");
|
TRY(builder.put_literal("; "));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.put_literal("(");
|
TRY(builder.put_literal("("));
|
||||||
builder.put_literal(command.node->class_name());
|
TRY(builder.put_literal(command.node->class_name()));
|
||||||
builder.put_literal("...)");
|
TRY(builder.put_literal("...)"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!value.should_wait)
|
if (!value.should_wait)
|
||||||
builder.put_literal("&");
|
TRY(builder.put_literal("&"));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Shell::AST {
|
namespace Shell::AST {
|
||||||
|
|
|
@ -1512,7 +1512,7 @@ struct Formatter<Shell::AST::Command> : StandardFormatter {
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void format(FormatBuilder&, const Shell::AST::Command& value);
|
ErrorOr<void> format(FormatBuilder&, Shell::AST::Command const& value);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -273,7 +273,7 @@ struct Formatter<BitflagDerivative> : StandardFormatter {
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void format(FormatBuilder& format_builder, BitflagDerivative const& value)
|
ErrorOr<void> format(FormatBuilder& format_builder, BitflagDerivative const& value)
|
||||||
{
|
{
|
||||||
bool had_any_output = false;
|
bool had_any_output = false;
|
||||||
int remaining = value.flagset;
|
int remaining = value.flagset;
|
||||||
|
@ -283,25 +283,27 @@ struct Formatter<BitflagDerivative> : StandardFormatter {
|
||||||
continue;
|
continue;
|
||||||
remaining &= ~option.value;
|
remaining &= ~option.value;
|
||||||
if (had_any_output)
|
if (had_any_output)
|
||||||
format_builder.put_literal(" | ");
|
TRY(format_builder.put_literal(" | "));
|
||||||
format_builder.put_literal(option.name);
|
TRY(format_builder.put_literal(option.name));
|
||||||
had_any_output = true;
|
had_any_output = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remaining != 0) {
|
if (remaining != 0) {
|
||||||
// No more BitflagOptions are available. Any remaining flags are unrecognized.
|
// No more BitflagOptions are available. Any remaining flags are unrecognized.
|
||||||
if (had_any_output)
|
if (had_any_output)
|
||||||
format_builder.put_literal(" | ");
|
TRY(format_builder.put_literal(" | "));
|
||||||
format_builder.builder().appendff("0x{:x} (?)", static_cast<unsigned>(remaining));
|
format_builder.builder().appendff("0x{:x} (?)", static_cast<unsigned>(remaining));
|
||||||
had_any_output = true;
|
had_any_output = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!had_any_output) {
|
if (!had_any_output) {
|
||||||
if constexpr (requires { BitflagDerivative::default_; })
|
if constexpr (requires { BitflagDerivative::default_; })
|
||||||
format_builder.put_literal(BitflagDerivative::default_);
|
TRY(format_builder.put_literal(BitflagDerivative::default_));
|
||||||
else
|
else
|
||||||
format_builder.put_literal("0");
|
TRY(format_builder.put_literal("0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -319,13 +321,14 @@ struct Formatter<PointerArgument> : StandardFormatter {
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void format(FormatBuilder& format_builder, PointerArgument const& value)
|
ErrorOr<void> format(FormatBuilder& format_builder, PointerArgument const& value)
|
||||||
{
|
{
|
||||||
auto& builder = format_builder.builder();
|
auto& builder = format_builder.builder();
|
||||||
if (value.value == nullptr)
|
if (value.value == nullptr)
|
||||||
builder.append("null");
|
builder.append("null");
|
||||||
else
|
else
|
||||||
builder.appendff("{}", value.value);
|
builder.appendff("{}", value.value);
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -478,25 +481,27 @@ static void format_ioctl(FormattedSyscallBuilder& builder, int fd, unsigned requ
|
||||||
namespace AK {
|
namespace AK {
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<struct timespec> : StandardFormatter {
|
struct Formatter<struct timespec> : StandardFormatter {
|
||||||
void format(FormatBuilder& format_builder, struct timespec value)
|
ErrorOr<void> format(FormatBuilder& format_builder, struct timespec value)
|
||||||
{
|
{
|
||||||
auto& builder = format_builder.builder();
|
auto& builder = format_builder.builder();
|
||||||
builder.appendff("{{tv_sec={}, tv_nsec={}}}", value.tv_sec, value.tv_nsec);
|
builder.appendff("{{tv_sec={}, tv_nsec={}}}", value.tv_sec, value.tv_nsec);
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<struct timeval> : StandardFormatter {
|
struct Formatter<struct timeval> : StandardFormatter {
|
||||||
void format(FormatBuilder& format_builder, struct timeval value)
|
ErrorOr<void> format(FormatBuilder& format_builder, struct timeval value)
|
||||||
{
|
{
|
||||||
auto& builder = format_builder.builder();
|
auto& builder = format_builder.builder();
|
||||||
builder.appendff("{{tv_sec={}, tv_usec={}}}", value.tv_sec, value.tv_usec);
|
builder.appendff("{{tv_sec={}, tv_usec={}}}", value.tv_sec, value.tv_usec);
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<struct stat> : StandardFormatter {
|
struct Formatter<struct stat> : StandardFormatter {
|
||||||
void format(FormatBuilder& format_builder, struct stat value)
|
ErrorOr<void> format(FormatBuilder& format_builder, struct stat value)
|
||||||
{
|
{
|
||||||
auto& builder = format_builder.builder();
|
auto& builder = format_builder.builder();
|
||||||
builder.appendff(
|
builder.appendff(
|
||||||
|
@ -504,6 +509,7 @@ struct Formatter<struct stat> : StandardFormatter {
|
||||||
"st_size={}, st_blksize={}, st_blocks={}, st_atim={}, st_mtim={}, st_ctim={}}}",
|
"st_size={}, st_blksize={}, st_blocks={}, st_atim={}, st_mtim={}, st_ctim={}}}",
|
||||||
value.st_dev, value.st_ino, value.st_mode, value.st_nlink, value.st_uid, value.st_gid, value.st_rdev,
|
value.st_dev, value.st_ino, value.st_mode, value.st_nlink, value.st_uid, value.st_gid, value.st_rdev,
|
||||||
value.st_size, value.st_blksize, value.st_blocks, value.st_atim, value.st_mtim, value.st_ctim);
|
value.st_size, value.st_blksize, value.st_blocks, value.st_atim, value.st_mtim, value.st_ctim);
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -561,7 +567,7 @@ static void format_select(FormattedSyscallBuilder& builder, Syscall::SC_select_p
|
||||||
namespace AK {
|
namespace AK {
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<struct sockaddr> : StandardFormatter {
|
struct Formatter<struct sockaddr> : StandardFormatter {
|
||||||
void format(FormatBuilder& format_builder, struct sockaddr address)
|
ErrorOr<void> format(FormatBuilder& format_builder, struct sockaddr address)
|
||||||
{
|
{
|
||||||
auto& builder = format_builder.builder();
|
auto& builder = format_builder.builder();
|
||||||
builder.append("{sa_family=");
|
builder.append("{sa_family=");
|
||||||
|
@ -579,6 +585,7 @@ struct Formatter<struct sockaddr> : StandardFormatter {
|
||||||
address_un->sun_path);
|
address_un->sun_path);
|
||||||
}
|
}
|
||||||
builder.append('}');
|
builder.append('}');
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ static FlatPtr parse_from(ArgIter&);
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<Syscall::Function> : Formatter<StringView> {
|
struct AK::Formatter<Syscall::Function> : Formatter<StringView> {
|
||||||
void format(FormatBuilder& builder, Syscall::Function function)
|
ErrorOr<void> format(FormatBuilder& builder, Syscall::Function function)
|
||||||
{
|
{
|
||||||
return Formatter<StringView>::format(builder, to_string(function));
|
return Formatter<StringView>::format(builder, to_string(function));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue