added the E notation support to some string-to-integer functions

This commit is contained in:
2021-07-12 14:40:51 +00:00
parent 802b8038bd
commit f1b9fcfdd0
21 changed files with 1484 additions and 91 deletions

View File

@ -1,7 +1,7 @@
# Makefile.in generated by automake 1.16.1 from Makefile.am.
# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2018 Free Software Foundation, Inc.
# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@ -250,8 +250,8 @@ am__include_HEADERS_DIST = mio-cfg.h mio-chr.h mio-cmn.h mio-dns.h \
mio-pro.h mio-sck.h mio-skad.h mio-thr.h mio-upac.h mio-utl.h \
mio.h mio-mar.h
HEADERS = $(include_HEADERS)
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) \
$(LISP)mio-cfg.h.in
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) \
mio-cfg.h.in
# Read a list of newline-separated strings from the standard input,
# and print each of them once, without duplicates. Input order is
# *not* preserved.
@ -403,7 +403,6 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@

View File

@ -468,7 +468,7 @@ static int cgi_peer_htrd_peek (mio_htrd_t* htrd, mio_htre_t* req)
const mio_bch_t* endptr;
mio_intmax_t v;
v = mio_bchars_to_intmax(req->attr.status, mio_count_bcstr(req->attr.status), MIO_BCHARS_TO_INTMAX_MAKE_OPTION(0,0,10), &endptr, &is_sober);
v = mio_bchars_to_intmax(req->attr.status, mio_count_bcstr(req->attr.status), MIO_BCHARS_TO_INTMAX_MAKE_OPTION(0,0,0,10), &endptr, &is_sober);
if (*endptr == '\0' && is_sober && v > 0 && v <= MIO_TYPE_MAX(int)) status_code = v;
}

View File

@ -468,7 +468,7 @@ static int thr_peer_htrd_peek (mio_htrd_t* htrd, mio_htre_t* req)
const mio_bch_t* endptr;
mio_intmax_t v;
v = mio_bchars_to_intmax(req->attr.status, mio_count_bcstr(req->attr.status), MIO_BCHARS_TO_INTMAX_MAKE_OPTION(0,0,10), &endptr, &is_sober);
v = mio_bchars_to_intmax(req->attr.status, mio_count_bcstr(req->attr.status), MIO_BCHARS_TO_INTMAX_MAKE_OPTION(0,0,0,10), &endptr, &is_sober);
if (*endptr == '\0' && is_sober && v > 0 && v <= MIO_TYPE_MAX(int)) status_code = v;
}

View File

@ -548,32 +548,38 @@ MIO_EXPORT mio_oow_t mio_byte_to_bcstr (
);
/* ------------------------------------------------------------------------- */
#define MIO_OOCHARS_TO_INTMAX_MAKE_OPTION(ltrim,rtrim,base) (((!!(ltrim)) << 2) | ((!!(rtrim)) << 4) | ((base) << 8))
#define MIO_OOCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) (((!!(e)) << 0) | ((!!(ltrim)) << 2) | ((!!(rtrim)) << 3) | ((base) << 8))
#define MIO_OOCHARS_TO_INTMAX_GET_OPTION_E(option) ((option) & 1)
#define MIO_OOCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) ((option) & 4)
#define MIO_OOCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) ((option) & 8)
#define MIO_OOCHARS_TO_INTMAX_GET_OPTION_BASE(option) ((option) >> 8)
#define MIO_OOCHARS_TO_UINTMAX_MAKE_OPTION(ltrim,rtrim,base) (((!!(ltrim)) << 2) | ((!!(rtrim)) << 4) | ((base) << 8))
#define MIO_OOCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) (((!!(e)) << 0) | ((!!(ltrim)) << 2) | ((!!(rtrim)) << 3) | ((base) << 8))
#define MIO_OOCHARS_TO_UINTMAX_GET_OPTION_E(option) ((option) & 1)
#define MIO_OOCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) ((option) & 4)
#define MIO_OOCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) ((option) & 8)
#define MIO_OOCHARS_TO_UINTMAX_GET_OPTION_BASE(option) ((option) >> 8)
#define MIO_UCHARS_TO_INTMAX_MAKE_OPTION(ltrim,rtrim,base) MIO_OOCHARS_TO_INTMAX_MAKE_OPTION(ltrim,rtrim,base)
#define MIO_UCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) MIO_OOCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base)
#define MIO_UCHARS_TO_INTMAX_GET_OPTION_E(option) MIO_OOCHARS_TO_INTMAX_GET_OPTION_E(option)
#define MIO_UCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) MIO_OOCHARS_TO_INTMAX_GET_OPTION_LTRIM(option)
#define MIO_UCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) MIO_OOCHARS_TO_INTMAX_GET_OPTION_RTRIM(option)
#define MIO_UCHARS_TO_INTMAX_GET_OPTION_BASE(option) MIO_OOCHARS_TO_INTMAX_GET_OPTION_BASE(option)
#define MIO_BCHARS_TO_INTMAX_MAKE_OPTION(ltrim,rtrim,base) MIO_OOCHARS_TO_INTMAX_MAKE_OPTION(ltrim,rtrim,base)
#define MIO_BCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) MIO_OOCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base)
#define MIO_BCHARS_TO_INTMAX_GET_OPTION_E(option) MIO_OOCHARS_TO_INTMAX_GET_OPTION_E(option)
#define MIO_BCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) MIO_OOCHARS_TO_INTMAX_GET_OPTION_LTRIM(option)
#define MIO_BCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) MIO_OOCHARS_TO_INTMAX_GET_OPTION_RTRIM(option)
#define MIO_BCHARS_TO_INTMAX_GET_OPTION_BASE(option) MIO_OOCHARS_TO_INTMAX_GET_OPTION_BASE(option)
#define MIO_UCHARS_TO_UINTMAX_MAKE_OPTION(ltrim,rtrim,base) MIO_OOCHARS_TO_UINTMAX_MAKE_OPTION(ltrim,rtrim,base)
#define MIO_UCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) MIO_OOCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base)
#define MIO_UCHARS_TO_UINTMAX_GET_OPTION_E(option) MIO_OOCHARS_TO_UINTMAX_GET_OPTION_E(option)
#define MIO_UCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) MIO_OOCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option)
#define MIO_UCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) MIO_OOCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option)
#define MIO_UCHARS_TO_UINTMAX_GET_OPTION_BASE(option) MIO_OOCHARS_TO_UINTMAX_GET_OPTION_BASE(option)
#define MIO_BCHARS_TO_UINTMAX_MAKE_OPTION(ltrim,rtrim,base) MIO_OOCHARS_TO_UINTMAX_MAKE_OPTION(ltrim,rtrim,base)
#define MIO_BCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) MIO_OOCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base)
#define MIO_BCHARS_TO_UINTMAX_GET_OPTION_E(option) MIO_OOCHARS_TO_UINTMAX_GET_OPTION_E(option)
#define MIO_BCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) MIO_OOCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option)
#define MIO_BCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) MIO_OOCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option)
#define MIO_BCHARS_TO_UINTMAX_GET_OPTION_BASE(option) MIO_OOCHARS_TO_UINTMAX_GET_OPTION_BASE(option)

