From 7a80a80a12341ef3721b119b44ae0d45592f8558 Mon Sep 17 00:00:00 2001 From: Redstone1024 <2824517378@qq.com> Date: Sun, 10 Nov 2024 19:21:49 +0800 Subject: [PATCH] fix(string): fix incorrect TChar results due to signed char --- Redcraft.Utility/Source/Public/String/Char.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Redcraft.Utility/Source/Public/String/Char.h b/Redcraft.Utility/Source/Public/String/Char.h index c03752a..52942b1 100644 --- a/Redcraft.Utility/Source/Public/String/Char.h +++ b/Redcraft.Utility/Source/Public/String/Char.h @@ -60,6 +60,11 @@ NAMESPACE_PRIVATE_END /** Templated literal struct to allow selection of string literals based on the character type provided, and not on compiler switches. */ #define LITERAL(CharType, StringLiteral) NAMESPACE_PRIVATE::TLiteral::Select(TEXT(StringLiteral), WTEXT(StringLiteral), U8TEXT(StringLiteral), U16TEXT(StringLiteral), U32TEXT(StringLiteral)) +static_assert(CUnsigned, "TChar assumes u8char is an unsigned integer"); +static_assert(CUnsigned, "TChar assumes u16char is an unsigned integer"); +static_assert(CUnsigned, "TChar assumes u32char is an unsigned integer"); +static_assert(CUnsigned, "TChar assumes unicodechar is an unsigned integer"); + /** Set of utility functions operating on a single character. Implemented based on user-preferred locale and ISO 30112 "i18n". */ template struct TChar @@ -181,7 +186,7 @@ struct TChar } (); - return ASCIICompatible && InChar <= 0x7F; + return ASCIICompatible && 0x00 <= InChar && InChar <= 0x7F; } else if constexpr (CSameAs) @@ -207,7 +212,7 @@ struct TChar } (); - return ASCIICompatible && InChar <= 0x7F; + return ASCIICompatible && 0x00 <= InChar && InChar <= 0x7F; } else if constexpr (CSameAs || CSameAs || CSameAs || CSameAs) @@ -358,15 +363,15 @@ struct TChar return (InChar >= LITERAL(CharType, '0') && InChar <= LITERAL(CharType, '9')); } - NODISCARD FORCEINLINE static constexpr bool IsDigit(CharType InChar, int Base) + NODISCARD FORCEINLINE static constexpr bool IsDigit(CharType InChar, unsigned Base) { checkf(Base >= 2 && Base <= 36, TEXT("Base must be in the range [2, 36].")); /* ..;..;..; */ return - (InChar >= LITERAL(CharType, '0') && InChar < LITERAL(CharType, '0') + Base ) || - (InChar >= LITERAL(CharType, 'a') && InChar < LITERAL(CharType, 'a') + Base - 10) || - (InChar >= LITERAL(CharType, 'A') && InChar < LITERAL(CharType, 'A') + Base - 10); + (InChar >= LITERAL(CharType, '0') && InChar < LITERAL(CharType, '0') + static_cast(Base) ) || + (InChar >= LITERAL(CharType, 'a') && InChar < LITERAL(CharType, 'a') + static_cast(Base) - 10) || + (InChar >= LITERAL(CharType, 'A') && InChar < LITERAL(CharType, 'A') + static_cast(Base) - 10); } NODISCARD FORCEINLINE static constexpr bool IsCntrl(CharType InChar)