added HAWK_ZDIGIT_TO_NUM()

This commit is contained in:
hyung-hwan 2020-05-27 09:32:52 +00:00
parent 303118bc5c
commit 1dbf8046b0
2 changed files with 13 additions and 12 deletions

View File

@ -91,6 +91,11 @@ typedef enum hawk_ooch_prop_t hawk_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 HAWK_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

@ -2615,21 +2615,19 @@ hawk_int_t hawk_uchars_to_int (const hawk_uch_t* str, hawk_oow_t len, int option
} }
else if (rem >= 2 && base == 16) else if (rem >= 2 && base == 16)
{ {
if (*p == '0' && if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
(*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
} }
else if (rem >= 2 && base == 2) else if (rem >= 2 && base == 2)
{ {
if (*p == '0' && if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
(*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
} }
/* process the digits */ /* process the digits */
pp = p; pp = p;
while (p < end) while (p < end)
{ {
digit = HAWK_XDIGIT_TO_NUM(*p); digit = HAWK_ZDIGIT_TO_NUM(*p, base);
if (digit <= - 1 || digit >= base) break; if (digit >= base) break;
n = n * base + digit; n = n * base + digit;
p++; p++;
} }
@ -2701,21 +2699,19 @@ hawk_int_t hawk_bchars_to_int (const hawk_bch_t* str, hawk_oow_t len, int option
} }
else if (rem >= 2 && base == 16) else if (rem >= 2 && base == 16)
{ {
if (*p == '0' && if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
(*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
} }
else if (rem >= 2 && base == 2) else if (rem >= 2 && base == 2)
{ {
if (*p == '0' && if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
(*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
} }
/* process the digits */ /* process the digits */
pp = p; pp = p;
while (p < end) while (p < end)
{ {
digit = HAWK_XDIGIT_TO_NUM(*p); digit = HAWK_ZDIGIT_TO_NUM(*p, base);
if (digit <= - 1 || digit >= base) break; if (digit >= base) break;
n = n * base + digit; n = n * base + digit;
p++; p++;
} }