Skip to content

Commit

Permalink
AK+Format: Use pointer mode for pointers by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
asynts authored and awesomekling committed Oct 8, 2020
1 parent b931647 commit b94cb02
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions AK/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 2 additions & 0 deletions AK/Tests/TestFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit b94cb02

Please sign in to comment.