summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorasynts <asynts@gmail.com>2021-01-01 23:34:00 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-02 01:37:22 +0100
commit632ff01e174f4efc0da6dc9f2170932a3c400fde (patch)
tree6a8d9ccda80839ee2ba656f5a0730cadc8087257 /AK
parent4cfef0cd95b3aa8d3bc94c8b59063f1dc0fd0b10 (diff)
downloadserenity-632ff01e174f4efc0da6dc9f2170932a3c400fde.zip
Piggyback: AK: Add formatter for std::nullptr_t.
Diffstat (limited to 'AK')
-rw-r--r--AK/Format.h11
-rw-r--r--AK/Tests/TestFormat.cpp5
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)