UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FastDecimalFormat.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Concepts/Integral.h"
7#include "CoreTypes.h"
10#include "Misc/CString.h"
11
12#include <type_traits>
13
54
62namespace FastDecimalFormat
63{
64
65namespace Internal
66{
67
70
87
106
107CORE_API bool StringToIntegral(const TCHAR* InStr, const int32 InStrLen, const FDecimalNumberFormattingRules& InFormattingRules, const FNumberParsingOptions& InParsingOptions, const FDecimalNumberIntegralLimits& Limits, bool& OutIsNegative, uint64& OutVal, int32* OutParsedLen);
108CORE_API bool StringToFractional(const TCHAR* InStr, const int32 InStrLen, const FDecimalNumberFormattingRules& InFormattingRules, const FNumberParsingOptions& InParsingOptions, const FDecimalNumberFractionalLimits& Limits, double& OutVal, int32* OutParsedLen);
109
110} // namespace Internal
111
112template<typename T>
114{
115 if constexpr (std::is_same_v<T, int8> || std::is_same_v<T, int16> || std::is_same_v<T, int32> || std::is_same_v<T, int64>)
116 {
117 #ifdef _MSC_VER
118 #pragma warning (push)
119 #pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
120 #endif
121 const bool bIsNegative = InVal < 0;
122 Internal::IntegralToString(bIsNegative, (bIsNegative) ? -static_cast<uint64>(InVal) : static_cast<uint64>(InVal), InFormattingRules, InFormattingOptions, OutString);
123 #ifdef _MSC_VER
124 #pragma warning (pop)
125 #endif
126 }
127 else if constexpr (std::is_same_v<T, uint8> || std::is_same_v<T, uint16> || std::is_same_v<T, uint32> || std::is_same_v<T, uint64>)
128 {
129 Internal::IntegralToString(false, static_cast<uint64>(InVal), InFormattingRules, InFormattingOptions, OutString);
130 }
131 else if constexpr (std::is_same_v<T, float> || std::is_same_v<T, double>)
132 {
133 Internal::FractionalToString(static_cast<double>(InVal), InFormattingRules, InFormattingOptions, OutString);
134 }
135 else
136 {
137 static_assert(sizeof(T) == 0, "Not supported");
138 }
139}
140
141template<typename T>
143{
144 FString Result; \
146 return Result; \
147}
148
149#define FAST_DECIMAL_PARSE_INTEGER_IMPL(NUMBER_TYPE) \
150 inline bool StringToNumber(const TCHAR* InStr, const int32 InStrLen, const FDecimalNumberFormattingRules& InFormattingRules, const FNumberParsingOptions& InParsingOptions, NUMBER_TYPE& OutVal, int32* OutParsedLen = nullptr) \
151 { \
152 bool bIsNegative = false; \
153 uint64 Val = 0; \
154 const bool bResult = Internal::StringToIntegral(InStr, InStrLen, InFormattingRules, InParsingOptions, Internal::FDecimalNumberIntegralLimits::FromNumericLimits<NUMBER_TYPE>(), bIsNegative, Val, OutParsedLen); \
155 OutVal = static_cast<NUMBER_TYPE>(Val); \
156 OutVal *= (bIsNegative ? -1 : 1); \
157 return bResult; \
158 } \
159 UE_FORCEINLINE_HINT bool StringToNumber(const TCHAR* InStr, const FDecimalNumberFormattingRules& InFormattingRules, const FNumberParsingOptions& InParsingOptions, NUMBER_TYPE& OutVal, int32* OutParsedLen = nullptr) \
160 { \
161 return StringToNumber(InStr, FCString::Strlen(InStr), InFormattingRules, InParsingOptions, OutVal, OutParsedLen); \
162 }
163
164#define FAST_DECIMAL_PARSE_FRACTIONAL_IMPL(NUMBER_TYPE) \
165 inline bool StringToNumber(const TCHAR* InStr, const int32 InStrLen, const FDecimalNumberFormattingRules& InFormattingRules, const FNumberParsingOptions& InParsingOptions, NUMBER_TYPE& OutVal, int32* OutParsedLen = nullptr) \
166 { \
167 double Val = 0.0; \
168 const bool bResult = Internal::StringToFractional(InStr, InStrLen, InFormattingRules, InParsingOptions, Internal::FDecimalNumberFractionalLimits::FromNumericLimits<NUMBER_TYPE>(), Val, OutParsedLen); \
169 OutVal = static_cast<NUMBER_TYPE>(Val); \
170 return bResult; \
171 } \
172 UE_FORCEINLINE_HINT bool StringToNumber(const TCHAR* InStr, const FDecimalNumberFormattingRules& InFormattingRules, const FNumberParsingOptions& InParsingOptions, NUMBER_TYPE& OutVal, int32* OutParsedLen = nullptr) \
173 { \
174 return StringToNumber(InStr, FCString::Strlen(InStr), InFormattingRules, InParsingOptions, OutVal, OutParsedLen); \
175 }
176
181
186
189
190#undef FAST_DECIMAL_PARSE_INTEGER_IMPL
191#undef FAST_DECIMAL_PARSE_FRACTIONAL_IMPL
192
197
203
204} // namespace FastDecimalFormat
205
206#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_4
207#include "Templates/EnableIf.h"
209#include "Templates/IsIntegral.h"
210#include "Templates/IsSigned.h"
211#endif
FPlatformTypes::int16 int16
A 16-bit signed integer.
Definition Platform.h:1123
FPlatformTypes::int8 int8
An 8-bit signed integer.
Definition Platform.h:1121
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define FAST_DECIMAL_PARSE_FRACTIONAL_IMPL(NUMBER_TYPE)
Definition FastDecimalFormat.h:164
#define FAST_DECIMAL_PARSE_INTEGER_IMPL(NUMBER_TYPE)
Definition FastDecimalFormat.h:149
#define UE_REQUIRES(...)
Definition Requires.h:86
uint8_t uint8
Definition binka_ue_file_header.h:8
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
bool StringToFractional(const TCHAR *InStr, const int32 InStrLen, const FDecimalNumberFormattingRules &InFormattingRules, const FNumberParsingOptions &InParsingOptions, const FDecimalNumberFractionalLimits &InLimits, double &OutVal, int32 *OutParsedLen)
Definition FastDecimalFormat.cpp:930
void IntegralToString(const bool bIsNegative, const uint64 InVal, const FDecimalNumberFormattingRules &InFormattingRules, FNumberFormattingOptions InFormattingOptions, FString &OutString)
Definition FastDecimalFormat.cpp:364
bool StringToIntegral(const TCHAR *InStr, const int32 InStrLen, const FDecimalNumberFormattingRules &InFormattingRules, const FNumberParsingOptions &InParsingOptions, const FDecimalNumberIntegralLimits &InLimits, bool &OutIsNegative, uint64 &OutVal, int32 *OutParsedLen)
Definition FastDecimalFormat.cpp:791
void FractionalToString(const double InVal, const FDecimalNumberFormattingRules &InFormattingRules, FNumberFormattingOptions InFormattingOptions, FString &OutString)
Definition FastDecimalFormat.cpp:501
Definition FastDecimalFormat.cpp:15
uint64 Pow10(const int32 InExponent)
Definition FastDecimalFormat.cpp:1021
const FDecimalNumberFormattingRules & GetCultureAgnosticFormattingRules()
Definition FastDecimalFormat.cpp:1001
void NumberToString(const T InVal, const FDecimalNumberFormattingRules &InFormattingRules, const FNumberFormattingOptions &InFormattingOptions, FString &OutString)
Definition FastDecimalFormat.h:113
Definition ByteSwap.h:14
Definition FastDecimalFormat.h:16
FDecimalNumberFormattingRules()
Definition FastDecimalFormat.h:17
FString NaNString
Definition FastDecimalFormat.h:37
uint8 SecondaryGroupingSize
Definition FastDecimalFormat.h:47
FString PositivePrefixString
Definition FastDecimalFormat.h:40
FString NegativePrefixString
Definition FastDecimalFormat.h:38
FString PositiveSuffixString
Definition FastDecimalFormat.h:41
TCHAR DigitCharacters[10]
Definition FastDecimalFormat.h:49
TCHAR DecimalSeparatorCharacter
Definition FastDecimalFormat.h:45
FString MinusString
Definition FastDecimalFormat.h:43
FNumberFormattingOptions CultureDefaultFormattingOptions
Definition FastDecimalFormat.h:52
uint8 PrimaryGroupingSize
Definition FastDecimalFormat.h:46
TCHAR GroupingSeparatorCharacter
Definition FastDecimalFormat.h:44
FString PlusString
Definition FastDecimalFormat.h:42
uint8 MinimumGroupingDigits
Definition FastDecimalFormat.h:48
FString NegativeSuffixString
Definition FastDecimalFormat.h:39
Definition Text.h:199
Definition Text.h:242
double NumericLimitMax
Definition FastDecimalFormat.h:95
FDecimalNumberFractionalLimits(double InLowest, double InMax)
Definition FastDecimalFormat.h:90
double NumericLimitLowest
Definition FastDecimalFormat.h:94
static FDecimalNumberFractionalLimits FromNumericLimits()
Definition FastDecimalFormat.h:101
static FDecimalNumberIntegralLimits FromNumericLimits()
Definition FastDecimalFormat.h:82
int64 NumericLimitLowest
Definition FastDecimalFormat.h:77
uint64 NumericLimitMax
Definition FastDecimalFormat.h:78
FDecimalNumberIntegralLimits(int64 InLowest, uint64 InMax, bool bInIsSigned)
Definition FastDecimalFormat.h:73
bool bIsNumericSigned
Definition FastDecimalFormat.h:79
Definition NumericLimits.h:41