fixed the template hio_chars_to_int/hio_chars_to_uint definitions
This commit is contained in:
parent
3c7f72b795
commit
5c20d20fa0
@ -135,6 +135,7 @@ uninstall-hook:
|
|||||||
$(srcdir)/hio-utl.h: utl-str.m4 hio-utl.h.m4
|
$(srcdir)/hio-utl.h: utl-str.m4 hio-utl.h.m4
|
||||||
m4 -I$(srcdir) $(srcdir)/hio-utl.h.m4 > $(srcdir)/hio-utl.h
|
m4 -I$(srcdir) $(srcdir)/hio-utl.h.m4 > $(srcdir)/hio-utl.h
|
||||||
|
|
||||||
|
# do NOT put $(srcdir) before utl-str.c
|
||||||
utl-str.c: utl-str.m4 utl-str.c.m4
|
utl-str.c: utl-str.m4 utl-str.c.m4
|
||||||
m4 -I$(srcdir) $(srcdir)/utl-str.c.m4 > $(srcdir)/utl-str.c
|
m4 -I$(srcdir) $(srcdir)/utl-str.c.m4 > $(srcdir)/utl-str.c
|
||||||
|
|
||||||
|
@ -1251,6 +1251,7 @@ uninstall-hook:
|
|||||||
$(srcdir)/hio-utl.h: utl-str.m4 hio-utl.h.m4
|
$(srcdir)/hio-utl.h: utl-str.m4 hio-utl.h.m4
|
||||||
m4 -I$(srcdir) $(srcdir)/hio-utl.h.m4 > $(srcdir)/hio-utl.h
|
m4 -I$(srcdir) $(srcdir)/hio-utl.h.m4 > $(srcdir)/hio-utl.h
|
||||||
|
|
||||||
|
# do NOT put $(srcdir) before utl-str.c
|
||||||
utl-str.c: utl-str.m4 utl-str.c.m4
|
utl-str.c: utl-str.m4 utl-str.c.m4
|
||||||
m4 -I$(srcdir) $(srcdir)/utl-str.c.m4 > $(srcdir)/utl-str.c
|
m4 -I$(srcdir) $(srcdir)/utl-str.c.m4 > $(srcdir)/utl-str.c
|
||||||
|
|
||||||
|
@ -82,18 +82,6 @@ typedef enum hio_ooch_prop_t hio_ooch_prop_t;
|
|||||||
typedef enum hio_ooch_prop_t hio_uch_prop_t;
|
typedef enum hio_ooch_prop_t hio_uch_prop_t;
|
||||||
typedef enum hio_ooch_prop_t hio_bch_prop_t;
|
typedef enum hio_ooch_prop_t hio_bch_prop_t;
|
||||||
|
|
||||||
#define HIO_DIGIT_TO_NUM(c) (((c) >= '0' && (c) <= '9')? ((c) - '0'): -1)
|
|
||||||
|
|
||||||
#define HIO_XDIGIT_TO_NUM(c) \
|
|
||||||
(((c) >= '0' && (c) <= '9')? ((c) - '0'): \
|
|
||||||
((c) >= 'A' && (c) <= 'F')? ((c) - 'A' + 10): \
|
|
||||||
((c) >= 'a' && (c) <= 'f')? ((c) - 'a' + 10): -1)
|
|
||||||
|
|
||||||
#define HIO_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
|
||||||
|
@ -1023,4 +1023,19 @@ struct hio_cmgr_t
|
|||||||
# error Unsupported platform
|
# error Unsupported platform
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* =========================================================================
|
||||||
|
* DIGIT-TO-NUMBER CONVERSION
|
||||||
|
* =========================================================================*/
|
||||||
|
#define HIO_DIGIT_TO_NUM(c) (((c) >= '0' && (c) <= '9')? ((c) - '0'): -1)
|
||||||
|
|
||||||
|
#define HIO_XDIGIT_TO_NUM(c) \
|
||||||
|
(((c) >= '0' && (c) <= '9')? ((c) - '0'): \
|
||||||
|
((c) >= 'A' && (c) <= 'F')? ((c) - 'A' + 10): \
|
||||||
|
((c) >= 'a' && (c) <= 'f')? ((c) - 'a' + 10): -1)
|
||||||
|
|
||||||
|
#define HIO_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)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -648,53 +648,53 @@ HIO_EXPORT hio_oow_t hio_byte_to_bcstr (
|
|||||||
);
|
);
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
#define HIO_CHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) (((!!(e)) << 0) | ((!!(ltrim)) << 2) | ((!!(rtrim)) << 3) | ((base) << 8))
|
#define HIO_CHARS_TO_INT_MAKE_OPTION(e,ltrim,rtrim,base) (((!!(e)) << 0) | ((!!(ltrim)) << 2) | ((!!(rtrim)) << 3) | ((base) << 8))
|
||||||
#define HIO_CHARS_TO_INTMAX_GET_OPTION_E(option) ((option) & 1)
|
#define HIO_CHARS_TO_INT_GET_OPTION_E(option) ((option) & 1)
|
||||||
#define HIO_CHARS_TO_INTMAX_GET_OPTION_LTRIM(option) ((option) & 4)
|
#define HIO_CHARS_TO_INT_GET_OPTION_LTRIM(option) ((option) & 4)
|
||||||
#define HIO_CHARS_TO_INTMAX_GET_OPTION_RTRIM(option) ((option) & 8)
|
#define HIO_CHARS_TO_INT_GET_OPTION_RTRIM(option) ((option) & 8)
|
||||||
#define HIO_CHARS_TO_INTMAX_GET_OPTION_BASE(option) ((option) >> 8)
|
#define HIO_CHARS_TO_INT_GET_OPTION_BASE(option) ((option) >> 8)
|
||||||
|
|
||||||
#define HIO_CHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) (((!!(e)) << 0) | ((!!(ltrim)) << 2) | ((!!(rtrim)) << 3) | ((base) << 8))
|
#define HIO_CHARS_TO_UINT_MAKE_OPTION(e,ltrim,rtrim,base) (((!!(e)) << 0) | ((!!(ltrim)) << 2) | ((!!(rtrim)) << 3) | ((base) << 8))
|
||||||
#define HIO_CHARS_TO_UINTMAX_GET_OPTION_E(option) ((option) & 1)
|
#define HIO_CHARS_TO_UINT_GET_OPTION_E(option) ((option) & 1)
|
||||||
#define HIO_CHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) ((option) & 4)
|
#define HIO_CHARS_TO_UINT_GET_OPTION_LTRIM(option) ((option) & 4)
|
||||||
#define HIO_CHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) ((option) & 8)
|
#define HIO_CHARS_TO_UINT_GET_OPTION_RTRIM(option) ((option) & 8)
|
||||||
#define HIO_CHARS_TO_UINTMAX_GET_OPTION_BASE(option) ((option) >> 8)
|
#define HIO_CHARS_TO_UINT_GET_OPTION_BASE(option) ((option) >> 8)
|
||||||
|
|
||||||
#define HIO_OOCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base)
|
#define HIO_OOCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_INT_MAKE_OPTION(e,ltrim,rtrim,base)
|
||||||
#define HIO_OOCHARS_TO_INTMAX_GET_OPTION_E(option) HIO_CHARS_TO_INTMAX_GET_OPTION_E(option)
|
#define HIO_OOCHARS_TO_INTMAX_GET_OPTION_E(option) HIO_CHARS_TO_INT_GET_OPTION_E(option)
|
||||||
#define HIO_OOCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_INTMAX_GET_OPTION_LTRIM(option)
|
#define HIO_OOCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_INT_GET_OPTION_LTRIM(option)
|
||||||
#define HIO_OOCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_INTMAX_GET_OPTION_RTRIM(option)
|
#define HIO_OOCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_INT_GET_OPTION_RTRIM(option)
|
||||||
#define HIO_OOCHARS_TO_INTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_INTMAX_GET_OPTION_BASE(option)
|
#define HIO_OOCHARS_TO_INTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_INT_GET_OPTION_BASE(option)
|
||||||
|
|
||||||
#define HIO_OOCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base)
|
#define HIO_OOCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_UINT_MAKE_OPTION(e,ltrim,rtrim,base)
|
||||||
#define HIO_OOCHARS_TO_UINTMAX_GET_OPTION_E(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_E(option)
|
#define HIO_OOCHARS_TO_UINTMAX_GET_OPTION_E(option) HIO_CHARS_TO_UINT_GET_OPTION_E(option)
|
||||||
#define HIO_OOCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_LTRIM(option)
|
#define HIO_OOCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_UINT_GET_OPTION_LTRIM(option)
|
||||||
#define HIO_OOCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_RTRIM(option)
|
#define HIO_OOCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_UINT_GET_OPTION_RTRIM(option)
|
||||||
#define HIO_OOCHARS_TO_UINTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_BASE(option)
|
#define HIO_OOCHARS_TO_UINTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_UINT_GET_OPTION_BASE(option)
|
||||||
|
|
||||||
#define HIO_UCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base)
|
#define HIO_UCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_INT_MAKE_OPTION(e,ltrim,rtrim,base)
|
||||||
#define HIO_UCHARS_TO_INTMAX_GET_OPTION_E(option) HIO_CHARS_TO_INTMAX_GET_OPTION_E(option)
|
#define HIO_UCHARS_TO_INTMAX_GET_OPTION_E(option) HIO_CHARS_TO_INT_GET_OPTION_E(option)
|
||||||
#define HIO_UCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_INTMAX_GET_OPTION_LTRIM(option)
|
#define HIO_UCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_INT_GET_OPTION_LTRIM(option)
|
||||||
#define HIO_UCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_INTMAX_GET_OPTION_RTRIM(option)
|
#define HIO_UCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_INT_GET_OPTION_RTRIM(option)
|
||||||
#define HIO_UCHARS_TO_INTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_INTMAX_GET_OPTION_BASE(option)
|
#define HIO_UCHARS_TO_INTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_INT_GET_OPTION_BASE(option)
|
||||||
|
|
||||||
#define HIO_BCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base)
|
#define HIO_BCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_INT_MAKE_OPTION(e,ltrim,rtrim,base)
|
||||||
#define HIO_BCHARS_TO_INTMAX_GET_OPTION_E(option) HIO_CHARS_TO_INTMAX_GET_OPTION_E(option)
|
#define HIO_BCHARS_TO_INTMAX_GET_OPTION_E(option) HIO_CHARS_TO_INT_GET_OPTION_E(option)
|
||||||
#define HIO_BCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_INTMAX_GET_OPTION_LTRIM(option)
|
#define HIO_BCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_INT_GET_OPTION_LTRIM(option)
|
||||||
#define HIO_BCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_INTMAX_GET_OPTION_RTRIM(option)
|
#define HIO_BCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_INT_GET_OPTION_RTRIM(option)
|
||||||
#define HIO_BCHARS_TO_INTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_INTMAX_GET_OPTION_BASE(option)
|
#define HIO_BCHARS_TO_INTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_INT_GET_OPTION_BASE(option)
|
||||||
|
|
||||||
#define HIO_UCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base)
|
#define HIO_UCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_UINT_MAKE_OPTION(e,ltrim,rtrim,base)
|
||||||
#define HIO_UCHARS_TO_UINTMAX_GET_OPTION_E(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_E(option)
|
#define HIO_UCHARS_TO_UINTMAX_GET_OPTION_E(option) HIO_CHARS_TO_UINT_GET_OPTION_E(option)
|
||||||
#define HIO_UCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_LTRIM(option)
|
#define HIO_UCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_UINT_GET_OPTION_LTRIM(option)
|
||||||
#define HIO_UCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_RTRIM(option)
|
#define HIO_UCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_UINT_GET_OPTION_RTRIM(option)
|
||||||
#define HIO_UCHARS_TO_UINTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_BASE(option)
|
#define HIO_UCHARS_TO_UINTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_UINT_GET_OPTION_BASE(option)
|
||||||
|
|
||||||
#define HIO_BCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base)
|
#define HIO_BCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_UINT_MAKE_OPTION(e,ltrim,rtrim,base)
|
||||||
#define HIO_BCHARS_TO_UINTMAX_GET_OPTION_E(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_E(option)
|
#define HIO_BCHARS_TO_UINTMAX_GET_OPTION_E(option) HIO_CHARS_TO_UINT_GET_OPTION_E(option)
|
||||||
#define HIO_BCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_LTRIM(option)
|
#define HIO_BCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_UINT_GET_OPTION_LTRIM(option)
|
||||||
#define HIO_BCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_RTRIM(option)
|
#define HIO_BCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_UINT_GET_OPTION_RTRIM(option)
|
||||||
#define HIO_BCHARS_TO_UINTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_BASE(option)
|
#define HIO_BCHARS_TO_UINTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_UINT_GET_OPTION_BASE(option)
|
||||||
|
|
||||||
HIO_EXPORT hio_intmax_t hio_uchars_to_intmax (
|
HIO_EXPORT hio_intmax_t hio_uchars_to_intmax (
|
||||||
const hio_uch_t* str,
|
const hio_uch_t* str,
|
||||||
@ -1133,23 +1133,32 @@ HIO_EXPORT void hio_sip_hash_24 (
|
|||||||
|
|
||||||
/* Some C++ utilities below */
|
/* Some C++ utilities below */
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
template<CHAR_TYPE, INT_TYPE>
|
|
||||||
INT_TYPE hio_chars_to_uint (const CHAR_TYPE* str, hio_oow_t len, int option, const CHAR_TYPE** endptr, int* is_sober)
|
/*
|
||||||
|
static inline int is_space (char c) { return isspace(c); }
|
||||||
|
static inline int is_wspace (wchar_t c) { return iswspace(c); }
|
||||||
|
unsigned x = hio_chars_to_uint<char,unsigned,is_space>("0x12345", 7, 0, NULL, NULL);
|
||||||
|
unsigned y = hio_chars_to_uint<wchar_t,unsigned,is_wspace>(L"0x12345", 7, 0, NULL, NULL);
|
||||||
|
int a = hio_chars_to_int<char,int,is_space>("-0x12345", 8, 0, NULL, NULL);
|
||||||
|
int b = hio_chars_to_int<wchar_t,int,is_wspace>(L"-0x12345", 8, 0, NULL, NULL);
|
||||||
|
*/
|
||||||
|
template<typename CHAR_TYPE, typename INT_TYPE, int (*IS_SPACE)(CHAR_TYPE)>
|
||||||
|
INT_TYPE hio_chars_to_int (const CHAR_TYPE* str, hio_oow_t len, int option, const CHAR_TYPE** endptr, int* is_sober)
|
||||||
{
|
{
|
||||||
INT_TYPE n = 0;
|
INT_TYPE n = 0;
|
||||||
const CHAR_TYPE* p, * pp;
|
const CHAR_TYPE* p, * pp;
|
||||||
const CHAR_TYPE* end;
|
const CHAR_TYPE* end;
|
||||||
hio_oow_t rem;
|
hio_oow_t rem;
|
||||||
int digit, negative = 0;
|
int digit, negative = 0;
|
||||||
int base = HIO_CHARS_TO_INTMAX_GET_OPTION_BASE(option);
|
int base = HIO_CHARS_TO_INT_GET_OPTION_BASE(option);
|
||||||
|
|
||||||
p = str;
|
p = str;
|
||||||
end = str + len;
|
end = str + len;
|
||||||
|
|
||||||
if (HIO_CHARS_TO_INTMAX_GET_OPTION_LTRIM(option))
|
if (HIO_CHARS_TO_INT_GET_OPTION_LTRIM(option))
|
||||||
{
|
{
|
||||||
/* strip off leading spaces */
|
/* strip off leading spaces */
|
||||||
while (p < end && hio_is_bch_space(*p)) p++;
|
while (p < end && IS_SPACE(*p)) p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check for a sign */
|
/* check for a sign */
|
||||||
@ -1206,7 +1215,7 @@ INT_TYPE hio_chars_to_uint (const CHAR_TYPE* str, hio_oow_t len, int option, con
|
|||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HIO_CHARS_TO_INTMAX_GET_OPTION_E(option))
|
if (HIO_CHARS_TO_INT_GET_OPTION_E(option))
|
||||||
{
|
{
|
||||||
if (*p == 'E' || *p == 'e')
|
if (*p == 'E' || *p == 'e')
|
||||||
{
|
{
|
||||||
@ -1239,17 +1248,17 @@ INT_TYPE hio_chars_to_uint (const CHAR_TYPE* str, hio_oow_t len, int option, con
|
|||||||
* other case: p > pp to be able to have at least 1 meaningful digit. */
|
* other case: p > pp to be able to have at least 1 meaningful digit. */
|
||||||
if (is_sober) *is_sober = (base == 8 || p > pp);
|
if (is_sober) *is_sober = (base == 8 || p > pp);
|
||||||
|
|
||||||
if (HIO_CHARS_TO_INTMAX_GET_OPTION_RTRIM(option))
|
if (HIO_CHARS_TO_INT_GET_OPTION_RTRIM(option))
|
||||||
{
|
{
|
||||||
/* consume trailing spaces */
|
/* consume trailing spaces */
|
||||||
while (p < end && hio_is_bch_space(*p)) p++;
|
while (p < end && IS_SPACE(*p)) p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endptr) *endptr = p;
|
if (endptr) *endptr = p;
|
||||||
return (negative)? -n: n;
|
return (negative)? -n: n;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<CHAR_TYPE, UINT_TYPE>
|
template<typename CHAR_TYPE, typename UINT_TYPE, int (*IS_SPACE)(CHAR_TYPE)>
|
||||||
UINT_TYPE hio_chars_to_uint (const CHAR_TYPE* str, hio_oow_t len, int option, const CHAR_TYPE** endptr, int* is_sober)
|
UINT_TYPE hio_chars_to_uint (const CHAR_TYPE* str, hio_oow_t len, int option, const CHAR_TYPE** endptr, int* is_sober)
|
||||||
{
|
{
|
||||||
UINT_TYPE n = 0;
|
UINT_TYPE n = 0;
|
||||||
@ -1257,15 +1266,15 @@ UINT_TYPE hio_chars_to_uint (const CHAR_TYPE* str, hio_oow_t len, int option, co
|
|||||||
const CHAR_TYPE* end;
|
const CHAR_TYPE* end;
|
||||||
hio_oow_t rem;
|
hio_oow_t rem;
|
||||||
int digit;
|
int digit;
|
||||||
int base = HIO_CHARS_TO_UINTMAX_GET_OPTION_BASE(option);
|
int base = HIO_CHARS_TO_UINT_GET_OPTION_BASE(option);
|
||||||
|
|
||||||
p = str;
|
p = str;
|
||||||
end = str + len;
|
end = str + len;
|
||||||
|
|
||||||
if (HIO_CHARS_TO_UINTMAX_GET_OPTION_LTRIM(option))
|
if (HIO_CHARS_TO_UINT_GET_OPTION_LTRIM(option))
|
||||||
{
|
{
|
||||||
/* strip off leading spaces */
|
/* strip off leading spaces */
|
||||||
while (p < end && hio_is_bch_space(*p)) p++;
|
while (p < end && IS_SPACE(*p)) p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check for a sign */
|
/* check for a sign */
|
||||||
@ -1317,7 +1326,7 @@ UINT_TYPE hio_chars_to_uint (const CHAR_TYPE* str, hio_oow_t len, int option, co
|
|||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HIO_CHARS_TO_UINTMAX_GET_OPTION_E(option))
|
if (HIO_CHARS_TO_UINT_GET_OPTION_E(option))
|
||||||
{
|
{
|
||||||
if (*p == 'E' || *p == 'e')
|
if (*p == 'E' || *p == 'e')
|
||||||
{
|
{
|
||||||
@ -1350,16 +1359,17 @@ UINT_TYPE hio_chars_to_uint (const CHAR_TYPE* str, hio_oow_t len, int option, co
|
|||||||
* other case: p > pp to be able to have at least 1 meaningful digit. */
|
* other case: p > pp to be able to have at least 1 meaningful digit. */
|
||||||
if (is_sober) *is_sober = (base == 8 || p > pp);
|
if (is_sober) *is_sober = (base == 8 || p > pp);
|
||||||
|
|
||||||
if (HIO_CHARS_TO_UINTMAX_GET_OPTION_RTRIM(option))
|
if (HIO_CHARS_TO_UINT_GET_OPTION_RTRIM(option))
|
||||||
{
|
{
|
||||||
/* consume trailing spaces */
|
/* consume trailing spaces */
|
||||||
while (p < end && hio_is_bch_space(*p)) p++;
|
while (p < end && IS_SPACE(*p)) p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endptr) *endptr = p;
|
if (endptr) *endptr = p;
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -619,53 +619,53 @@ HIO_EXPORT hio_oow_t hio_byte_to_bcstr (
|
|||||||
);
|
);
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
#define HIO_CHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) (((!!(e)) << 0) | ((!!(ltrim)) << 2) | ((!!(rtrim)) << 3) | ((base) << 8))
|
#define HIO_CHARS_TO_INT_MAKE_OPTION(e,ltrim,rtrim,base) (((!!(e)) << 0) | ((!!(ltrim)) << 2) | ((!!(rtrim)) << 3) | ((base) << 8))
|
||||||
#define HIO_CHARS_TO_INTMAX_GET_OPTION_E(option) ((option) & 1)
|
#define HIO_CHARS_TO_INT_GET_OPTION_E(option) ((option) & 1)
|
||||||
#define HIO_CHARS_TO_INTMAX_GET_OPTION_LTRIM(option) ((option) & 4)
|
#define HIO_CHARS_TO_INT_GET_OPTION_LTRIM(option) ((option) & 4)
|
||||||
#define HIO_CHARS_TO_INTMAX_GET_OPTION_RTRIM(option) ((option) & 8)
|
#define HIO_CHARS_TO_INT_GET_OPTION_RTRIM(option) ((option) & 8)
|
||||||
#define HIO_CHARS_TO_INTMAX_GET_OPTION_BASE(option) ((option) >> 8)
|
#define HIO_CHARS_TO_INT_GET_OPTION_BASE(option) ((option) >> 8)
|
||||||
|
|
||||||
#define HIO_CHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) (((!!(e)) << 0) | ((!!(ltrim)) << 2) | ((!!(rtrim)) << 3) | ((base) << 8))
|
#define HIO_CHARS_TO_UINT_MAKE_OPTION(e,ltrim,rtrim,base) (((!!(e)) << 0) | ((!!(ltrim)) << 2) | ((!!(rtrim)) << 3) | ((base) << 8))
|
||||||
#define HIO_CHARS_TO_UINTMAX_GET_OPTION_E(option) ((option) & 1)
|
#define HIO_CHARS_TO_UINT_GET_OPTION_E(option) ((option) & 1)
|
||||||
#define HIO_CHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) ((option) & 4)
|
#define HIO_CHARS_TO_UINT_GET_OPTION_LTRIM(option) ((option) & 4)
|
||||||
#define HIO_CHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) ((option) & 8)
|
#define HIO_CHARS_TO_UINT_GET_OPTION_RTRIM(option) ((option) & 8)
|
||||||
#define HIO_CHARS_TO_UINTMAX_GET_OPTION_BASE(option) ((option) >> 8)
|
#define HIO_CHARS_TO_UINT_GET_OPTION_BASE(option) ((option) >> 8)
|
||||||
|
|
||||||
#define HIO_OOCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base)
|
#define HIO_OOCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_INT_MAKE_OPTION(e,ltrim,rtrim,base)
|
||||||
#define HIO_OOCHARS_TO_INTMAX_GET_OPTION_E(option) HIO_CHARS_TO_INTMAX_GET_OPTION_E(option)
|
#define HIO_OOCHARS_TO_INTMAX_GET_OPTION_E(option) HIO_CHARS_TO_INT_GET_OPTION_E(option)
|
||||||
#define HIO_OOCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_INTMAX_GET_OPTION_LTRIM(option)
|
#define HIO_OOCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_INT_GET_OPTION_LTRIM(option)
|
||||||
#define HIO_OOCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_INTMAX_GET_OPTION_RTRIM(option)
|
#define HIO_OOCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_INT_GET_OPTION_RTRIM(option)
|
||||||
#define HIO_OOCHARS_TO_INTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_INTMAX_GET_OPTION_BASE(option)
|
#define HIO_OOCHARS_TO_INTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_INT_GET_OPTION_BASE(option)
|
||||||
|
|
||||||
#define HIO_OOCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base)
|
#define HIO_OOCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_UINT_MAKE_OPTION(e,ltrim,rtrim,base)
|
||||||
#define HIO_OOCHARS_TO_UINTMAX_GET_OPTION_E(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_E(option)
|
#define HIO_OOCHARS_TO_UINTMAX_GET_OPTION_E(option) HIO_CHARS_TO_UINT_GET_OPTION_E(option)
|
||||||
#define HIO_OOCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_LTRIM(option)
|
#define HIO_OOCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_UINT_GET_OPTION_LTRIM(option)
|
||||||
#define HIO_OOCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_RTRIM(option)
|
#define HIO_OOCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_UINT_GET_OPTION_RTRIM(option)
|
||||||
#define HIO_OOCHARS_TO_UINTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_BASE(option)
|
#define HIO_OOCHARS_TO_UINTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_UINT_GET_OPTION_BASE(option)
|
||||||
|
|
||||||
#define HIO_UCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base)
|
#define HIO_UCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_INT_MAKE_OPTION(e,ltrim,rtrim,base)
|
||||||
#define HIO_UCHARS_TO_INTMAX_GET_OPTION_E(option) HIO_CHARS_TO_INTMAX_GET_OPTION_E(option)
|
#define HIO_UCHARS_TO_INTMAX_GET_OPTION_E(option) HIO_CHARS_TO_INT_GET_OPTION_E(option)
|
||||||
#define HIO_UCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_INTMAX_GET_OPTION_LTRIM(option)
|
#define HIO_UCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_INT_GET_OPTION_LTRIM(option)
|
||||||
#define HIO_UCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_INTMAX_GET_OPTION_RTRIM(option)
|
#define HIO_UCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_INT_GET_OPTION_RTRIM(option)
|
||||||
#define HIO_UCHARS_TO_INTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_INTMAX_GET_OPTION_BASE(option)
|
#define HIO_UCHARS_TO_INTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_INT_GET_OPTION_BASE(option)
|
||||||
|
|
||||||
#define HIO_BCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base)
|
#define HIO_BCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_INT_MAKE_OPTION(e,ltrim,rtrim,base)
|
||||||
#define HIO_BCHARS_TO_INTMAX_GET_OPTION_E(option) HIO_CHARS_TO_INTMAX_GET_OPTION_E(option)
|
#define HIO_BCHARS_TO_INTMAX_GET_OPTION_E(option) HIO_CHARS_TO_INT_GET_OPTION_E(option)
|
||||||
#define HIO_BCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_INTMAX_GET_OPTION_LTRIM(option)
|
#define HIO_BCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_INT_GET_OPTION_LTRIM(option)
|
||||||
#define HIO_BCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_INTMAX_GET_OPTION_RTRIM(option)
|
#define HIO_BCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_INT_GET_OPTION_RTRIM(option)
|
||||||
#define HIO_BCHARS_TO_INTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_INTMAX_GET_OPTION_BASE(option)
|
#define HIO_BCHARS_TO_INTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_INT_GET_OPTION_BASE(option)
|
||||||
|
|
||||||
#define HIO_UCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base)
|
#define HIO_UCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_UINT_MAKE_OPTION(e,ltrim,rtrim,base)
|
||||||
#define HIO_UCHARS_TO_UINTMAX_GET_OPTION_E(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_E(option)
|
#define HIO_UCHARS_TO_UINTMAX_GET_OPTION_E(option) HIO_CHARS_TO_UINT_GET_OPTION_E(option)
|
||||||
#define HIO_UCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_LTRIM(option)
|
#define HIO_UCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_UINT_GET_OPTION_LTRIM(option)
|
||||||
#define HIO_UCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_RTRIM(option)
|
#define HIO_UCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_UINT_GET_OPTION_RTRIM(option)
|
||||||
#define HIO_UCHARS_TO_UINTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_BASE(option)
|
#define HIO_UCHARS_TO_UINTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_UINT_GET_OPTION_BASE(option)
|
||||||
|
|
||||||
#define HIO_BCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base)
|
#define HIO_BCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HIO_CHARS_TO_UINT_MAKE_OPTION(e,ltrim,rtrim,base)
|
||||||
#define HIO_BCHARS_TO_UINTMAX_GET_OPTION_E(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_E(option)
|
#define HIO_BCHARS_TO_UINTMAX_GET_OPTION_E(option) HIO_CHARS_TO_UINT_GET_OPTION_E(option)
|
||||||
#define HIO_BCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_LTRIM(option)
|
#define HIO_BCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) HIO_CHARS_TO_UINT_GET_OPTION_LTRIM(option)
|
||||||
#define HIO_BCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_RTRIM(option)
|
#define HIO_BCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) HIO_CHARS_TO_UINT_GET_OPTION_RTRIM(option)
|
||||||
#define HIO_BCHARS_TO_UINTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_UINTMAX_GET_OPTION_BASE(option)
|
#define HIO_BCHARS_TO_UINTMAX_GET_OPTION_BASE(option) HIO_CHARS_TO_UINT_GET_OPTION_BASE(option)
|
||||||
|
|
||||||
HIO_EXPORT hio_intmax_t hio_uchars_to_intmax (
|
HIO_EXPORT hio_intmax_t hio_uchars_to_intmax (
|
||||||
const hio_uch_t* str,
|
const hio_uch_t* str,
|
||||||
@ -1104,8 +1104,18 @@ HIO_EXPORT void hio_sip_hash_24 (
|
|||||||
|
|
||||||
/* Some C++ utilities below */
|
/* Some C++ utilities below */
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
template<CHAR_TYPE, INT_TYPE>fn_chars_to_int(hio_chars_to_uint, CHAR_TYPE, INT_TYPE, hio_is_bch_space, HIO_CHARS_TO_INTMAX)
|
|
||||||
template<CHAR_TYPE, UINT_TYPE>fn_chars_to_uint(hio_chars_to_uint, CHAR_TYPE, UINT_TYPE, hio_is_bch_space, HIO_CHARS_TO_UINTMAX)
|
/*
|
||||||
|
static inline int is_space (char c) { return isspace(c); }
|
||||||
|
static inline int is_wspace (wchar_t c) { return iswspace(c); }
|
||||||
|
unsigned x = hio_chars_to_uint<char,unsigned,is_space>("0x12345", 7, 0, NULL, NULL);
|
||||||
|
unsigned y = hio_chars_to_uint<wchar_t,unsigned,is_wspace>(L"0x12345", 7, 0, NULL, NULL);
|
||||||
|
int a = hio_chars_to_int<char,int,is_space>("-0x12345", 8, 0, NULL, NULL);
|
||||||
|
int b = hio_chars_to_int<wchar_t,int,is_wspace>(L"-0x12345", 8, 0, NULL, NULL);
|
||||||
|
*/
|
||||||
|
template<typename CHAR_TYPE, typename INT_TYPE, int (*IS_SPACE)(CHAR_TYPE)>fn_chars_to_int(hio_chars_to_int, CHAR_TYPE, INT_TYPE, IS_SPACE, HIO_CHARS_TO_INT)
|
||||||
|
template<typename CHAR_TYPE, typename UINT_TYPE, int (*IS_SPACE)(CHAR_TYPE)>fn_chars_to_uint(hio_chars_to_uint, CHAR_TYPE, UINT_TYPE, IS_SPACE, HIO_CHARS_TO_UINT)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
#include <hio-skad.h>
|
#include <hio-skad.h>
|
||||||
#include <hio-nwif.h>
|
#include <hio-nwif.h>
|
||||||
#include <hio-fmt.h>
|
#include <hio-fmt.h>
|
||||||
#include <hio-chr.h>
|
|
||||||
#include "hio-prv.h"
|
#include "hio-prv.h"
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -644,6 +644,7 @@ _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _
|
|||||||
]])
|
]])
|
||||||
|
|
||||||
dnl ---------------------------------------------------------------------------
|
dnl ---------------------------------------------------------------------------
|
||||||
|
dnl $4: is_space $5: prefix for some macros
|
||||||
define([[fn_chars_to_uint]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) define([[_int_type_]], $3)
|
define([[fn_chars_to_uint]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) define([[_int_type_]], $3)
|
||||||
_int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _char_type_** endptr, int* is_sober)
|
_int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _char_type_** endptr, int* is_sober)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user