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 <dacs.git@brilhante.top>
This commit is contained in:
parent
a8f50b625c
commit
32fbc9c08c
35
numericx.c
35
numericx.c
|
@ -303,6 +303,39 @@ numeral_to_string(numeral_ptr* numeral, bool result_with_units_on_the_end)
|
||||||
return result;
|
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.
|
* @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( 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(counting);
|
||||||
free_numeral(result);
|
free_numeral(result);
|
||||||
|
|
Loading…
Reference in New Issue