refactor(string): refactor string conversion but not fully tested
This commit is contained in:
parent
646d0cb7a4
commit
1c0c93ee25
@ -81,9 +81,25 @@ void TestChar()
|
|||||||
always_check(0xF == TChar<T>::ToDigit(LITERAL(T, 'f')));
|
always_check(0xF == TChar<T>::ToDigit(LITERAL(T, 'f')));
|
||||||
always_check(0xF == TChar<T>::ToDigit(LITERAL(T, 'F')));
|
always_check(0xF == TChar<T>::ToDigit(LITERAL(T, 'F')));
|
||||||
|
|
||||||
|
always_check(0x0 == TChar<T>::ToDigit(LITERAL(T, '0'), false));
|
||||||
|
always_check(0xF != TChar<T>::ToDigit(LITERAL(T, 'f'), false));
|
||||||
|
always_check(0xF == TChar<T>::ToDigit(LITERAL(T, 'F'), false));
|
||||||
|
|
||||||
|
always_check(0x0 == TChar<T>::ToDigit(LITERAL(T, '0'), true));
|
||||||
|
always_check(0xF == TChar<T>::ToDigit(LITERAL(T, 'f'), true));
|
||||||
|
always_check(0xF != TChar<T>::ToDigit(LITERAL(T, 'F'), true));
|
||||||
|
|
||||||
always_check(LITERAL(T, '0') == TChar<T>::FromDigit(0x0));
|
always_check(LITERAL(T, '0') == TChar<T>::FromDigit(0x0));
|
||||||
always_check(LITERAL(T, 'f') != TChar<T>::FromDigit(0xF));
|
always_check(LITERAL(T, 'f') != TChar<T>::FromDigit(0xF));
|
||||||
always_check(LITERAL(T, 'F') == TChar<T>::FromDigit(0xF));
|
always_check(LITERAL(T, 'F') == TChar<T>::FromDigit(0xF));
|
||||||
|
|
||||||
|
always_check(LITERAL(T, '0') == TChar<T>::FromDigit(0x0, false));
|
||||||
|
always_check(LITERAL(T, 'f') != TChar<T>::FromDigit(0xF, false));
|
||||||
|
always_check(LITERAL(T, 'F') == TChar<T>::FromDigit(0xF, false));
|
||||||
|
|
||||||
|
always_check(LITERAL(T, '0') == TChar<T>::FromDigit(0x0, true));
|
||||||
|
always_check(LITERAL(T, 'f') == TChar<T>::FromDigit(0xF, true));
|
||||||
|
always_check(LITERAL(T, 'F') != TChar<T>::FromDigit(0xF, true));
|
||||||
};
|
};
|
||||||
|
|
||||||
Test(InPlaceType<char>);
|
Test(InPlaceType<char>);
|
||||||
|
@ -839,6 +839,66 @@ struct TChar
|
|||||||
return DigitFromChar[InChar];
|
return DigitFromChar[InChar];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NODISCARD FORCEINLINE static constexpr unsigned ToDigit(CharType InChar, bool bLowercase)
|
||||||
|
{
|
||||||
|
static_assert(TChar::IsASCII());
|
||||||
|
|
||||||
|
if (bLowercase)
|
||||||
|
{
|
||||||
|
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,
|
||||||
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||||
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 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, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||||
|
0xFF, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0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>> 8) return DigitFromChar[0];
|
||||||
|
|
||||||
|
return DigitFromChar[InChar];
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||||
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||||
|
0xFF, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
|
||||||
|
0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 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, 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, 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, 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, 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, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert(sizeof(DigitFromChar) == 256);
|
||||||
|
|
||||||
|
if constexpr (sizeof(CharType) > 1) if (InChar >> 8) return DigitFromChar[0];
|
||||||
|
|
||||||
|
return DigitFromChar[InChar];
|
||||||
|
}
|
||||||
|
|
||||||
NODISCARD FORCEINLINE static constexpr CharType FromDigit(unsigned InDigit)
|
NODISCARD FORCEINLINE static constexpr CharType FromDigit(unsigned InDigit)
|
||||||
{
|
{
|
||||||
checkf(InDigit < 36, TEXT("Digit must be in the range [0, 35]."));
|
checkf(InDigit < 36, TEXT("Digit must be in the range [0, 35]."));
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1296,7 +1296,7 @@ public:
|
|||||||
{
|
{
|
||||||
TStringView<ElementType> View = *this;
|
TStringView<ElementType> View = *this;
|
||||||
|
|
||||||
bool Result = View.ToBool();
|
bool Result = View.ToBoolAndTrim();
|
||||||
|
|
||||||
size_t TrimNum = this->Num() - View.Num();
|
size_t TrimNum = this->Num() - View.Num();
|
||||||
|
|
||||||
@ -1311,7 +1311,7 @@ public:
|
|||||||
{
|
{
|
||||||
TStringView<ElementType> View = *this;
|
TStringView<ElementType> View = *this;
|
||||||
|
|
||||||
U Result = View.template ToInt<U>(Base);
|
U Result = View.template ToIntAndTrim<U>(Base);
|
||||||
|
|
||||||
size_t TrimNum = this->Num() - View.Num();
|
size_t TrimNum = this->Num() - View.Num();
|
||||||
|
|
||||||
@ -1326,7 +1326,7 @@ public:
|
|||||||
{
|
{
|
||||||
TStringView<ElementType> View = *this;
|
TStringView<ElementType> View = *this;
|
||||||
|
|
||||||
U Result = View.template ToFloat<U>(bFixed, bScientific);
|
U Result = View.template ToFloatAndTrim<U>(bFixed, bScientific);
|
||||||
|
|
||||||
size_t TrimNum = this->Num() - View.Num();
|
size_t TrimNum = this->Num() - View.Num();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user