updated utl-str.m4 and utl-str.c.m4

This commit is contained in:
hyung-hwan 2021-09-12 02:41:33 +00:00
parent bbfbf53cd8
commit 1bbfee2957
4 changed files with 114 additions and 222 deletions

View File

@ -39,35 +39,6 @@
/* ========================================================================= /* =========================================================================
* ENDIAN CHANGE OF A CONSTANT * ENDIAN CHANGE OF A CONSTANT
* ========================================================================= */ * ========================================================================= */
@ -1142,8 +1113,7 @@ unsigned y = hio_chars_to_uint<wchar_t,unsigned,is_wspace>(L"0x12345", 7, 0, NUL
int a = hio_chars_to_int<char,int,is_space>("-0x12345", 8, 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); int b = hio_chars_to_int<wchar_t,int,is_wspace>(L"-0x12345", 8, 0, NULL, NULL);
*/ */
template<typename CHAR_TYPE, typename INT_TYPE, bool(*IS_SPACE)(CHAR_TYPE)> template<typename CHAR_TYPE, typename INT_TYPE, bool(*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 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;
@ -1258,8 +1228,7 @@ INT_TYPE hio_chars_to_int (const CHAR_TYPE* str, hio_oow_t len, int option, cons
return (negative)? -n: n; return (negative)? -n: n;
} }
template<typename CHAR_TYPE, typename UINT_TYPE, bool(*IS_SPACE)(CHAR_TYPE)> template<typename CHAR_TYPE, typename UINT_TYPE, bool(*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;
const CHAR_TYPE* p, * pp; const CHAR_TYPE* p, * pp;

View File

@ -33,39 +33,6 @@
#include <hio-chr.h> #include <hio-chr.h>
hio_oow_t hio_count_ucstr (const hio_uch_t* str) hio_oow_t hio_count_ucstr (const hio_uch_t* str)
{ {
const hio_uch_t* ptr = str; const hio_uch_t* ptr = str;
@ -73,7 +40,6 @@ hio_oow_t hio_count_ucstr (const hio_uch_t* str)
return ptr - str; return ptr - str;
} }
hio_oow_t hio_count_bcstr (const hio_bch_t* str) hio_oow_t hio_count_bcstr (const hio_bch_t* str)
{ {
const hio_bch_t* ptr = str; const hio_bch_t* ptr = str;
@ -81,8 +47,6 @@ hio_oow_t hio_count_bcstr (const hio_bch_t* str)
return ptr - str; return ptr - str;
} }
int hio_equal_uchars (const hio_uch_t* str1, const hio_uch_t* str2, hio_oow_t len) int hio_equal_uchars (const hio_uch_t* str1, const hio_uch_t* str2, hio_oow_t len)
{ {
hio_oow_t i; hio_oow_t i;
@ -98,7 +62,6 @@ int hio_equal_uchars (const hio_uch_t* str1, const hio_uch_t* str2, hio_oow_t le
return 1; return 1;
} }
int hio_equal_bchars (const hio_bch_t* str1, const hio_bch_t* str2, hio_oow_t len) int hio_equal_bchars (const hio_bch_t* str1, const hio_bch_t* str2, hio_oow_t len)
{ {
hio_oow_t i; hio_oow_t i;
@ -114,8 +77,6 @@ int hio_equal_bchars (const hio_bch_t* str1, const hio_bch_t* str2, hio_oow_t le
return 1; return 1;
} }
int hio_comp_uchars (const hio_uch_t* str1, hio_oow_t len1, const hio_uch_t* str2, hio_oow_t len2, int ignorecase) int hio_comp_uchars (const hio_uch_t* str1, hio_oow_t len1, const hio_uch_t* str2, hio_oow_t len2, int ignorecase)
{ {
hio_uchu_t c1, c2; hio_uchu_t c1, c2;
@ -156,7 +117,6 @@ int hio_comp_uchars (const hio_uch_t* str1, hio_oow_t len1, const hio_uch_t* str
return (str2 < end2)? -1: 0; return (str2 < end2)? -1: 0;
} }
int hio_comp_bchars (const hio_bch_t* str1, hio_oow_t len1, const hio_bch_t* str2, hio_oow_t len2, int ignorecase) int hio_comp_bchars (const hio_bch_t* str1, hio_oow_t len1, const hio_bch_t* str2, hio_oow_t len2, int ignorecase)
{ {
hio_bchu_t c1, c2; hio_bchu_t c1, c2;
@ -197,8 +157,6 @@ int hio_comp_bchars (const hio_bch_t* str1, hio_oow_t len1, const hio_bch_t* str
return (str2 < end2)? -1: 0; return (str2 < end2)? -1: 0;
} }
int hio_comp_ucstr (const hio_uch_t* str1, const hio_uch_t* str2, int ignorecase) int hio_comp_ucstr (const hio_uch_t* str1, const hio_uch_t* str2, int ignorecase)
{ {
if (ignorecase) if (ignorecase)
@ -223,7 +181,6 @@ int hio_comp_ucstr (const hio_uch_t* str1, const hio_uch_t* str2, int ignorecase
} }
} }
int hio_comp_bcstr (const hio_bch_t* str1, const hio_bch_t* str2, int ignorecase) int hio_comp_bcstr (const hio_bch_t* str1, const hio_bch_t* str2, int ignorecase)
{ {
if (ignorecase) if (ignorecase)
@ -248,8 +205,6 @@ int hio_comp_bcstr (const hio_bch_t* str1, const hio_bch_t* str2, int ignorecase
} }
} }
int hio_comp_ucstr_limited (const hio_uch_t* str1, const hio_uch_t* str2, hio_oow_t maxlen, int ignorecase) int hio_comp_ucstr_limited (const hio_uch_t* str1, const hio_uch_t* str2, hio_oow_t maxlen, int ignorecase)
{ {
if (maxlen == 0) return 0; if (maxlen == 0) return 0;
@ -276,7 +231,6 @@ int hio_comp_ucstr_limited (const hio_uch_t* str1, const hio_uch_t* str2, hio_oo
} }
} }
int hio_comp_bcstr_limited (const hio_bch_t* str1, const hio_bch_t* str2, hio_oow_t maxlen, int ignorecase) int hio_comp_bcstr_limited (const hio_bch_t* str1, const hio_bch_t* str2, hio_oow_t maxlen, int ignorecase)
{ {
if (maxlen == 0) return 0; if (maxlen == 0) return 0;
@ -303,8 +257,7 @@ int hio_comp_bcstr_limited (const hio_bch_t* str1, const hio_bch_t* str2, hio_oo
} }
} }
hio_oow_t hio_concat_uchars_to_ucstr (hio_uch_t* buf, hio_oow_t bsz, const hio_uch_t* str, hio_oow_t len)
hio_oow_t hio_concat_uchars_to_ucstr (hio_uch_t* buf, hio_oow_t bsz, const hio_uch_t* str, hio_oow_t len)
{ {
hio_uch_t* p, * p2; hio_uch_t* p, * p2;
const hio_uch_t* end; const hio_uch_t* end;
@ -328,7 +281,7 @@ int hio_comp_bcstr_limited (const hio_bch_t* str1, const hio_bch_t* str2, hio_oo
return p - buf; return p - buf;
} }
hio_oow_t hio_concat_bchars_to_bcstr (hio_bch_t* buf, hio_oow_t bsz, const hio_bch_t* str, hio_oow_t len) hio_oow_t hio_concat_bchars_to_bcstr (hio_bch_t* buf, hio_oow_t bsz, const hio_bch_t* str, hio_oow_t len)
{ {
hio_bch_t* p, * p2; hio_bch_t* p, * p2;
const hio_bch_t* end; const hio_bch_t* end;
@ -352,8 +305,6 @@ int hio_comp_bcstr_limited (const hio_bch_t* str1, const hio_bch_t* str2, hio_oo
return p - buf; return p - buf;
} }
hio_oow_t hio_concat_ucstr (hio_uch_t* buf, hio_oow_t bsz, const hio_uch_t* str) hio_oow_t hio_concat_ucstr (hio_uch_t* buf, hio_oow_t bsz, const hio_uch_t* str)
{ {
hio_uch_t* p, * p2; hio_uch_t* p, * p2;
@ -375,7 +326,6 @@ hio_oow_t hio_concat_ucstr (hio_uch_t* buf, hio_oow_t bsz, const hio_uch_t* str)
return p - buf; return p - buf;
} }
hio_oow_t hio_concat_bcstr (hio_bch_t* buf, hio_oow_t bsz, const hio_bch_t* str) hio_oow_t hio_concat_bcstr (hio_bch_t* buf, hio_oow_t bsz, const hio_bch_t* str)
{ {
hio_bch_t* p, * p2; hio_bch_t* p, * p2;
@ -397,23 +347,18 @@ hio_oow_t hio_concat_bcstr (hio_bch_t* buf, hio_oow_t bsz, const hio_bch_t* str)
return p - buf; return p - buf;
} }
void hio_fill_uchars (hio_uch_t* dst, hio_uch_t ch, hio_oow_t len) void hio_fill_uchars (hio_uch_t* dst, hio_uch_t ch, hio_oow_t len)
{ {
hio_oow_t i; hio_oow_t i;
for (i = 0; i < len; i++) dst[i] = ch; for (i = 0; i < len; i++) dst[i] = ch;
} }
void hio_fill_bchars (hio_bch_t* dst, hio_bch_t ch, hio_oow_t len) void hio_fill_bchars (hio_bch_t* dst, hio_bch_t ch, hio_oow_t len)
{ {
hio_oow_t i; hio_oow_t i;
for (i = 0; i < len; i++) dst[i] = ch; for (i = 0; i < len; i++) dst[i] = ch;
} }
hio_uch_t* hio_find_uchar (const hio_uch_t* ptr, hio_oow_t len, hio_uch_t c) hio_uch_t* hio_find_uchar (const hio_uch_t* ptr, hio_oow_t len, hio_uch_t c)
{ {
const hio_uch_t* end; const hio_uch_t* end;
@ -428,7 +373,6 @@ hio_uch_t* hio_find_uchar (const hio_uch_t* ptr, hio_oow_t len, hio_uch_t c)
return HIO_NULL; return HIO_NULL;
} }
hio_bch_t* hio_find_bchar (const hio_bch_t* ptr, hio_oow_t len, hio_bch_t c) hio_bch_t* hio_find_bchar (const hio_bch_t* ptr, hio_oow_t len, hio_bch_t c)
{ {
const hio_bch_t* end; const hio_bch_t* end;
@ -443,8 +387,6 @@ hio_bch_t* hio_find_bchar (const hio_bch_t* ptr, hio_oow_t len, hio_bch_t c)
return HIO_NULL; return HIO_NULL;
} }
hio_uch_t* hio_rfind_uchar (const hio_uch_t* ptr, hio_oow_t len, hio_uch_t c) hio_uch_t* hio_rfind_uchar (const hio_uch_t* ptr, hio_oow_t len, hio_uch_t c)
{ {
const hio_uch_t* cur; const hio_uch_t* cur;
@ -459,7 +401,6 @@ hio_uch_t* hio_rfind_uchar (const hio_uch_t* ptr, hio_oow_t len, hio_uch_t c)
return HIO_NULL; return HIO_NULL;
} }
hio_bch_t* hio_rfind_bchar (const hio_bch_t* ptr, hio_oow_t len, hio_bch_t c) hio_bch_t* hio_rfind_bchar (const hio_bch_t* ptr, hio_oow_t len, hio_bch_t c)
{ {
const hio_bch_t* cur; const hio_bch_t* cur;
@ -474,8 +415,6 @@ hio_bch_t* hio_rfind_bchar (const hio_bch_t* ptr, hio_oow_t len, hio_bch_t c)
return HIO_NULL; return HIO_NULL;
} }
hio_uch_t* hio_find_uchar_in_ucstr (const hio_uch_t* ptr, hio_uch_t c) hio_uch_t* hio_find_uchar_in_ucstr (const hio_uch_t* ptr, hio_uch_t c)
{ {
while (*ptr != '\0') while (*ptr != '\0')
@ -487,7 +426,6 @@ hio_uch_t* hio_find_uchar_in_ucstr (const hio_uch_t* ptr, hio_uch_t c)
return HIO_NULL; return HIO_NULL;
} }
hio_bch_t* hio_find_bchar_in_bcstr (const hio_bch_t* ptr, hio_bch_t c) hio_bch_t* hio_find_bchar_in_bcstr (const hio_bch_t* ptr, hio_bch_t c)
{ {
while (*ptr != '\0') while (*ptr != '\0')
@ -499,8 +437,6 @@ hio_bch_t* hio_find_bchar_in_bcstr (const hio_bch_t* ptr, hio_bch_t c)
return HIO_NULL; return HIO_NULL;
} }
hio_uch_t* hio_trim_uchars (const hio_uch_t* str, hio_oow_t* len, int flags) hio_uch_t* hio_trim_uchars (const hio_uch_t* str, hio_oow_t* len, int flags)
{ {
const hio_uch_t* p = str, * end = str + *len; const hio_uch_t* p = str, * end = str + *len;
@ -543,7 +479,6 @@ hio_uch_t* hio_trim_uchars (const hio_uch_t* str, hio_oow_t* len, int flags)
return (hio_uch_t*)str; return (hio_uch_t*)str;
} }
hio_bch_t* hio_trim_bchars (const hio_bch_t* str, hio_oow_t* len, int flags) hio_bch_t* hio_trim_bchars (const hio_bch_t* str, hio_oow_t* len, int flags)
{ {
const hio_bch_t* p = str, * end = str + *len; const hio_bch_t* p = str, * end = str + *len;
@ -586,8 +521,6 @@ hio_bch_t* hio_trim_bchars (const hio_bch_t* str, hio_oow_t* len, int flags)
return (hio_bch_t*)str; return (hio_bch_t*)str;
} }
int hio_split_ucstr (hio_uch_t* s, const hio_uch_t* delim, hio_uch_t lquote, hio_uch_t rquote, hio_uch_t escape) int hio_split_ucstr (hio_uch_t* s, const hio_uch_t* delim, hio_uch_t lquote, hio_uch_t rquote, hio_uch_t escape)
{ {
hio_uch_t* p = s, *d; hio_uch_t* p = s, *d;
@ -826,7 +759,6 @@ exit_point:
return cnt; return cnt;
} }
int hio_split_bcstr (hio_bch_t* s, const hio_bch_t* delim, hio_bch_t lquote, hio_bch_t rquote, hio_bch_t escape) int hio_split_bcstr (hio_bch_t* s, const hio_bch_t* delim, hio_bch_t lquote, hio_bch_t rquote, hio_bch_t escape)
{ {
hio_bch_t* p = s, *d; hio_bch_t* p = s, *d;
@ -1065,8 +997,6 @@ exit_point:
return cnt; return cnt;
} }
hio_intmax_t hio_uchars_to_intmax (const hio_uch_t* str, hio_oow_t len, int option, const hio_uch_t** endptr, int* is_sober) hio_intmax_t hio_uchars_to_intmax (const hio_uch_t* str, hio_oow_t len, int option, const hio_uch_t** endptr, int* is_sober)
{ {
hio_intmax_t n = 0; hio_intmax_t n = 0;
@ -1182,7 +1112,6 @@ hio_intmax_t hio_uchars_to_intmax (const hio_uch_t* str, hio_oow_t len, int opti
return (negative)? -n: n; return (negative)? -n: n;
} }
hio_intmax_t hio_bchars_to_intmax (const hio_bch_t* str, hio_oow_t len, int option, const hio_bch_t** endptr, int* is_sober) hio_intmax_t hio_bchars_to_intmax (const hio_bch_t* str, hio_oow_t len, int option, const hio_bch_t** endptr, int* is_sober)
{ {
hio_intmax_t n = 0; hio_intmax_t n = 0;
@ -1298,8 +1227,6 @@ hio_intmax_t hio_bchars_to_intmax (const hio_bch_t* str, hio_oow_t len, int opti
return (negative)? -n: n; return (negative)? -n: n;
} }
hio_uintmax_t hio_uchars_to_uintmax (const hio_uch_t* str, hio_oow_t len, int option, const hio_uch_t** endptr, int* is_sober) hio_uintmax_t hio_uchars_to_uintmax (const hio_uch_t* str, hio_oow_t len, int option, const hio_uch_t** endptr, int* is_sober)
{ {
hio_uintmax_t n = 0; hio_uintmax_t n = 0;
@ -1410,7 +1337,6 @@ hio_uintmax_t hio_uchars_to_uintmax (const hio_uch_t* str, hio_oow_t len, int op
return n; return n;
} }
hio_uintmax_t hio_bchars_to_uintmax (const hio_bch_t* str, hio_oow_t len, int option, const hio_bch_t** endptr, int* is_sober) hio_uintmax_t hio_bchars_to_uintmax (const hio_bch_t* str, hio_oow_t len, int option, const hio_bch_t** endptr, int* is_sober)
{ {
hio_uintmax_t n = 0; hio_uintmax_t n = 0;

View File

@ -31,52 +31,52 @@
#include "hio-prv.h" #include "hio-prv.h"
#include <hio-chr.h> #include <hio-chr.h>
dnl
dnl --------------------------------------------------------------------------- dnl ---------------------------------------------------------------------------
include(`utl-str.m4') include(`utl-str.m4')dnl
dnl --------------------------------------------------------------------------- dnl ---------------------------------------------------------------------------
dnl
fn_count_cstr(hio_count_ucstr, hio_uch_t) fn_count_cstr(hio_count_ucstr, hio_uch_t)
fn_count_cstr(hio_count_bcstr, hio_bch_t) fn_count_cstr(hio_count_bcstr, hio_bch_t)
dnl --
fn_equal_chars(hio_equal_uchars, hio_uch_t) fn_equal_chars(hio_equal_uchars, hio_uch_t)
fn_equal_chars(hio_equal_bchars, hio_bch_t) fn_equal_chars(hio_equal_bchars, hio_bch_t)
dnl --
fn_comp_chars(hio_comp_uchars, hio_uch_t, hio_uchu_t, hio_to_uch_lower) fn_comp_chars(hio_comp_uchars, hio_uch_t, hio_uchu_t, hio_to_uch_lower)
fn_comp_chars(hio_comp_bchars, hio_bch_t, hio_bchu_t, hio_to_bch_lower) fn_comp_chars(hio_comp_bchars, hio_bch_t, hio_bchu_t, hio_to_bch_lower)
dnl --
fn_comp_cstr(hio_comp_ucstr, hio_uch_t, hio_uchu_t, hio_to_uch_lower) fn_comp_cstr(hio_comp_ucstr, hio_uch_t, hio_uchu_t, hio_to_uch_lower)
fn_comp_cstr(hio_comp_bcstr, hio_bch_t, hio_bchu_t, hio_to_bch_lower) fn_comp_cstr(hio_comp_bcstr, hio_bch_t, hio_bchu_t, hio_to_bch_lower)
dnl --
fn_comp_cstr_limited(hio_comp_ucstr_limited, hio_uch_t, hio_uchu_t, hio_to_uch_lower) fn_comp_cstr_limited(hio_comp_ucstr_limited, hio_uch_t, hio_uchu_t, hio_to_uch_lower)
fn_comp_cstr_limited(hio_comp_bcstr_limited, hio_bch_t, hio_bchu_t, hio_to_bch_lower) fn_comp_cstr_limited(hio_comp_bcstr_limited, hio_bch_t, hio_bchu_t, hio_to_bch_lower)
dnl --
fn_concat_chars_to_cstr(hio_concat_uchars_to_ucstr, hio_uch_t, hio_count_ucstr) fn_concat_chars_to_cstr(hio_concat_uchars_to_ucstr, hio_uch_t, hio_count_ucstr)
fn_concat_chars_to_cstr(hio_concat_bchars_to_bcstr, hio_bch_t, hio_count_bcstr) fn_concat_chars_to_cstr(hio_concat_bchars_to_bcstr, hio_bch_t, hio_count_bcstr)
dnl --
fn_concat_cstr(hio_concat_ucstr, hio_uch_t, hio_count_ucstr) fn_concat_cstr(hio_concat_ucstr, hio_uch_t, hio_count_ucstr)
fn_concat_cstr(hio_concat_bcstr, hio_bch_t, hio_count_bcstr) fn_concat_cstr(hio_concat_bcstr, hio_bch_t, hio_count_bcstr)
dnl --
fn_fill_chars(hio_fill_uchars, hio_uch_t) fn_fill_chars(hio_fill_uchars, hio_uch_t)
fn_fill_chars(hio_fill_bchars, hio_bch_t) fn_fill_chars(hio_fill_bchars, hio_bch_t)
dnl --
fn_find_char(hio_find_uchar, hio_uch_t) fn_find_char(hio_find_uchar, hio_uch_t)
fn_find_char(hio_find_bchar, hio_bch_t) fn_find_char(hio_find_bchar, hio_bch_t)
dnl --
fn_rfind_char(hio_rfind_uchar, hio_uch_t) fn_rfind_char(hio_rfind_uchar, hio_uch_t)
fn_rfind_char(hio_rfind_bchar, hio_bch_t) fn_rfind_char(hio_rfind_bchar, hio_bch_t)
dnl --
fn_find_char_in_cstr(hio_find_uchar_in_ucstr, hio_uch_t) fn_find_char_in_cstr(hio_find_uchar_in_ucstr, hio_uch_t)
fn_find_char_in_cstr(hio_find_bchar_in_bcstr, hio_bch_t) fn_find_char_in_cstr(hio_find_bchar_in_bcstr, hio_bch_t)
dnl --
fn_trim_chars(hio_trim_uchars, hio_uch_t, hio_is_uch_space, HIO_TRIM_UCHARS) fn_trim_chars(hio_trim_uchars, hio_uch_t, hio_is_uch_space, HIO_TRIM_UCHARS)
fn_trim_chars(hio_trim_bchars, hio_bch_t, hio_is_bch_space, HIO_TRIM_BCHARS) fn_trim_chars(hio_trim_bchars, hio_bch_t, hio_is_bch_space, HIO_TRIM_BCHARS)
dnl --
fn_split_cstr(hio_split_ucstr, hio_uch_t, hio_is_uch_space, hio_copy_ucstr_unlimited) fn_split_cstr(hio_split_ucstr, hio_uch_t, hio_is_uch_space, hio_copy_ucstr_unlimited)
fn_split_cstr(hio_split_bcstr, hio_bch_t, hio_is_bch_space, hio_copy_bcstr_unlimited) fn_split_cstr(hio_split_bcstr, hio_bch_t, hio_is_bch_space, hio_copy_bcstr_unlimited)
dnl --
fn_chars_to_int(hio_uchars_to_intmax, hio_uch_t, hio_intmax_t, hio_is_uch_space, HIO_UCHARS_TO_INTMAX) fn_chars_to_int(hio_uchars_to_intmax, hio_uch_t, hio_intmax_t, hio_is_uch_space, HIO_UCHARS_TO_INTMAX)
fn_chars_to_int(hio_bchars_to_intmax, hio_bch_t, hio_intmax_t, hio_is_bch_space, HIO_BCHARS_TO_INTMAX) fn_chars_to_int(hio_bchars_to_intmax, hio_bch_t, hio_intmax_t, hio_is_bch_space, HIO_BCHARS_TO_INTMAX)
dnl --
fn_chars_to_uint(hio_uchars_to_uintmax, hio_uch_t, hio_uintmax_t, hio_is_uch_space, HIO_UCHARS_TO_UINTMAX) fn_chars_to_uint(hio_uchars_to_uintmax, hio_uch_t, hio_uintmax_t, hio_is_uch_space, HIO_UCHARS_TO_UINTMAX)
fn_chars_to_uint(hio_bchars_to_uintmax, hio_bch_t, hio_uintmax_t, hio_is_bch_space, HIO_BCHARS_TO_UINTMAX) fn_chars_to_uint(hio_bchars_to_uintmax, hio_bch_t, hio_uintmax_t, hio_is_bch_space, HIO_BCHARS_TO_UINTMAX)

View File

@ -1,18 +1,17 @@
dnl --------------------------------------------------------------------------- dnl ---------------------------------------------------------------------------
changequote(`[[', `]]') changequote(`[[', `]]')dnl
dnl --------------------------------------------------------------------------- dnl ---------------------------------------------------------------------------
define([[fn_count_cstr]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) define([[fn_count_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
hio_oow_t _fn_name_ (const _char_type_* str) hio_oow_t _fn_name_ (const _char_type_* str)
{ {
const _char_type_* ptr = str; const _char_type_* ptr = str;
while (*ptr != '\0') ptr++; while (*ptr != '\0') ptr++;
return ptr - str; return ptr - str;
} }
]]) popdef([[_fn_name_]])popdef([[_char_type_]])dnl
]])dnl
dnl --------------------------------------------------------------------------- dnl ---------------------------------------------------------------------------
define([[fn_equal_chars]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) define([[fn_equal_chars]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
int _fn_name_ (const _char_type_* str1, const _char_type_* str2, hio_oow_t len) int _fn_name_ (const _char_type_* str1, const _char_type_* str2, hio_oow_t len)
{ {
hio_oow_t i; hio_oow_t i;
@ -27,10 +26,10 @@ int _fn_name_ (const _char_type_* str1, const _char_type_* str2, hio_oow_t len)
return 1; return 1;
} }
]]) popdef([[_fn_name_]])popdef([[_char_type_]])dnl
]])dnl
dnl --------------------------------------------------------------------------- dnl ---------------------------------------------------------------------------
define([[fn_comp_chars]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) define([[_chau_type_]], $3) define([[fn_comp_chars]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_chau_type_]], $3)pushdef([[_to_lower_]], $4)dnl
int _fn_name_ (const _char_type_* str1, hio_oow_t len1, const _char_type_* str2, hio_oow_t len2, int ignorecase) int _fn_name_ (const _char_type_* str1, hio_oow_t len1, const _char_type_* str2, hio_oow_t len2, int ignorecase)
{ {
_chau_type_ c1, c2; _chau_type_ c1, c2;
@ -41,10 +40,10 @@ int _fn_name_ (const _char_type_* str1, hio_oow_t len1, const _char_type_* str2,
{ {
while (str1 < end1) while (str1 < end1)
{ {
c1 = $4(*str1); c1 = _to_lower_()(*str1);
if (str2 < end2) if (str2 < end2)
{ {
c2 = $4(*str2); c2 = _to_lower_()(*str2);
if (c1 > c2) return 1; if (c1 > c2) return 1;
if (c1 < c2) return -1; if (c1 < c2) return -1;
} }
@ -70,21 +69,21 @@ int _fn_name_ (const _char_type_* str1, hio_oow_t len1, const _char_type_* str2,
return (str2 < end2)? -1: 0; return (str2 < end2)? -1: 0;
} }
]]) popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_chau_type_]])popdef([[_to_lower_]])dnl
]])dnl
dnl --------------------------------------------------------------------------- dnl ---------------------------------------------------------------------------
define([[fn_comp_cstr]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) define([[_chau_type_]], $3) define([[fn_comp_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_chau_type_]], $3)pushdef([[_to_lower_]], $4)dnl
int _fn_name_ (const _char_type_* str1, const _char_type_* str2, int ignorecase) int _fn_name_ (const _char_type_* str1, const _char_type_* str2, int ignorecase)
{ {
if (ignorecase) if (ignorecase)
{ {
while ($4(*str1) == $4(*str2)) while (_to_lower_()(*str1) == _to_lower_()(*str2))
{ {
if (*str1 == '\0') return 0; if (*str1 == '\0') return 0;
str1++; str2++; str1++; str2++;
} }
return ((_chau_type_)$4(*str1) > (_chau_type_)$4(*str2))? 1: -1; return ((_chau_type_)_to_lower_()(*str1) > (_chau_type_)_to_lower_()(*str2))? 1: -1;
} }
else else
{ {
@ -97,23 +96,23 @@ int _fn_name_ (const _char_type_* str1, const _char_type_* str2, int ignorecase)
return ((_chau_type_)*str1 > (_chau_type_)*str2)? 1: -1; return ((_chau_type_)*str1 > (_chau_type_)*str2)? 1: -1;
} }
} }
]]) popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_chau_type_]])popdef([[_to_lower_]])dnl
]])dnl
dnl --------------------------------------------------------------------------- dnl ---------------------------------------------------------------------------
define([[fn_comp_cstr_limited]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) define([[_chau_type_]], $3) define([[fn_comp_cstr_limited]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_chau_type_]], $3)pushdef([[_to_lower_]], $4)dnl
int _fn_name_ (const _char_type_* str1, const _char_type_* str2, hio_oow_t maxlen, int ignorecase) int _fn_name_ (const _char_type_* str1, const _char_type_* str2, hio_oow_t maxlen, int ignorecase)
{ {
if (maxlen == 0) return 0; if (maxlen == 0) return 0;
if (ignorecase) if (ignorecase)
{ {
while ($4(*str1) == $4(*str2)) while (_to_lower_()(*str1) == _to_lower_()(*str2))
{ {
if (*str1 == '\0' || maxlen == 1) return 0; if (*str1 == '\0' || maxlen == 1) return 0;
str1++; str2++; maxlen--; str1++; str2++; maxlen--;
} }
return ((_chau_type_)$4(*str1) > (_chau_type_)$4(*str2))? 1: -1; return ((_chau_type_)_to_lower_()(*str1) > (_chau_type_)_to_lower_()(*str2))? 1: -1;
} }
else else
{ {
@ -126,17 +125,17 @@ int _fn_name_ (const _char_type_* str1, const _char_type_* str2, hio_oow_t maxle
return ((_chau_type_)*str1 > (_chau_type_)*str2)? 1: -1; return ((_chau_type_)*str1 > (_chau_type_)*str2)? 1: -1;
} }
} }
]]) popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_chau_type_]])popdef([[_to_lower_]])dnl
]])dnl
dnl --------------------------------------------------------------------------- dnl ---------------------------------------------------------------------------
define([[fn_concat_chars_to_cstr]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) dnl: $3 count_str define([[fn_concat_chars_to_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_count_str_]], $3)dnl
hio_oow_t _fn_name_ (_char_type_* buf, hio_oow_t bsz, const _char_type_* str, hio_oow_t len) hio_oow_t _fn_name_ (_char_type_* buf, hio_oow_t bsz, const _char_type_* str, hio_oow_t len)
{ {
_char_type_* p, * p2; _char_type_* p, * p2;
const _char_type_* end; const _char_type_* end;
hio_oow_t blen; hio_oow_t blen;
blen = $3(buf); blen = _count_str_()(buf);
if (blen >= bsz) return blen; /* something wrong */ if (blen >= bsz) return blen; /* something wrong */
p = buf + blen; p = buf + blen;
@ -153,17 +152,17 @@ hio_oow_t _fn_name_ (_char_type_* buf, hio_oow_t bsz, const _char_type_* str, hi
if (bsz > 0) *p = '\0'; if (bsz > 0) *p = '\0';
return p - buf; return p - buf;
} }
]]) popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_count_str_]])dnl
]])dnl
dnl --------------------------------------------------------------------------- dnl ---------------------------------------------------------------------------
dnl $3: count_str define([[fn_concat_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_count_str_]], $3)dnl
define([[fn_concat_cstr]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2)
hio_oow_t _fn_name_ (_char_type_* buf, hio_oow_t bsz, const _char_type_* str) hio_oow_t _fn_name_ (_char_type_* buf, hio_oow_t bsz, const _char_type_* str)
{ {
_char_type_* p, * p2; _char_type_* p, * p2;
hio_oow_t blen; hio_oow_t blen;
blen = $3(buf); blen = _count_str_()(buf);
if (blen >= bsz) return blen; /* something wrong */ if (blen >= bsz) return blen; /* something wrong */
p = buf + blen; p = buf + blen;
@ -178,19 +177,19 @@ hio_oow_t _fn_name_ (_char_type_* buf, hio_oow_t bsz, const _char_type_* str)
if (bsz > 0) *p = '\0'; if (bsz > 0) *p = '\0';
return p - buf; return p - buf;
} }
]]) popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_count_str_]])dnl
]])dnl
dnl --------------------------------------------------------------------------- dnl ---------------------------------------------------------------------------
define([[fn_fill_chars]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) define([[fn_fill_chars]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
void _fn_name_ (_char_type_* dst, _char_type_ ch, hio_oow_t len) void _fn_name_ (_char_type_* dst, _char_type_ ch, hio_oow_t len)
{ {
hio_oow_t i; hio_oow_t i;
for (i = 0; i < len; i++) dst[i] = ch; for (i = 0; i < len; i++) dst[i] = ch;
} }
]]) popdef([[_fn_name_]])popdef([[_char_type_]])dnl
]])dnl
dnl --------------------------------------------------------------------------- dnl ---------------------------------------------------------------------------
define([[fn_find_char]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) define([[fn_find_char]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
_char_type_* _fn_name_ (const _char_type_* ptr, hio_oow_t len, _char_type_ c) _char_type_* _fn_name_ (const _char_type_* ptr, hio_oow_t len, _char_type_ c)
{ {
const _char_type_* end; const _char_type_* end;
@ -204,10 +203,10 @@ _char_type_* _fn_name_ (const _char_type_* ptr, hio_oow_t len, _char_type_ c)
return HIO_NULL; return HIO_NULL;
} }
]]) popdef([[_fn_name_]])popdef([[_char_type_]])dnl
]])dnl
dnl --------------------------------------------------------------------------- dnl ---------------------------------------------------------------------------
define([[fn_rfind_char]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) define([[fn_rfind_char]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
_char_type_* _fn_name_ (const _char_type_* ptr, hio_oow_t len, _char_type_ c) _char_type_* _fn_name_ (const _char_type_* ptr, hio_oow_t len, _char_type_ c)
{ {
const _char_type_* cur; const _char_type_* cur;
@ -221,10 +220,10 @@ _char_type_* _fn_name_ (const _char_type_* ptr, hio_oow_t len, _char_type_ c)
return HIO_NULL; return HIO_NULL;
} }
]]) popdef([[_fn_name_]])popdef([[_char_type_]])dnl
]])dnl
dnl --------------------------------------------------------------------------- dnl ---------------------------------------------------------------------------
define([[fn_find_char_in_cstr]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) define([[fn_find_char_in_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
_char_type_* _fn_name_ (const _char_type_* ptr, _char_type_ c) _char_type_* _fn_name_ (const _char_type_* ptr, _char_type_ c)
{ {
while (*ptr != '\0') while (*ptr != '\0')
@ -235,11 +234,10 @@ _char_type_* _fn_name_ (const _char_type_* ptr, _char_type_ c)
return HIO_NULL; return HIO_NULL;
} }
]]) popdef([[_fn_name_]])popdef([[_char_type_]])dnl
]])dnl
dnl --------------------------------------------------------------------------- dnl ---------------------------------------------------------------------------
dnl $3: is_space $4: prefix for option values define([[fn_trim_chars]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_is_space_]], $3)pushdef([[_prefix_]], $4)dnl
define([[fn_trim_chars]], [[define([[_fn_name_]], $1) define([[_char_type_]], $2)
_char_type_* _fn_name_ (const _char_type_* str, hio_oow_t* len, int flags) _char_type_* _fn_name_ (const _char_type_* str, hio_oow_t* len, int flags)
{ {
const _char_type_* p = str, * end = str + *len; const _char_type_* p = str, * end = str + *len;
@ -250,7 +248,7 @@ _char_type_* _fn_name_ (const _char_type_* str, hio_oow_t* len, int flags)
do do
{ {
if (!$3(*p)) if (!_is_space_()(*p))
{ {
if (s == HIO_NULL) s = p; if (s == HIO_NULL) s = p;
e = p; e = p;
@ -261,11 +259,11 @@ _char_type_* _fn_name_ (const _char_type_* str, hio_oow_t* len, int flags)
if (e) if (e)
{ {
if (flags & $4_RIGHT) if (flags & _prefix_()_RIGHT)
{ {
*len -= end - e - 1; *len -= end - e - 1;
} }
if (flags & $4_LEFT) if (flags & _prefix_()_LEFT)
{ {
*len -= s - str; *len -= s - str;
str = s; str = s;
@ -274,18 +272,17 @@ _char_type_* _fn_name_ (const _char_type_* str, hio_oow_t* len, int flags)
else else
{ {
/* the entire string need to be deleted */ /* the entire string need to be deleted */
if ((flags & $4_RIGHT) || if ((flags & _prefix_()_RIGHT) ||
(flags & $4_LEFT)) *len = 0; (flags & _prefix_()_LEFT)) *len = 0;
} }
} }
return (_char_type_*)str; return (_char_type_*)str;
} }
]]) popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_is_space_]])popdef([[_prefix_]])dnl
]])dnl
dnl --------------------------------------------------------------------------- dnl ---------------------------------------------------------------------------
dnl $3 is_space $4: copy_str_unlimited define([[fn_split_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_is_space_]], $3)pushdef([[_copy_str_unlimited_]], $4)dnl
define([[fn_split_cstr]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2)
int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _char_type_ rquote, _char_type_ escape) int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _char_type_ rquote, _char_type_ escape)
{ {
_char_type_* p = s, *d; _char_type_* p = s, *d;
@ -298,19 +295,19 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch
{ {
delim_mode = 1; delim_mode = 1;
for (d = (_char_type_*)delim; *d != '\0'; d++) for (d = (_char_type_*)delim; *d != '\0'; d++)
if (!$3(*d)) delim_mode = 2; if (!_is_space_()(*d)) delim_mode = 2;
} }
if (delim_mode == 0) if (delim_mode == 0)
{ {
/* skip preceding space characters */ /* skip preceding space characters */
while ($3(*p)) p++; while (_is_space_()(*p)) p++;
/* when 0 is given as "delim", it has an effect of cutting /* when 0 is given as "delim", it has an effect of cutting
preceding and trailing space characters off "s". */ preceding and trailing space characters off "s". */
if (lquote != '\0' && *p == lquote) if (lquote != '\0' && *p == lquote)
{ {
$4 (p, p + 1); _copy_str_unlimited_ (p, p + 1);
for (;;) for (;;)
{ {
@ -318,7 +315,7 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch
if (escape != '\0' && *p == escape) if (escape != '\0' && *p == escape)
{ {
$4 (p, p + 1); _copy_str_unlimited_ (p, p + 1);
} }
else else
{ {
@ -333,14 +330,14 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch
ep = p; ep = p;
p++; p++;
} }
while ($3(*p)) p++; while (_is_space_()(*p)) p++;
if (*p != '\0') return -1; if (*p != '\0') return -1;
if (sp == 0 && ep == 0) s[0] = '\0'; if (sp == 0 && ep == 0) s[0] = '\0';
else else
{ {
ep[1] = '\0'; ep[1] = '\0';
if (s != (_char_type_*)sp) $4 (s, sp); if (s != (_char_type_*)sp) _copy_str_unlimited_ (s, sp);
cnt++; cnt++;
} }
} }
@ -348,7 +345,7 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch
{ {
while (*p) while (*p)
{ {
if (!$3(*p)) if (!_is_space_()(*p))
{ {
if (sp == 0) sp = p; if (sp == 0) sp = p;
ep = p; ep = p;
@ -360,7 +357,7 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch
else else
{ {
ep[1] = '\0'; ep[1] = '\0';
if (s != (_char_type_*)sp) $4 (s, sp); if (s != (_char_type_*)sp) _copy_str_unlimited_ (s, sp);
cnt++; cnt++;
} }
} }
@ -372,12 +369,12 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch
while (*p) while (*p)
{ {
o = p; o = p;
while ($3(*p)) p++; while (_is_space_()(*p)) p++;
if (o != p) { $4 (o, p); p = o; } if (o != p) { _copy_str_unlimited_ (o, p); p = o; }
if (lquote != '\0' && *p == lquote) if (lquote != '\0' && *p == lquote)
{ {
$4 (p, p + 1); _copy_str_unlimited_ (p, p + 1);
for (;;) for (;;)
{ {
@ -385,7 +382,7 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch
if (escape != '\0' && *p == escape) if (escape != '\0' && *p == escape)
{ {
$4 (p, p + 1); _copy_str_unlimited_ (p, p + 1);
} }
else else
{ {
@ -409,7 +406,7 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch
if (o != p) cnt++; if (o != p) cnt++;
break; break;
} }
if ($3(*p)) if (_is_space_()(*p))
{ {
*p++ = '\0'; *p++ = '\0';
cnt++; cnt++;
@ -428,12 +425,12 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch
while (*p != '\0') while (*p != '\0')
{ {
o = p; o = p;
while ($3(*p)) p++; while (_is_space_()(*p)) p++;
if (o != p) { $4 (o, p); p = o; } if (o != p) { _copy_str_unlimited_ (o, p); p = o; }
if (lquote != '\0' && *p == lquote) if (lquote != '\0' && *p == lquote)
{ {
$4 (p, p + 1); _copy_str_unlimited_ (p, p + 1);
for (;;) for (;;)
{ {
@ -441,7 +438,7 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch
if (escape != '\0' && *p == escape) if (escape != '\0' && *p == escape)
{ {
$4 (p, p + 1); _copy_str_unlimited_ (p, p + 1);
} }
else else
{ {
@ -456,14 +453,14 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch
} }
ok = 0; ok = 0;
while ($3(*p)) p++; while (_is_space_()(*p)) p++;
if (*p == '\0') ok = 1; if (*p == '\0') ok = 1;
for (d = (_char_type_*)delim; *d != '\0'; d++) for (d = (_char_type_*)delim; *d != '\0'; d++)
{ {
if (*p == *d) if (*p == *d)
{ {
ok = 1; ok = 1;
$4 (p, p + 1); _copy_str_unlimited_ (p, p + 1);
break; break;
} }
} }
@ -491,13 +488,13 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch
{ {
if (sp == HIO_NULL) if (sp == HIO_NULL)
{ {
$4 (o, p); p = o; _copy_str_unlimited_ (o, p); p = o;
*p++ = '\0'; *p++ = '\0';
} }
else else
{ {
$4 (&ep[1], p); _copy_str_unlimited_ (&ep[1], p);
$4 (o, sp); _copy_str_unlimited_ (o, sp);
o[ep - sp + 1] = '\0'; o[ep - sp + 1] = '\0';
p = &o[ep - sp + 2]; p = &o[ep - sp + 2];
} }
@ -508,7 +505,7 @@ int _fn_name_ (_char_type_* s, const _char_type_* delim, _char_type_ lquote, _ch
} }
} }
if (!$3(*p)) if (!_is_space_()(*p))
{ {
if (sp == HIO_NULL) sp = p; if (sp == HIO_NULL) sp = p;
ep = p; ep = p;
@ -523,10 +520,10 @@ exit_point:
return cnt; return cnt;
} }
]]) popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_is_space_]])popdef([[_copy_str_unlimited_]])dnl
]])dnl
dnl --------------------------------------------------------------------------- dnl ---------------------------------------------------------------------------
define([[fn_chars_to_int]], [[ define([[_fn_name_]], $1) define([[_char_type_]], $2) define([[_int_type_]], $3) define([[fn_chars_to_int]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_int_type_]], $3)pushdef([[_is_space_]], $4)pushdef([[_prefix_]], $5)dnl
_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)
{ {
_int_type_ n = 0; _int_type_ n = 0;
@ -534,15 +531,15 @@ _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _
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 = $5_GET_OPTION_BASE(option); int base = _prefix_()_GET_OPTION_BASE(option);
p = str; p = str;
end = str + len; end = str + len;
if ($5_GET_OPTION_LTRIM(option)) if (_prefix_()_GET_OPTION_LTRIM(option))
{ {
/* strip off leading spaces */ /* strip off leading spaces */
while (p < end && $4(*p)) p++; while (p < end && _is_space_()(*p)) p++;
} }
/* check for a sign */ /* check for a sign */
@ -599,7 +596,7 @@ _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _
p++; p++;
} }
if ($5_GET_OPTION_E(option)) if (_prefix_()_GET_OPTION_E(option))
{ {
if (*p == 'E' || *p == 'e') if (*p == 'E' || *p == 'e')
{ {
@ -632,20 +629,19 @@ _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _
* 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 ($5_GET_OPTION_RTRIM(option)) if (_prefix_()_GET_OPTION_RTRIM(option))
{ {
/* consume trailing spaces */ /* consume trailing spaces */
while (p < end && $4(*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;
} }
]]) popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_int_type_]])popdef([[_is_space_]])popdef([[_prefix_]])dnl
]])dnl
dnl --------------------------------------------------------------------------- dnl ---------------------------------------------------------------------------
dnl $4: is_space $5: prefix for some macros define([[fn_chars_to_uint]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_int_type_]], $3)pushdef([[_is_space_]], $4)pushdef([[_prefix_]], $5)dnl
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)
{ {
_int_type_ n = 0; _int_type_ n = 0;
@ -653,15 +649,15 @@ _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _
const _char_type_* end; const _char_type_* end;
hio_oow_t rem; hio_oow_t rem;
int digit; int digit;
int base = $5_GET_OPTION_BASE(option); int base = _prefix_()_GET_OPTION_BASE(option);
p = str; p = str;
end = str + len; end = str + len;
if ($5_GET_OPTION_LTRIM(option)) if (_prefix_()_GET_OPTION_LTRIM(option))
{ {
/* strip off leading spaces */ /* strip off leading spaces */
while (p < end && $4(*p)) p++; while (p < end && _is_space_()(*p)) p++;
} }
/* check for a sign */ /* check for a sign */
@ -713,7 +709,7 @@ _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _
p++; p++;
} }
if ($5_GET_OPTION_E(option)) if (_prefix_()_GET_OPTION_E(option))
{ {
if (*p == 'E' || *p == 'e') if (*p == 'E' || *p == 'e')
{ {
@ -746,13 +742,14 @@ _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _
* 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 ($5_GET_OPTION_RTRIM(option)) if (_prefix_()_GET_OPTION_RTRIM(option))
{ {
/* consume trailing spaces */ /* consume trailing spaces */
while (p < end && $4(*p)) p++; while (p < end && _is_space_()(*p)) p++;
} }
if (endptr) *endptr = p; if (endptr) *endptr = p;
return n; return n;
} }
popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_int_type_]])popdef([[_is_space_]])popdef([[_prefix_]])dnl
]]) ]])