diff --git a/hio/lib/Makefile.am b/hio/lib/Makefile.am index 2ca425c..26dfde3 100644 --- a/hio/lib/Makefile.am +++ b/hio/lib/Makefile.am @@ -135,6 +135,7 @@ uninstall-hook: $(srcdir)/hio-utl.h: utl-str.m4 hio-utl.h.m4 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 m4 -I$(srcdir) $(srcdir)/utl-str.c.m4 > $(srcdir)/utl-str.c diff --git a/hio/lib/Makefile.in b/hio/lib/Makefile.in index 44c4fb5..ca27880 100644 --- a/hio/lib/Makefile.in +++ b/hio/lib/Makefile.in @@ -1251,6 +1251,7 @@ uninstall-hook: $(srcdir)/hio-utl.h: utl-str.m4 hio-utl.h.m4 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 m4 -I$(srcdir) $(srcdir)/utl-str.c.m4 > $(srcdir)/utl-str.c diff --git a/hio/lib/hio-chr.h b/hio/lib/hio-chr.h index d5f207d..11a563e 100644 --- a/hio/lib/hio-chr.h +++ b/hio/lib/hio-chr.h @@ -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_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) extern "C" { #endif diff --git a/hio/lib/hio-cmn.h b/hio/lib/hio-cmn.h index 852212c..e7ddc51 100644 --- a/hio/lib/hio-cmn.h +++ b/hio/lib/hio-cmn.h @@ -1023,4 +1023,19 @@ struct hio_cmgr_t # error Unsupported platform #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 diff --git a/hio/lib/hio-utl.h b/hio/lib/hio-utl.h index 14b5acb..0a46f58 100644 --- a/hio/lib/hio-utl.h +++ b/hio/lib/hio-utl.h @@ -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_INTMAX_GET_OPTION_E(option) ((option) & 1) -#define HIO_CHARS_TO_INTMAX_GET_OPTION_LTRIM(option) ((option) & 4) -#define HIO_CHARS_TO_INTMAX_GET_OPTION_RTRIM(option) ((option) & 8) -#define HIO_CHARS_TO_INTMAX_GET_OPTION_BASE(option) ((option) >> 8) +#define HIO_CHARS_TO_INT_MAKE_OPTION(e,ltrim,rtrim,base) (((!!(e)) << 0) | ((!!(ltrim)) << 2) | ((!!(rtrim)) << 3) | ((base) << 8)) +#define HIO_CHARS_TO_INT_GET_OPTION_E(option) ((option) & 1) +#define HIO_CHARS_TO_INT_GET_OPTION_LTRIM(option) ((option) & 4) +#define HIO_CHARS_TO_INT_GET_OPTION_RTRIM(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_UINTMAX_GET_OPTION_E(option) ((option) & 1) -#define HIO_CHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) ((option) & 4) -#define HIO_CHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) ((option) & 8) -#define HIO_CHARS_TO_UINTMAX_GET_OPTION_BASE(option) ((option) >> 8) +#define HIO_CHARS_TO_UINT_MAKE_OPTION(e,ltrim,rtrim,base) (((!!(e)) << 0) | ((!!(ltrim)) << 2) | ((!!(rtrim)) << 3) | ((base) << 8)) +#define HIO_CHARS_TO_UINT_GET_OPTION_E(option) ((option) & 1) +#define HIO_CHARS_TO_UINT_GET_OPTION_LTRIM(option) ((option) & 4) +#define HIO_CHARS_TO_UINT_GET_OPTION_RTRIM(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_GET_OPTION_E(option) HIO_CHARS_TO_INTMAX_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_RTRIM(option) HIO_CHARS_TO_INTMAX_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_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_INT_GET_OPTION_E(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_INT_GET_OPTION_RTRIM(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_GET_OPTION_E(option) HIO_CHARS_TO_UINTMAX_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_RTRIM(option) HIO_CHARS_TO_UINTMAX_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_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_UINT_GET_OPTION_E(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_UINT_GET_OPTION_RTRIM(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_GET_OPTION_E(option) HIO_CHARS_TO_INTMAX_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_RTRIM(option) HIO_CHARS_TO_INTMAX_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_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_INT_GET_OPTION_E(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_INT_GET_OPTION_RTRIM(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_GET_OPTION_E(option) HIO_CHARS_TO_INTMAX_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_RTRIM(option) HIO_CHARS_TO_INTMAX_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_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_INT_GET_OPTION_E(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_INT_GET_OPTION_RTRIM(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_GET_OPTION_E(option) HIO_CHARS_TO_UINTMAX_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_RTRIM(option) HIO_CHARS_TO_UINTMAX_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_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_UINT_GET_OPTION_E(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_UINT_GET_OPTION_RTRIM(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_GET_OPTION_E(option) HIO_CHARS_TO_UINTMAX_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_RTRIM(option) HIO_CHARS_TO_UINTMAX_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_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_UINT_GET_OPTION_E(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_UINT_GET_OPTION_RTRIM(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 ( const hio_uch_t* str, @@ -1133,23 +1133,32 @@ HIO_EXPORT void hio_sip_hash_24 ( /* Some C++ utilities below */ #if defined(__cplusplus) -template -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("0x12345", 7, 0, NULL, NULL); +unsigned y = hio_chars_to_uint(L"0x12345", 7, 0, NULL, NULL); +int a = hio_chars_to_int("-0x12345", 8, 0, NULL, NULL); +int b = hio_chars_to_int(L"-0x12345", 8, 0, NULL, NULL); +*/ +template +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; const CHAR_TYPE* p, * pp; const CHAR_TYPE* end; hio_oow_t rem; 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; 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 */ - while (p < end && hio_is_bch_space(*p)) p++; + while (p < end && IS_SPACE(*p)) p++; } /* 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++; } - if (HIO_CHARS_TO_INTMAX_GET_OPTION_E(option)) + if (HIO_CHARS_TO_INT_GET_OPTION_E(option)) { 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. */ 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 */ - while (p < end && hio_is_bch_space(*p)) p++; + while (p < end && IS_SPACE(*p)) p++; } if (endptr) *endptr = p; return (negative)? -n: n; } -template +template 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; @@ -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; hio_oow_t rem; int digit; - int base = HIO_CHARS_TO_UINTMAX_GET_OPTION_BASE(option); + int base = HIO_CHARS_TO_UINT_GET_OPTION_BASE(option); p = str; 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 */ - while (p < end && hio_is_bch_space(*p)) p++; + while (p < end && IS_SPACE(*p)) p++; } /* 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++; } - if (HIO_CHARS_TO_UINTMAX_GET_OPTION_E(option)) + if (HIO_CHARS_TO_UINT_GET_OPTION_E(option)) { 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. */ 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 */ - while (p < end && hio_is_bch_space(*p)) p++; + while (p < end && IS_SPACE(*p)) p++; } if (endptr) *endptr = p; return n; } + #endif #endif diff --git a/hio/lib/hio-utl.h.m4 b/hio/lib/hio-utl.h.m4 index 7d3a5ff..87de84a 100644 --- a/hio/lib/hio-utl.h.m4 +++ b/hio/lib/hio-utl.h.m4 @@ -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_INTMAX_GET_OPTION_E(option) ((option) & 1) -#define HIO_CHARS_TO_INTMAX_GET_OPTION_LTRIM(option) ((option) & 4) -#define HIO_CHARS_TO_INTMAX_GET_OPTION_RTRIM(option) ((option) & 8) -#define HIO_CHARS_TO_INTMAX_GET_OPTION_BASE(option) ((option) >> 8) +#define HIO_CHARS_TO_INT_MAKE_OPTION(e,ltrim,rtrim,base) (((!!(e)) << 0) | ((!!(ltrim)) << 2) | ((!!(rtrim)) << 3) | ((base) << 8)) +#define HIO_CHARS_TO_INT_GET_OPTION_E(option) ((option) & 1) +#define HIO_CHARS_TO_INT_GET_OPTION_LTRIM(option) ((option) & 4) +#define HIO_CHARS_TO_INT_GET_OPTION_RTRIM(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_UINTMAX_GET_OPTION_E(option) ((option) & 1) -#define HIO_CHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) ((option) & 4) -#define HIO_CHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) ((option) & 8) -#define HIO_CHARS_TO_UINTMAX_GET_OPTION_BASE(option) ((option) >> 8) +#define HIO_CHARS_TO_UINT_MAKE_OPTION(e,ltrim,rtrim,base) (((!!(e)) << 0) | ((!!(ltrim)) << 2) | ((!!(rtrim)) << 3) | ((base) << 8)) +#define HIO_CHARS_TO_UINT_GET_OPTION_E(option) ((option) & 1) +#define HIO_CHARS_TO_UINT_GET_OPTION_LTRIM(option) ((option) & 4) +#define HIO_CHARS_TO_UINT_GET_OPTION_RTRIM(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_GET_OPTION_E(option) HIO_CHARS_TO_INTMAX_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_RTRIM(option) HIO_CHARS_TO_INTMAX_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_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_INT_GET_OPTION_E(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_INT_GET_OPTION_RTRIM(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_GET_OPTION_E(option) HIO_CHARS_TO_UINTMAX_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_RTRIM(option) HIO_CHARS_TO_UINTMAX_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_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_UINT_GET_OPTION_E(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_UINT_GET_OPTION_RTRIM(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_GET_OPTION_E(option) HIO_CHARS_TO_INTMAX_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_RTRIM(option) HIO_CHARS_TO_INTMAX_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_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_INT_GET_OPTION_E(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_INT_GET_OPTION_RTRIM(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_GET_OPTION_E(option) HIO_CHARS_TO_INTMAX_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_RTRIM(option) HIO_CHARS_TO_INTMAX_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_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_INT_GET_OPTION_E(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_INT_GET_OPTION_RTRIM(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_GET_OPTION_E(option) HIO_CHARS_TO_UINTMAX_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_RTRIM(option) HIO_CHARS_TO_UINTMAX_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_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_UINT_GET_OPTION_E(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_UINT_GET_OPTION_RTRIM(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_GET_OPTION_E(option) HIO_CHARS_TO_UINTMAX_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_RTRIM(option) HIO_CHARS_TO_UINTMAX_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_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_UINT_GET_OPTION_E(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_UINT_GET_OPTION_RTRIM(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 ( const hio_uch_t* str, @@ -1104,8 +1104,18 @@ HIO_EXPORT void hio_sip_hash_24 ( /* Some C++ utilities below */ #if defined(__cplusplus) -templatefn_chars_to_int(hio_chars_to_uint, CHAR_TYPE, INT_TYPE, hio_is_bch_space, HIO_CHARS_TO_INTMAX) -templatefn_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("0x12345", 7, 0, NULL, NULL); +unsigned y = hio_chars_to_uint(L"0x12345", 7, 0, NULL, NULL); +int a = hio_chars_to_int("-0x12345", 8, 0, NULL, NULL); +int b = hio_chars_to_int(L"-0x12345", 8, 0, NULL, NULL); +*/ +templatefn_chars_to_int(hio_chars_to_int, CHAR_TYPE, INT_TYPE, IS_SPACE, HIO_CHARS_TO_INT) +templatefn_chars_to_uint(hio_chars_to_uint, CHAR_TYPE, UINT_TYPE, IS_SPACE, HIO_CHARS_TO_UINT) + #endif #endif diff --git a/hio/lib/skad.c b/hio/lib/skad.c index 42adeb2..20ccd3c 100644 --- a/hio/lib/skad.c +++ b/hio/lib/skad.c @@ -25,7 +25,6 @@ #include #include #include -#include #include "hio-prv.h" #include diff --git a/hio/lib/utl-str.m4 b/hio/lib/utl-str.m4 index a424377..aa5d5c3 100644 --- a/hio/lib/utl-str.m4 +++ b/hio/lib/utl-str.m4 @@ -644,6 +644,7 @@ _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _ ]]) 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) _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _char_type_** endptr, int* is_sober) {