From 44f44aedca172ffadf875adbe02b745aa36eb421 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 19 Nov 2022 22:52:08 +0100 Subject: [PATCH] Make _strtoi call _strtou, to deduplicate code --- luna/NumberParsing.cpp | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/luna/NumberParsing.cpp b/luna/NumberParsing.cpp index 742b2447..428cbfa1 100644 --- a/luna/NumberParsing.cpp +++ b/luna/NumberParsing.cpp @@ -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; }