diff options
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Format.h | 11 | ||||
-rw-r--r-- | AK/Tests/TestFormat.cpp | 5 |
2 files changed, 16 insertions, 0 deletions
diff --git a/AK/Format.h b/AK/Format.h index ea2bd6edf7..90030765ec 100644 --- a/AK/Format.h +++ b/AK/Format.h @@ -348,6 +348,17 @@ struct Formatter<double> : StandardFormatter { }; #endif +template<> +struct Formatter<std::nullptr_t> : Formatter<FlatPtr> { + void format(FormatBuilder& builder, std::nullptr_t) + { + if (m_mode == Mode::Default) + m_mode = Mode::Pointer; + + return Formatter<FlatPtr>::format(builder, 0); + } +}; + void vformat(StringBuilder& builder, StringView fmtstr, TypeErasedFormatParams); void vformat(const LogStream& stream, StringView fmtstr, TypeErasedFormatParams); diff --git a/AK/Tests/TestFormat.cpp b/AK/Tests/TestFormat.cpp index bcf9b91889..cfe7fe2950 100644 --- a/AK/Tests/TestFormat.cpp +++ b/AK/Tests/TestFormat.cpp @@ -269,4 +269,9 @@ TEST_CASE(yay_this_implementation_sucks) EXPECT_EQ(String::formatted("{:.0}", .99999999999), "0."); } +TEST_CASE(format_nullptr) +{ + EXPECT_EQ(String::formatted("{}", nullptr), String::formatted("{:p}", static_cast<FlatPtr>(0))); +} + TEST_MAIN(Format) |