From 3afcde257d318e1441e45e7c53fdee43fb001c36 Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Thu, 19 Nov 2015 17:45:29 +0100 Subject: [PATCH] gmio_core/internal: make distinction between fast_strtof() and fast_atof() --- src/gmio_core/internal/fast_atof.h | 226 ++++++-------------------- src/gmio_core/internal/string_parse.h | 24 ++- 2 files changed, 67 insertions(+), 183 deletions(-) diff --git a/src/gmio_core/internal/fast_atof.h b/src/gmio_core/internal/fast_atof.h index 21cfd64..ee1afdd 100644 --- a/src/gmio_core/internal/fast_atof.h +++ b/src/gmio_core/internal/fast_atof.h @@ -57,24 +57,12 @@ static const float fast_atof_table[17] = { */ GMIO_INLINE uint32_t strtoul10(const char* in, const char** out) { - gmio_bool_t overflow=GMIO_FALSE; - uint32_t unsignedValue = 0; - - while ( gmio_ascii_isdigit(*in) ) - { - const uint32_t tmp = ( unsignedValue * 10 ) + ( *in - '0' ); - if (tmp (uint32_t)INT_MAX) - { - if (negative) - return (int32_t)INT_MIN; - else - return (int32_t)INT_MAX; - } - else - { - if (negative) - return -((int32_t)unsignedValue); - else - return (int32_t)unsignedValue; - } -} -/*! Convert a hex-encoded character to an unsigned integer. - * - * \param[in] in The digit to convert. Only digits 0 to 9 and chars A-F,a-f - * will be considered. - * \return The unsigned integer value of the digit. 0xffffffff if the input is - * not hex - */ -GMIO_INLINE uint32_t ctoul16(char in) -{ - if (in >= '0' && in <= '9') - return in - '0'; - else if (in >= 'a' && in <= 'f') - return 10u + in - 'a'; - else if (in >= 'A' && in <= 'F') - return 10u + in - 'A'; - else - return 0xffffffff; -} - -/*! Convert a simple string of base 16 digits into an unsigned 32 bit integer. - * - * \param[in] in: The string of digits to convert. No leading chars are - * allowed, only digits 0 to 9 and chars A-F,a-f are allowed. Parsing stops - * at the first illegal char. - * \param[out] out: (optional) If provided, it will be set to point at the - * first character not used in the calculation. - * \return The unsigned integer value of the digits. If the string specifies - * too many digits to encode in an uint32_t then INT_MAX will be returned. - */ -GMIO_INLINE uint32_t strtoul16(const char* in, const char** out) -{ - gmio_bool_t overflow=GMIO_FALSE; - uint32_t unsignedValue = 0; - - for (;;) - { - uint32_t tmp = 0; - if (gmio_ascii_isdigit(*in)) - tmp = (unsignedValue << 4u) + (*in - '0'); - else if ((*in >= 'A') && (*in <= 'F')) - tmp = (unsignedValue << 4u) + (*in - 'A') + 10; - else if ((*in >= 'a') && (*in <= 'f')) - tmp = (unsignedValue << 4u) + (*in - 'a') + 10; - else - break; - if (tmp= '0') && (*in <= '7')) - tmp = (unsignedValue << 3u) + (*in - '0'); - else - break; - if (tmp