Browse Source

Util: Change nullptr stringification

master
Riyyi 2 years ago
parent
commit
5e419f501d
  1. 2
      src/util/format/formatter.cpp
  2. 2
      src/util/format/formatter.h
  3. 2
      test/unit/testutilformat.cpp

2
src/util/format/formatter.cpp

@ -97,7 +97,7 @@ void Formatter<const char*>::format(Builder& builder, const char* value) const
{
Formatter<std::string_view>::format(
builder,
value != nullptr ? std::string_view { value, strlen(value) } : "(nil)");
value != nullptr ? std::string_view { value, strlen(value) } : "nullptr");
}
// Pointer

2
src/util/format/formatter.h

@ -149,7 +149,7 @@ struct Formatter<T*> {
void format(Builder& builder, T* value) const
{
value == nullptr
? builder.putString("0x0")
? builder.putString("nullptr")
: builder.putPointer(static_cast<const void*>(value));
}
};

2
test/unit/testutilformat.cpp

@ -26,7 +26,7 @@ TEST_CASE(FormatBasicTypes)
EXPECT_EQ(result, "");
result = Util::format("{}", nullptr);
EXPECT_EQ(result, "(nil)");
EXPECT_EQ(result, "nullptr");
int* number = new int(3);
result = Util::format("{}", number);

Loading…
Cancel
Save