mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:37:47 +00:00
AK: Add Formatter<FormatString> as helper class.
This commit is contained in:
parent
9a842ec419
commit
1160817a9e
13 changed files with 64 additions and 94 deletions
|
@ -268,12 +268,3 @@ const LogStream& operator<<(const LogStream& stream, const Object& object)
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
namespace AK {
|
||||
|
||||
void Formatter<Core::Object>::format(FormatBuilder& builder, const Core::Object& value)
|
||||
{
|
||||
Formatter<StringView>::format(builder, String::formatted("{}({})", value.class_name(), &value));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -173,12 +173,13 @@ private:
|
|||
|
||||
}
|
||||
|
||||
namespace AK {
|
||||
template<>
|
||||
struct Formatter<Core::Object> : Formatter<StringView> {
|
||||
void format(FormatBuilder&, const Core::Object&);
|
||||
struct AK::Formatter<Core::Object> : AK::Formatter<FormatString> {
|
||||
void format(FormatBuilder& builder, const Core::Object& value)
|
||||
{
|
||||
return AK::Formatter<FormatString>::format(builder, "{}({})", value.class_name(), &value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace Core {
|
||||
template<typename T, typename Callback>
|
||||
|
|
|
@ -47,17 +47,3 @@ const LogStream& operator<<(const LogStream& stream, const ModelIndex& value)
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
namespace AK {
|
||||
|
||||
void Formatter<GUI::ModelIndex>::format(FormatBuilder& builder, const GUI::ModelIndex& value)
|
||||
{
|
||||
Formatter<StringView> formatter { *this };
|
||||
|
||||
if (value.internal_data())
|
||||
formatter.format(builder, String::formatted("ModelIndex({},{},{:p})", value.row(), value.column(), value.internal_data()));
|
||||
else
|
||||
formatter.format(builder, String::formatted("ModelIndex({},{})", value.row(), value.column()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -82,8 +82,14 @@ const LogStream& operator<<(const LogStream&, const ModelIndex&);
|
|||
namespace AK {
|
||||
|
||||
template<>
|
||||
struct Formatter<GUI::ModelIndex> : Formatter<StringView> {
|
||||
void format(FormatBuilder&, const GUI::ModelIndex&);
|
||||
struct Formatter<GUI::ModelIndex> : Formatter<FormatString> {
|
||||
void format(FormatBuilder& builder, const GUI::ModelIndex& value)
|
||||
{
|
||||
if (value.internal_data())
|
||||
return Formatter<FormatString>::format(builder, "ModelIndex({},{},{})", value.row(), value.column(), value.internal_data());
|
||||
else
|
||||
return Formatter<FormatString>::format(builder, "ModelIndex({},{})", value.row(), value.column());
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
|
@ -66,17 +66,13 @@ inline const LogStream& operator<<(const LogStream& stream, const TextPosition&
|
|||
|
||||
}
|
||||
|
||||
namespace AK {
|
||||
|
||||
template<>
|
||||
struct Formatter<GUI::TextPosition> : Formatter<StringView> {
|
||||
struct AK::Formatter<GUI::TextPosition> : AK::Formatter<FormatString> {
|
||||
void format(FormatBuilder& builder, const GUI::TextPosition& value)
|
||||
{
|
||||
if (value.is_valid())
|
||||
Formatter<StringView>::format(builder, String::formatted("({},{})", value.line(), value.column()));
|
||||
Formatter<FormatString>::format(builder, "({},{})", value.line(), value.column());
|
||||
else
|
||||
Formatter<StringView>::format(builder, "GUI::TextPosition(Invalid)");
|
||||
Formatter<FormatString>::format(builder, "GUI::TextPosition(Invalid)");
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -94,17 +94,13 @@ inline const LogStream& operator<<(const LogStream& stream, const TextRange& val
|
|||
|
||||
}
|
||||
|
||||
namespace AK {
|
||||
|
||||
template<>
|
||||
struct Formatter<GUI::TextRange> : Formatter<StringView> {
|
||||
struct AK::Formatter<GUI::TextRange> : AK::Formatter<FormatString> {
|
||||
void format(FormatBuilder& builder, const GUI::TextRange& value)
|
||||
{
|
||||
if (value.is_valid())
|
||||
Formatter<StringView>::format(builder, String::formatted("{}-{}", value.start(), value.end()));
|
||||
return Formatter<FormatString>::format(builder, "{}-{}", value.start(), value.end());
|
||||
else
|
||||
Formatter<StringView>::format(builder, "GUI::TextRange(Invalid)");
|
||||
return Formatter<FormatString>::format(builder, "GUI::TextRange(Invalid)");
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -75,17 +75,13 @@ private:
|
|||
|
||||
}
|
||||
|
||||
namespace AK {
|
||||
|
||||
template<>
|
||||
struct Formatter<JS::Cell> : Formatter<StringView> {
|
||||
struct AK::Formatter<JS::Cell> : AK::Formatter<FormatString> {
|
||||
void format(FormatBuilder& builder, const JS::Cell* cell)
|
||||
{
|
||||
if (!cell)
|
||||
Formatter<StringView>::format(builder, "Cell{nullptr}");
|
||||
Formatter<FormatString>::format(builder, "Cell{nullptr}");
|
||||
else
|
||||
Formatter<StringView>::format(builder, String::formatted("{}{{{}}}", cell->class_name(), static_cast<const void*>(cell)));
|
||||
Formatter<FormatString>::format(builder, "{}({})", cell->class_name(), cell);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue