diff --git a/Redcraft.Utility/Source/Public/Strings/Formatting.h b/Redcraft.Utility/Source/Public/Strings/Formatting.h index 444c6c1..025659c 100644 --- a/Redcraft.Utility/Source/Public/Strings/Formatting.h +++ b/Redcraft.Utility/Source/Public/Strings/Formatting.h @@ -235,8 +235,6 @@ FORCEINLINE constexpr TRangeIterator Format(R2&& Output, R1&& Fmt, Ts&&... A // If the output range is insufficient. if (OutIter == OutSent) UNLIKELY return OutIter; - TTuple, FCharType>...> Formatters; - // For each character in the format string. for (FCharType Char; FmtIter != FmtSent; ++FmtIter) { @@ -315,35 +313,40 @@ FORCEINLINE constexpr TRangeIterator Format(R2&& Output, R1&& Fmt, Ts&&... A // Jump over the ':' character. if (Char == LITERAL(FCharType, ':')) ++FmtIter; - FormatStringContext.AdvanceTo(MoveTemp(FmtIter)); - - // Parse the format description string. - FmtIter = Formatters.Visit([&FormatStringContext](auto& Formatter) -> decltype(FmtIter) { return Formatter.Parse(FormatStringContext); }, Index); - - if (FmtIter == FmtSent || *FmtIter != LITERAL(FCharType, '}')) UNLIKELY + if (FmtIter == FmtSent) UNLIKELY { checkf(false, TEXT("Illegal format string. Missing '}' in format string.")); break; } - FormatObjectContext.AdvanceTo(MoveTemp(OutIter)); + Char = *FmtIter; - auto FormatHandler = [&](TIndexSequence) + ForwardAsTuple(Forward(Args)...).Visit([&](T&& Arg) { - TTuple...> Visitor; + TFormatter, FCharType> Formatter; - return Visitor.Visit([&](TConstant) + if (Char != LITERAL(FCharType, '}')) { - check(ConstantIndex == Index); + FormatStringContext.AdvanceTo(MoveTemp(FmtIter)); - return Formatters.template GetValue().Format(ForwardAsTuple(Forward(Args)...).template GetValue(), FormatObjectContext); + // Parse the format description string. + FmtIter = Formatter.Parse(FormatStringContext); + + if (FmtIter == FmtSent || *FmtIter != LITERAL(FCharType, '}')) UNLIKELY + { + checkf(false, TEXT("Illegal format string. Missing '}' in format string.")); + + return; + } } - , Index); - }; - // Format the object and write the result to the context. - OutIter = FormatHandler(TIndexSequenceFor()); + FormatObjectContext.AdvanceTo(MoveTemp(OutIter)); + + // Format the object and write the result to the context. + OutIter = Formatter.Format(Forward(Arg), FormatObjectContext); + } + , Index); } else