Compare commits
2 Commits
3859070d53
...
1c0c93ee25
Author | SHA1 | Date | |
---|---|---|---|
1c0c93ee25 | |||
646d0cb7a4 |
@ -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(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, '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>);
|
||||
|
@ -839,6 +839,66 @@ struct TChar
|
||||
return DigitFromChar[InChar];
|
||||
}
|
||||
|
||||
NODISCARD FORCEINLINE static constexpr unsigned ToDigit(CharType InChar, bool bLowercase)
|
||||
{
|
||||
static_assert(TChar::IsASCII());
|
||||
|
||||
if (bLowercase)
|
||||
{
|
||||
const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FF, 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];
|
||||
}
|
||||
|
||||
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, 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F, 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)
|
||||
{
|
||||
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;
|
||||
|
||||
bool Result = View.ToBool();
|
||||
bool Result = View.ToBoolAndTrim();
|
||||
|
||||
size_t TrimNum = this->Num() - View.Num();
|
||||
|
||||
@ -1311,7 +1311,7 @@ public:
|
||||
{
|
||||
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();
|
||||
|
||||
@ -1326,7 +1326,7 @@ public:
|
||||
{
|
||||
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();
|
||||
|
||||
|
@ -116,7 +116,7 @@ public:
|
||||
public:
|
||||
|
||||
/** Shrinks the view by moving its start forward. */
|
||||
FORCEINLINE constexpr TStringView RemovePrefix(size_t Count)
|
||||
FORCEINLINE constexpr TStringView& RemovePrefix(size_t Count)
|
||||
{
|
||||
checkf(Count <= this->Num(), TEXT("Illegal subview range. Please check Count."));
|
||||
|
||||
@ -126,7 +126,7 @@ public:
|
||||
}
|
||||
|
||||
/** Shrinks the view by moving its end backward. */
|
||||
FORCEINLINE constexpr TStringView RemoveSuffix(size_t Count)
|
||||
FORCEINLINE constexpr TStringView& RemoveSuffix(size_t Count)
|
||||
{
|
||||
checkf(Count <= this->Num(), TEXT("Illegal subview range. Please check Count."));
|
||||
|
||||
@ -136,7 +136,7 @@ public:
|
||||
}
|
||||
|
||||
/** Removes whitespace characters from the start of this string. */
|
||||
FORCEINLINE constexpr TStringView TrimStart()
|
||||
FORCEINLINE constexpr TStringView& TrimStart()
|
||||
{
|
||||
auto Index = Find([](ElementType Char) { return !TChar<ElementType>::IsSpace(Char); });
|
||||
|
||||
@ -150,7 +150,7 @@ public:
|
||||
}
|
||||
|
||||
/** Removes whitespace characters from the end of this string. */
|
||||
FORCEINLINE constexpr TStringView TrimEnd()
|
||||
FORCEINLINE constexpr TStringView& TrimEnd()
|
||||
{
|
||||
auto Index = RFind([](ElementType Char) { return !TChar<ElementType>::IsSpace(Char); });
|
||||
|
||||
@ -164,7 +164,7 @@ public:
|
||||
}
|
||||
|
||||
/** Removes whitespace characters from the start and end of this string. */
|
||||
FORCEINLINE constexpr TStringView TrimStartAndEnd()
|
||||
FORCEINLINE constexpr TStringView& TrimStartAndEnd()
|
||||
{
|
||||
TrimStart();
|
||||
TrimEnd();
|
||||
@ -173,7 +173,7 @@ public:
|
||||
}
|
||||
|
||||
/** Removes characters after the first null-terminator. */
|
||||
FORCEINLINE constexpr TStringView TrimToNullTerminator()
|
||||
FORCEINLINE constexpr TStringView& TrimToNullTerminator()
|
||||
{
|
||||
auto Index = Find(LITERAL(ElementType, '\0'));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user