From dc8d2a49cd67c1850829e27860961e86ed49d2af Mon Sep 17 00:00:00 2001 From: Riyyi Date: Fri, 5 Aug 2022 21:10:47 +0200 Subject: [PATCH] Util: Call integral formatter from pointer type --- src/util/format/formatter.cpp | 14 +++++--------- src/util/format/formatter.h | 10 ++++------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/util/format/formatter.cpp b/src/util/format/formatter.cpp index 49e3cb6..201e3e3 100644 --- a/src/util/format/formatter.cpp +++ b/src/util/format/formatter.cpp @@ -46,9 +46,10 @@ void Formatter::parse(Parser& parser) void Formatter::format(Builder& builder, const char* value) const { if (specifier.type == PresentationType::Pointer) { - Formatter formatter { .specifier = specifier }; - formatter.format(builder, static_cast(value)); - return; + Formatter formatter { .specifier = specifier }; + formatter.specifier.alternativeForm = true; + formatter.specifier.type = PresentationType::Hex; + return formatter.format(builder, reinterpret_cast(value)); } Formatter::format( @@ -58,14 +59,9 @@ void Formatter::format(Builder& builder, const char* value) const // Pointer -void Formatter::parse(Parser& parser) -{ - parser.parseSpecifier(specifier, Parser::ParameterType::Pointer); -} - void Formatter::format(Builder& builder, std::nullptr_t) const { - Formatter::format(builder, "nullptr"); + Formatter::format(builder, 0); } } // namespace Util::Format diff --git a/src/util/format/formatter.h b/src/util/format/formatter.h index bb07259..572a314 100644 --- a/src/util/format/formatter.h +++ b/src/util/format/formatter.h @@ -194,23 +194,21 @@ struct Formatter : Formatter { template struct Formatter : Formatter { - Specifier specifier; - constexpr void parse(Parser& parser) { parser.parseSpecifier(specifier, Parser::ParameterType::Pointer); + specifier.alternativeForm = true; + specifier.type = PresentationType::Hex; } void format(Builder& builder, T* value) const { - builder.putU64(reinterpret_cast(value), 16, false, specifier.fill, specifier.align, - Builder::Sign::None, true, false, specifier.width); + Formatter::format(builder, reinterpret_cast(value)); } }; template<> -struct Formatter : Formatter { - void parse(Parser& parser); +struct Formatter : Formatter { void format(Builder& builder, std::nullptr_t) const; };