perf(string): add assertions to character functions that depend on ASCII compatibilitya
This commit is contained in:
parent
f8ef1da107
commit
49feb0b12b
@ -161,7 +161,7 @@ struct TChar
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
NODISCARD FORCEINLINE static constexpr bool IsASCII(CharType InChar)
|
NODISCARD FORCEINLINE static constexpr bool IsASCII(CharType InChar = LITERAL(CharType, '\0'))
|
||||||
{
|
{
|
||||||
if constexpr (CSameAs<CharType, char>)
|
if constexpr (CSameAs<CharType, char>)
|
||||||
{
|
{
|
||||||
@ -359,19 +359,30 @@ struct TChar
|
|||||||
|
|
||||||
NODISCARD FORCEINLINE static constexpr bool IsDigit(CharType InChar)
|
NODISCARD FORCEINLINE static constexpr bool IsDigit(CharType InChar)
|
||||||
{
|
{
|
||||||
|
static_assert(TChar::IsASCII());
|
||||||
|
|
||||||
/* <U0030>..<U0039>; */
|
/* <U0030>..<U0039>; */
|
||||||
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)
|
NODISCARD FORCEINLINE static constexpr bool IsDigit(CharType InChar, unsigned Base)
|
||||||
{
|
{
|
||||||
checkf(Base >= 2 && Base <= 36, TEXT("Base must be in the range [2, 36]."));
|
checkf(Base >= 2 && Base <= 36, TEXT("Base must be in the range [2, 36]."));
|
||||||
|
|
||||||
/* <U0030>..<U0039>;<U0041>..<U0046>;<U0061>..<U0066>; */
|
static_assert(TChar::IsASCII());
|
||||||
return
|
|
||||||
(InChar >= LITERAL(CharType, '0') && InChar < LITERAL(CharType, '0') + static_cast<signed>(Base) ) ||
|
bool bResult = false;
|
||||||
(InChar >= LITERAL(CharType, 'a') && InChar < LITERAL(CharType, 'a') + static_cast<signed>(Base) - 10) ||
|
|
||||||
(InChar >= LITERAL(CharType, 'A') && InChar < LITERAL(CharType, 'A') + static_cast<signed>(Base) - 10);
|
/* <U0030>..<U0039>; */
|
||||||
|
bResult |= InChar >= LITERAL(CharType, '0') && InChar < LITERAL(CharType, '0') + static_cast<signed>(Base);
|
||||||
|
|
||||||
|
/* <U0041>..<U0046>; */
|
||||||
|
bResult |= InChar >= LITERAL(CharType, 'a') && InChar < LITERAL(CharType, 'a') + static_cast<signed>(Base) - 10;
|
||||||
|
|
||||||
|
/* <U0061>..<U0066>; */
|
||||||
|
bResult |= InChar >= LITERAL(CharType, 'A') && InChar < LITERAL(CharType, 'A') + static_cast<signed>(Base) - 10;
|
||||||
|
|
||||||
|
return bResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
NODISCARD FORCEINLINE static constexpr bool IsCntrl(CharType InChar)
|
NODISCARD FORCEINLINE static constexpr bool IsCntrl(CharType InChar)
|
||||||
@ -800,6 +811,8 @@ struct TChar
|
|||||||
|
|
||||||
NODISCARD FORCEINLINE static constexpr TOptional<unsigned> ToDigit(CharType InChar, unsigned Base = 10)
|
NODISCARD FORCEINLINE static constexpr TOptional<unsigned> ToDigit(CharType InChar, unsigned Base = 10)
|
||||||
{
|
{
|
||||||
|
static_assert(TChar::IsASCII());
|
||||||
|
|
||||||
constexpr uint8 DigitFromChar[] =
|
constexpr uint8 DigitFromChar[] =
|
||||||
{
|
{
|
||||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
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;
|
if (DigitFromChar[InChar] >= Base) return Invalid;
|
||||||
|
|
||||||
check(TChar::IsASCII(InChar));
|
|
||||||
|
|
||||||
return DigitFromChar[InChar];
|
return DigitFromChar[InChar];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user