From 32fbc9c08c95658fab3b31c71583642847b552aa Mon Sep 17 00:00:00 2001 From: Daniel Santos Date: Fri, 18 Mar 2022 20:10:17 +0000 Subject: [PATCH] bugfix: handle number void with any number of cases * add is_number_void() * numericx_translate() was only handling a void number with one digit as argument, for example a 0. When encontering a void number with more then one digit, the function was entering on a infinite cycle. Now, with the function is_number_void(), numericx_translate() can handle correctly void number with any number of cases. Either with a from numerical system that is infinite (0 == 00 == 000 ...) or if it is not (0 is void, 00 is concrete, 000 is concrete, ...) Signed-off-by: Daniel Santos --- numericx.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/numericx.c b/numericx.c index ccf6f4f..41831e9 100644 --- a/numericx.c +++ b/numericx.c @@ -303,6 +303,39 @@ numeral_to_string(numeral_ptr* numeral, bool result_with_units_on_the_end) return result; } +/** + * @brief Check if number is void. + * + * Check if number is void by testing each digit to see if all of + * number's numerals correspond to void_numeral. + * + * @param number - Number string to be checked. + * @param void_numeral - Numeral that represents void. + * + * @result true if number is void. + * @result false if number is countable. + */ +static bool +is_number_void(char* number, char* void_numeral, bool is_infinite) +{ + if( !is_infinite ) + { + return ( (strlen(number) == 1) && (*number == *void_numeral) ); + } + else + { + while( !(*number == '\0') ) + { + if( *number != *void_numeral ) + return false; + + ++number; + } + + return true; + } +} + /** * @brief Translate string to a different numerical system. * @@ -369,7 +402,7 @@ numericx_translate(char* from, bool from_units_on_the_end, bool from_first_numbe { if( from_first_number_void ) { - if( strlen(number) == 1 && *number == *from_first ) + if( is_number_void(number, from_first, from_infinite_base) ) { free_numeral(counting); free_numeral(result);