View File

@ -1155,6 +1155,33 @@ mio_oow_t mio_byte_to_bcstr (mio_uint8_t byte, mio_bch_t* buf, mio_oow_t size, i
/* ========================================================================= */
#define HANDLE_E() \
if (*p == 'E') \
{ \
mio_uintmax_t e = 0, i; \
int e_neg = 0; \
p++; \
if (*p == '+') \
{ \
p++; \
} \
else if (*p == '-') \
{ \
p++; e_neg = 1; \
} \
while (p < end) \
{ \
digit = MIO_ZDIGIT_TO_NUM(*p, base); \
if (digit >= base) break; \
e = e * base + digit; \
p++; \
} \
if (e_neg) \
for (i = 0; i < e; i++) n /= 10; \
else \
for (i = 0; i < e; i++) n *= 10; \
}
mio_intmax_t mio_uchars_to_intmax (const mio_uch_t* str, mio_oow_t len, int option, const mio_uch_t** endptr, int* is_sober)
{
mio_intmax_t n = 0;
@ -1227,6 +1254,11 @@ mio_intmax_t mio_uchars_to_intmax (const mio_uch_t* str, mio_oow_t len, int opti
p++;
}
if (MIO_UCHARS_TO_INTMAX_GET_OPTION_E(option))
{
HANDLE_E();
}
/* base 8: at least a zero digit has been seen.
* other case: p > pp to be able to have at least 1 meaningful digit. */
if (is_sober) *is_sober = (base == 8 || p > pp);
@ -1313,6 +1345,11 @@ mio_intmax_t mio_bchars_to_intmax (const mio_bch_t* str, mio_oow_t len, int opti
p++;
}
if (MIO_BCHARS_TO_INTMAX_GET_OPTION_E(option))
{
HANDLE_E();
}
/* base 8: at least a zero digit has been seen.
* other case: p > pp to be able to have at least 1 meaningful digit. */
if (is_sober) *is_sober = (base == 8 || p > pp);
@ -1395,6 +1432,11 @@ mio_uintmax_t mio_uchars_to_uintmax (const mio_uch_t* str, mio_oow_t len, int op
p++;
}
if (MIO_UCHARS_TO_UINTMAX_GET_OPTION_E(option))
{
HANDLE_E();
}
/* base 8: at least a zero digit has been seen.
* other case: p > pp to be able to have at least 1 meaningful digit. */
if (is_sober) *is_sober = (base == 8 || p > pp);
@ -1476,6 +1518,11 @@ mio_uintmax_t mio_bchars_to_uintmax (const mio_bch_t* str, mio_oow_t len, int op
p++;
}
if (MIO_BCHARS_TO_UINTMAX_GET_OPTION_E(option))
{
HANDLE_E();
}
/* base 8: at least a zero digit has been seen.
* other case: p > pp to be able to have at least 1 meaningful digit. */
if (is_sober) *is_sober = (base == 8 || p > pp);