added MIO_ZDIGIT_TO_NUM()

This commit is contained in:
hyung-hwan 2020-05-27 09:53:55 +00:00
parent 349d0f0181
commit 9d2147c245
3 changed files with 9 additions and 32 deletions

View File

@ -91,6 +91,11 @@ typedef enum mio_ooch_prop_t mio_bch_prop_t;
((c) >= 'A' && (c) <= 'F')? ((c) - 'A' + 10): \ ((c) >= 'A' && (c) <= 'F')? ((c) - 'A' + 10): \
((c) >= 'a' && (c) <= 'f')? ((c) - 'a' + 10): -1) ((c) >= 'a' && (c) <= 'f')? ((c) - 'a' + 10): -1)
#define MIO_ZDIGIT_TO_NUM(c,base) \
(((c) >= '0' && (c) <= '9')? ((c) - '0'): \
((c) >= 'A' && (c) <= 'Z')? ((c) - 'A' + 10): \
((c) >= 'a' && (c) <= 'Z')? ((c) - 'a' + 10): base)
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif

View File

@ -184,13 +184,7 @@ static int uchars_to_ipv6 (const mio_uch_t* src, mio_oow_t len, struct in6_addr*
ch = *src++; ch = *src++;
if (ch >= '0' && ch <= '9') v1 = MIO_XDIGIT_TO_NUM(ch);
v1 = ch - '0';
else if (ch >= 'A' && ch <= 'F')
v1 = ch - 'A' + 10;
else if (ch >= 'a' && ch <= 'f')
v1 = ch - 'a' + 10;
else v1 = -1;
if (v1 >= 0) if (v1 >= 0)
{ {
val <<= 4; val <<= 4;
@ -294,13 +288,7 @@ static int bchars_to_ipv6 (const mio_bch_t* src, mio_oow_t len, struct in6_addr*
ch = *src++; ch = *src++;
if (ch >= '0' && ch <= '9') v1 = MIO_XDIGIT_TO_NUM(ch);
v1 = ch - '0';
else if (ch >= 'A' && ch <= 'F')
v1 = ch - 'A' + 10;
else if (ch >= 'a' && ch <= 'f')
v1 = ch - 'a' + 10;
else v1 = -1;
if (v1 >= 0) if (v1 >= 0)
{ {
val <<= 4; val <<= 4;

View File

@ -1221,17 +1221,9 @@ mio_intmax_t mio_uchars_to_intmax (const mio_uch_t* str, mio_oow_t len, int opti
pp = p; pp = p;
while (p < end) while (p < end)
{ {
if (*p >= '0' && *p <= '9') { digit = MIO_ZDIGIT_TO_NUM(*p, base);
digit = *p - '0'; }
else if (*p >= 'A' && *p <= 'Z')
digit = *p - 'A' + 10;
else if (*p >= 'a' && *p <= 'z')
digit = *p - 'a' + 10;
else break;
if (digit >= base) break; if (digit >= base) break;
n = n * base + digit; n = n * base + digit;
p++; p++;
} }
@ -1315,17 +1307,9 @@ mio_intmax_t mio_bchars_to_intmax (const mio_bch_t* str, mio_oow_t len, int opti
pp = p; pp = p;
while (p < end) while (p < end)
{ {
if (*p >= '0' && *p <= '9') digit = MIO_ZDIGIT_TO_NUM(*p, base);
digit = *p - '0';
else if (*p >= 'A' && *p <= 'Z')
digit = *p - 'A' + 10;
else if (*p >= 'a' && *p <= 'z')
digit = *p - 'a' + 10;
else break;
if (digit >= base) break; if (digit >= base) break;
n = n * base + digit; n = n * base + digit;
p++; p++;
} }