added HAWK_ZDIGIT_TO_NUM()
This commit is contained in:
parent
303118bc5c
commit
1dbf8046b0
@ -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): -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)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -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)
|
||||
{
|
||||
if (*p == '0' &&
|
||||
(*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
||||
if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
||||
}
|
||||
else if (rem >= 2 && base == 2)
|
||||
{
|
||||
if (*p == '0' &&
|
||||
(*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
||||
if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
||||
}
|
||||
|
||||
/* process the digits */
|
||||
pp = p;
|
||||
while (p < end)
|
||||
{
|
||||
digit = HAWK_XDIGIT_TO_NUM(*p);
|
||||
if (digit <= - 1 || digit >= base) break;
|
||||
digit = HAWK_ZDIGIT_TO_NUM(*p, base);
|
||||
if (digit >= base) break;
|
||||
n = n * base + digit;
|
||||
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)
|
||||
{
|
||||
if (*p == '0' &&
|
||||
(*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
||||
if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
||||
}
|
||||
else if (rem >= 2 && base == 2)
|
||||
{
|
||||
if (*p == '0' &&
|
||||
(*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
||||
if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
||||
}
|
||||
|
||||
/* process the digits */
|
||||
pp = p;
|
||||
while (p < end)
|
||||
{
|
||||
digit = HAWK_XDIGIT_TO_NUM(*p);
|
||||
if (digit <= - 1 || digit >= base) break;
|
||||
digit = HAWK_ZDIGIT_TO_NUM(*p, base);
|
||||
if (digit >= base) break;
|
||||
n = n * base + digit;
|
||||
p++;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user