AK+Format: Use pointer mode for pointers by default.

This commit is contained in:
asynts 2020-10-07 12:47:35 +02:00 committed by Andreas Kling
parent b9316474b7
commit b94cb02a7f
Notes: sideshowbarker 2024-07-19 01:59:31 +09:00
2 changed files with 5 additions and 0 deletions

View file

@ -284,6 +284,9 @@ template<typename T>
struct Formatter<T*> : StandardFormatter {
void format(TypeErasedFormatParams& params, FormatBuilder& builder, T* value)
{
if (m_mode == Mode::Default)
m_mode = Mode::Pointer;
Formatter<FlatPtr> formatter { *this };
formatter.format(params, builder, reinterpret_cast<FlatPtr>(value));
}

View file

@ -156,9 +156,11 @@ TEST_CASE(pointers)
if (sizeof(void*) == 4) {
EXPECT_EQ(String::formatted("{:p}", 32), "0x00000020");
EXPECT_EQ(String::formatted("{:p}", ptr), "0x00004000");
EXPECT_EQ(String::formatted("{}", ptr), "0x00004000");
} else if (sizeof(void*) == 8) {
EXPECT_EQ(String::formatted("{:p}", 32), "0x0000000000000020");
EXPECT_EQ(String::formatted("{:p}", ptr), "0x0000000000004000");
EXPECT_EQ(String::formatted("{}", ptr), "0x0000000000004000");
} else {
ASSERT_NOT_REACHED();
}