Make _strtoi call _strtou, to deduplicate code

This commit is contained in:
apio 2022-11-19 22:52:08 +01:00
parent 30a7d760ae
commit 44f44aedca

View File

@ -96,7 +96,6 @@ usize _strtou(const char* str, const char** endptr, int base)
isize _strtoi(const char* str, const char** endptr, int base)
{
isize val = 0;
bool negative = false;
while (_isspace(*str)) str++;
@ -107,27 +106,8 @@ isize _strtoi(const char* str, const char** endptr, int base)
str++;
}
if ((base == 0 || base == 16) && *str == '0')
{
str++;
if (_tolower(*str) == 'x')
{
base = 16;
str++;
}
else if (base == 0)
base = 8;
}
else if (base == 0)
base = 10;
usize rc = _strtou(str, endptr,
base); // FIXME: Check for overflow (the unsigned usize value might not fit into a signed isize)
while (is_valid_digit_for_base(base, *str))
{
val = (base * val) + parse_digit_unchecked(*str);
str++;
}
if (endptr) *endptr = str;
return negative ? -val : val;
return negative ? -(isize)rc : (isize)rc;
}