Use _strto{i,u} in _atou and _atos

This commit is contained in:
apio 2022-11-20 09:28:17 +01:00
parent bde5de68ca
commit 33876dcda4

View File

@ -1,42 +1,5 @@
#include <NumberParsing.h> #include <NumberParsing.h>
usize _atou(const char** str)
{
usize val = 0;
while (_isdigit(**str))
{
val = (10 * val) + (**str - '0');
(*str)++;
}
return val;
}
isize _atos(const char** str)
{
bool neg = false;
isize val = 0;
switch (**str)
{
case '-':
neg = true;
(*str)++;
break;
case '+': (*str)++; break;
default: break;
}
while (_isdigit(**str))
{
val = (10 * val) + (**str - '0');
(*str)++;
}
return neg ? -val : val;
}
// This function assumes you have called is_valid_digit_for_base() to validate the digit first. // This function assumes you have called is_valid_digit_for_base() to validate the digit first.
static isize parse_digit_unchecked(char c) static isize parse_digit_unchecked(char c)
{ {
@ -100,3 +63,13 @@ isize _strtoi(const char* str, const char** endptr, int base)
return negative ? -(isize)rc : (isize)rc; return negative ? -(isize)rc : (isize)rc;
} }
usize _atou(const char** str)
{
return _strtou(*str, str, 10);
}
isize _atos(const char** str)
{
return _strtoi(*str, str, 10);
}