Util: Call integral formatter from pointer type

This commit is contained in:
Riyyi
2022-08-05 21:59:40 +02:00
parent 8b4a748c9d
commit dc8d2a49cd
2 changed files with 9 additions and 15 deletions
+5 -9
View File
@@ -46,9 +46,10 @@ void Formatter<const char*>::parse(Parser& parser)
void Formatter<const char*>::format(Builder& builder, const char* value) const
{
if (specifier.type == PresentationType::Pointer) {
Formatter<const void*> formatter { .specifier = specifier };
formatter.format(builder, static_cast<const void*>(value));
return;
Formatter<uintptr_t> formatter { .specifier = specifier };
formatter.specifier.alternativeForm = true;
formatter.specifier.type = PresentationType::Hex;
return formatter.format(builder, reinterpret_cast<uintptr_t>(value));
}
Formatter<std::string_view>::format(
@@ -58,14 +59,9 @@ void Formatter<const char*>::format(Builder& builder, const char* value) const
// Pointer
void Formatter<std::nullptr_t>::parse(Parser& parser)
{
parser.parseSpecifier(specifier, Parser::ParameterType::Pointer);
}
void Formatter<std::nullptr_t>::format(Builder& builder, std::nullptr_t) const
{
Formatter<std::string_view>::format(builder, "nullptr");
Formatter<const void*>::format(builder, 0);
}
} // namespace Util::Format
+4 -6
View File
@@ -194,23 +194,21 @@ struct Formatter<char[N]> : Formatter<const char*> {
template<typename T>
struct Formatter<T*> : Formatter<uintptr_t> {
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<uintptr_t>(value), 16, false, specifier.fill, specifier.align,
Builder::Sign::None, true, false, specifier.width);
Formatter<uintptr_t>::format(builder, reinterpret_cast<uintptr_t>(value));
}
};
template<>
struct Formatter<std::nullptr_t> : Formatter<std::string_view> {
void parse(Parser& parser);
struct Formatter<std::nullptr_t> : Formatter<const void*> {
void format(Builder& builder, std::nullptr_t) const;
};