From 33876dcda446d50ed852e476771cec3c5fbedff8 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 20 Nov 2022 09:28:17 +0100 Subject: [PATCH] Use _strto{i,u} in _atou and _atos --- luna/NumberParsing.cpp | 47 +++++++++--------------------------------- 1 file changed, 10 insertions(+), 37 deletions(-) diff --git a/luna/NumberParsing.cpp b/luna/NumberParsing.cpp index 7304a851..0e46b314 100644 --- a/luna/NumberParsing.cpp +++ b/luna/NumberParsing.cpp @@ -1,42 +1,5 @@ #include -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. 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; } + +usize _atou(const char** str) +{ + return _strtou(*str, str, 10); +} + +isize _atos(const char** str) +{ + return _strtoi(*str, str, 10); +}