From 1ac94c8aff47b549f30b370be2191bcc0157826c Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Thu, 2 Jan 2025 21:57:57 -0600 Subject: More bugs in format... --- include/fud_format.hpp | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'include/fud_format.hpp') diff --git a/include/fud_format.hpp b/include/fud_format.hpp index 8dd2231..e80d96e 100644 --- a/include/fud_format.hpp +++ b/include/fud_format.hpp @@ -172,6 +172,8 @@ enum class FormatType : utf8 FixedUpper = 'F', GeneralLower = 'g', GeneralUpper = 'G', + PointerLower = 'p', + PointerUpper = 'P', }; struct FormatSpec; @@ -337,7 +339,6 @@ size_t findSpec(StringView scanView); template requires Drainable FormatResult format(Sink& sink, FormatCharMode formatMode, FormatString fmt, Args&&... args) { - static_cast(sink); if (formatMode != FormatCharMode::Unchecked) { return {0, FudStatus::NotImplemented}; } @@ -416,6 +417,9 @@ FormatResult vFormat(Sink& sink, FormatCharMode formatMode, FormatString fmt, co result.status = drainResult.status; return result; } + if (specIndex == scanView.length()) { + return result; + } scanView.advanceUnsafe(specIndex); if (specIndex == scanView.length()) { return result; @@ -698,6 +702,8 @@ template case FormatType::FixedUpper: case FormatType::GeneralLower: case FormatType::GeneralUpper: + case FormatType::PointerLower: + case FormatType::PointerUpper: result.status = FudStatus::FormatInvalid; break; default: @@ -1270,8 +1276,6 @@ template static_assert(std::is_same_v); static_assert(std::is_same_v); - static_cast(decimalRepr); - auto uppercaseResult = validateFloatFormatType(formatSpec.formatType); if (uppercaseResult.isError()) { return FormatResult{0, uppercaseResult.takeError()}; @@ -1468,23 +1472,35 @@ FormatResult format(Sink& sink, FormatCharMode formatMode, const FormatSpec& for template FormatResult format(Sink& sink, FormatCharMode formatMode, const FormatSpec& formatSpec, const void* arg) { - FormatResult result{0, FudStatus::NotImplemented}; - static_cast(sink); - static_cast(formatMode); - static_cast(formatSpec); - static_cast(arg); - return result; + auto pointerFormatSpec = formatSpec; + if (pointerFormatSpec.formatType == FormatType::Unspecified || + pointerFormatSpec.formatType == FormatType::PointerLower) { + pointerFormatSpec.formatType = FormatType::HexLower; + } else if (pointerFormatSpec.formatType == FormatType::PointerUpper) { + pointerFormatSpec.formatType = FormatType::HexUpper; + } else { + return DrainResult{0, FudStatus::FormatInvalid}; + } + pointerFormatSpec.formatType = FormatType::HexLower; + if (pointerFormatSpec.alternateForm || pointerFormatSpec.hasLocale || + pointerFormatSpec.formatSign != FormatSign::Default) { + return DrainResult{0, FudStatus::FormatInvalid}; + } + pointerFormatSpec.alternateForm = true; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + return impl::formatIntegral(sink, formatMode, pointerFormatSpec, reinterpret_cast(arg)); } template FormatResult format(Sink& sink, FormatCharMode formatMode, const FormatSpec& formatSpec, impl::FormatHandle arg) { - FormatResult result{0, FudStatus::NotImplemented}; + // FormatResult result{0, FudStatus::NotImplemented}; static_cast(sink); static_cast(formatMode); static_cast(formatSpec); static_cast(arg); - return result; + + return format(sink, formatMode, formatSpec, "not implemented"); } } // namespace fud -- cgit v1.2.3