diff --git a/Redcraft.Utility/Source/Public/String/Char.h b/Redcraft.Utility/Source/Public/String/Char.h index 2f39875..f4451be 100644 --- a/Redcraft.Utility/Source/Public/String/Char.h +++ b/Redcraft.Utility/Source/Public/String/Char.h @@ -161,7 +161,7 @@ struct TChar return false; } - NODISCARD FORCEINLINE static constexpr bool IsASCII(CharType InChar) + NODISCARD FORCEINLINE static constexpr bool IsASCII(CharType InChar = LITERAL(CharType, '\0')) { if constexpr (CSameAs) { @@ -359,19 +359,30 @@ struct TChar NODISCARD FORCEINLINE static constexpr bool IsDigit(CharType InChar) { + static_assert(TChar::IsASCII()); + /* ..; */ - return (InChar >= LITERAL(CharType, '0') && InChar <= LITERAL(CharType, '9')); + return InChar >= LITERAL(CharType, '0') && InChar <= LITERAL(CharType, '9'); } 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') + 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); + static_assert(TChar::IsASCII()); + + bool bResult = false; + + /* ..; */ + bResult |= InChar >= LITERAL(CharType, '0') && InChar < LITERAL(CharType, '0') + static_cast(Base); + + /* ..; */ + bResult |= InChar >= LITERAL(CharType, 'a') && InChar < LITERAL(CharType, 'a') + static_cast(Base) - 10; + + /* ..; */ + bResult |= InChar >= LITERAL(CharType, 'A') && InChar < LITERAL(CharType, 'A') + static_cast(Base) - 10; + + return bResult; } NODISCARD FORCEINLINE static constexpr bool IsCntrl(CharType InChar) @@ -800,6 +811,8 @@ struct TChar NODISCARD FORCEINLINE static constexpr TOptional ToDigit(CharType InChar, unsigned Base = 10) { + static_assert(TChar::IsASCII()); + constexpr uint8 DigitFromChar[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -826,8 +839,6 @@ struct TChar if (DigitFromChar[InChar] >= Base) return Invalid; - check(TChar::IsASCII(InChar)); - return DigitFromChar[InChar]; }