refactor(string): add base-checking to conversions between characters and digits

This commit is contained in:
2024-11-11 12:20:29 +08:00
parent 09bbcecc28
commit f8ef1da107
3 changed files with 43 additions and 76 deletions

View File

@ -209,9 +209,13 @@ struct TStringHelper
{
NumberType Result = Init;
while (!View.IsEmpty() && (Base == 10 ? TChar<T>::IsDigit(View.Front()) : TChar<T>::IsDigit(View.Front(), Base)))
while (!View.IsEmpty())
{
Result = static_cast<NumberType>(Result * Base + *TChar<T>::ToDigit(View.Front()));
auto Digit = TChar<T>::ToDigit(View.Front(), Base);
if (!Digit) break;
Result = Result * static_cast<NumberType>(Base) + static_cast<NumberType>(*Digit);
View.RemovePrefix(1);
}