mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-03 21:10:30 +00:00
Kernel: Add formatter function for OwnPtr<KString>
This adds a formatter function for OwnPtr<KString>. This is added mainly because lots of dbgln() statements generate Strings (such as absolute paths) which are only used for debugging. Instead of catching possible OOM situations at all the dbgln() callsites, this makes it possible to let the formatter code handle those situations by outputting "[out of memory]" if the OwnPtr is null.
This commit is contained in:
parent
95f769ea51
commit
0f8a6e574c
Notes:
sideshowbarker
2024-07-18 10:14:05 +09:00
Author: https://github.com/MaxWipfli Commit: https://github.com/SerenityOS/serenity/commit/0f8a6e574cd Pull-request: https://github.com/SerenityOS/serenity/pull/8492 Reviewed-by: https://github.com/alimpfard
1 changed files with 12 additions and 1 deletions
|
@ -48,7 +48,18 @@ template<>
|
|||
struct Formatter<Kernel::KString> : Formatter<StringView> {
|
||||
void format(FormatBuilder& builder, Kernel::KString const& value)
|
||||
{
|
||||
Formatter<StringView>::format(builder, value.characters());
|
||||
Formatter<StringView>::format(builder, value.view());
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Formatter<OwnPtr<Kernel::KString>> : Formatter<StringView> {
|
||||
void format(FormatBuilder& builder, OwnPtr<Kernel::KString> const& value)
|
||||
{
|
||||
if (value)
|
||||
Formatter<StringView>::format(builder, value->view());
|
||||
else
|
||||
Formatter<StringView>::format(builder, "[out of memory]"sv);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue