reorganized basic string functions
This commit is contained in:
parent
73d60963c8
commit
37c50c7d06
@ -41,6 +41,7 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
@ -691,7 +692,7 @@ int z = 0;
|
|||||||
z++;
|
z++;
|
||||||
if ((y % 2) && (z >5))
|
if ((y % 2) && (z >5))
|
||||||
{
|
{
|
||||||
write (iop->wfd, 0, HIO_NULL);
|
write (iop->wfd, HIO_NULL, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,12 @@ CFLAGS_ALL_COMMON =
|
|||||||
LDFLAGS_ALL_COMMON = -L$(abs_builddir) -L$(libdir)
|
LDFLAGS_ALL_COMMON = -L$(abs_builddir) -L$(libdir)
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
hio-utl.h.m4 \
|
hio-str.h.m4 \
|
||||||
utl-str.c.m4 \
|
utl-str.c.m4 \
|
||||||
utl-str.m4
|
utl-str.m4
|
||||||
|
|
||||||
BUILT_SOURCES = \
|
BUILT_SOURCES = \
|
||||||
hio-utl.h \
|
hio-str.h \
|
||||||
utl-str.c
|
utl-str.c
|
||||||
|
|
||||||
##################################################
|
##################################################
|
||||||
@ -58,6 +58,7 @@ include_HEADERS = \
|
|||||||
hio-sck.h \
|
hio-sck.h \
|
||||||
hio-shw.h \
|
hio-shw.h \
|
||||||
hio-skad.h \
|
hio-skad.h \
|
||||||
|
hio-str.h \
|
||||||
hio-thr.h \
|
hio-thr.h \
|
||||||
hio-upac.h \
|
hio-upac.h \
|
||||||
hio-utl.h \
|
hio-utl.h \
|
||||||
@ -144,8 +145,8 @@ install-data-hook:
|
|||||||
uninstall-hook:
|
uninstall-hook:
|
||||||
@rm -f "$(DESTDIR)$(includedir)/hio-cfg.h"
|
@rm -f "$(DESTDIR)$(includedir)/hio-cfg.h"
|
||||||
|
|
||||||
hio-utl.h: utl-str.m4 hio-utl.h.m4
|
hio-str.h: utl-str.m4 hio-str.h.m4
|
||||||
m4 -I$(srcdir) $(srcdir)/hio-utl.h.m4 > $(srcdir)/hio-utl.h
|
m4 -I$(srcdir) $(srcdir)/hio-str.h.m4 > $(srcdir)/hio-str.h
|
||||||
|
|
||||||
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
|
||||||
|
@ -256,8 +256,8 @@ am__include_HEADERS_DIST = hio-chr.h hio-cmn.h hio-dhcp.h hio-dns.h \
|
|||||||
hio-ecs.h hio-fmt.h hio-htb.h hio-htrd.h hio-htre.h hio-http.h \
|
hio-ecs.h hio-fmt.h hio-htb.h hio-htrd.h hio-htre.h hio-http.h \
|
||||||
hio-json.h hio-md5.h hio-nwif.h hio-opt.h hio-pac1.h \
|
hio-json.h hio-md5.h hio-nwif.h hio-opt.h hio-pac1.h \
|
||||||
hio-path.h hio-pipe.h hio-pro.h hio-pty.h hio-rad.h hio-sck.h \
|
hio-path.h hio-pipe.h hio-pro.h hio-pty.h hio-rad.h hio-sck.h \
|
||||||
hio-shw.h hio-skad.h hio-thr.h hio-upac.h hio-utl.h hio.h \
|
hio-shw.h hio-skad.h hio-str.h hio-thr.h hio-upac.h hio-utl.h \
|
||||||
hio-mar.h
|
hio.h hio-mar.h
|
||||||
HEADERS = $(include_HEADERS)
|
HEADERS = $(include_HEADERS)
|
||||||
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) \
|
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) \
|
||||||
hio-cfg.h.in
|
hio-cfg.h.in
|
||||||
@ -430,12 +430,12 @@ CPPFLAGS_ALL_COMMON = \
|
|||||||
CFLAGS_ALL_COMMON =
|
CFLAGS_ALL_COMMON =
|
||||||
LDFLAGS_ALL_COMMON = -L$(abs_builddir) -L$(libdir)
|
LDFLAGS_ALL_COMMON = -L$(abs_builddir) -L$(libdir)
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
hio-utl.h.m4 \
|
hio-str.h.m4 \
|
||||||
utl-str.c.m4 \
|
utl-str.c.m4 \
|
||||||
utl-str.m4
|
utl-str.m4
|
||||||
|
|
||||||
BUILT_SOURCES = \
|
BUILT_SOURCES = \
|
||||||
hio-utl.h \
|
hio-str.h \
|
||||||
utl-str.c
|
utl-str.c
|
||||||
|
|
||||||
|
|
||||||
@ -459,8 +459,8 @@ include_HEADERS = hio-chr.h hio-cmn.h hio-dhcp.h hio-dns.h hio-ecs.h \
|
|||||||
hio-fmt.h hio-htb.h hio-htrd.h hio-htre.h hio-http.h \
|
hio-fmt.h hio-htb.h hio-htrd.h hio-htre.h hio-http.h \
|
||||||
hio-json.h hio-md5.h hio-nwif.h hio-opt.h hio-pac1.h \
|
hio-json.h hio-md5.h hio-nwif.h hio-opt.h hio-pac1.h \
|
||||||
hio-path.h hio-pipe.h hio-pro.h hio-pty.h hio-rad.h hio-sck.h \
|
hio-path.h hio-pipe.h hio-pro.h hio-pty.h hio-rad.h hio-sck.h \
|
||||||
hio-shw.h hio-skad.h hio-thr.h hio-upac.h hio-utl.h hio.h \
|
hio-shw.h hio-skad.h hio-str.h hio-thr.h hio-upac.h hio-utl.h \
|
||||||
$(am__append_1)
|
hio.h $(am__append_1)
|
||||||
lib_LTLIBRARIES = libhio.la
|
lib_LTLIBRARIES = libhio.la
|
||||||
libhio_la_SOURCES = chr.c dhcp-svr.c dns.c dns-cli.c ecs.c ecs-imp.h \
|
libhio_la_SOURCES = chr.c dhcp-svr.c dns.c dns-cli.c ecs.c ecs-imp.h \
|
||||||
err.c fmt.c fmt-imp.h htb.c htrd.c htre.c http.c http-cgi.c \
|
err.c fmt.c fmt-imp.h htb.c htrd.c htre.c http.c http-cgi.c \
|
||||||
@ -1286,8 +1286,8 @@ install-data-hook:
|
|||||||
uninstall-hook:
|
uninstall-hook:
|
||||||
@rm -f "$(DESTDIR)$(includedir)/hio-cfg.h"
|
@rm -f "$(DESTDIR)$(includedir)/hio-cfg.h"
|
||||||
|
|
||||||
hio-utl.h: utl-str.m4 hio-utl.h.m4
|
hio-str.h: utl-str.m4 hio-str.h.m4
|
||||||
m4 -I$(srcdir) $(srcdir)/hio-utl.h.m4 > $(srcdir)/hio-utl.h
|
m4 -I$(srcdir) $(srcdir)/hio-str.h.m4 > $(srcdir)/hio-str.h
|
||||||
|
|
||||||
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
|
||||||
|
709
hio/lib/hio-str.h.m4
Normal file
709
hio/lib/hio-str.h.m4
Normal file
@ -0,0 +1,709 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Do NOT edit hio-str.h. Edit hio-str.h.m4 instead.
|
||||||
|
*
|
||||||
|
* Generate hio-str.h.m4 with m4
|
||||||
|
* $ m4 hio-str.h.m4 > hio-str.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _HIO_STR_H_
|
||||||
|
#define _HIO_STR_H_
|
||||||
|
|
||||||
|
#include <hio-cmn.h>
|
||||||
|
|
||||||
|
dnl ---------------------------------------------------------------------------
|
||||||
|
dnl include utl-str.m4 for c++ template functions far below
|
||||||
|
include(`utl-str.m4')
|
||||||
|
dnl ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/* =========================================================================
|
||||||
|
* STRING
|
||||||
|
* ========================================================================= */
|
||||||
|
|
||||||
|
enum hio_trim_oochars_flag_t
|
||||||
|
{
|
||||||
|
HIO_TRIM_OOCHARS_LEFT = (1 << 0), /**< trim leading spaces */
|
||||||
|
#define HIO_TRIM_OOCHARS_LEFT HIO_TRIM_OOCHARS_LEFT
|
||||||
|
#define HIO_TRIM_UCHARS_LEFT HIO_TRIM_OOCHARS_LEFT
|
||||||
|
#define HIO_TRIM_BCHARS_LEFT HIO_TRIM_OOCHARS_LEFT
|
||||||
|
HIO_TRIM_OOCHARS_RIGHT = (1 << 1) /**< trim trailing spaces */
|
||||||
|
#define HIO_TRIM_OOCHARS_RIGHT HIO_TRIM_OOCHARS_RIGHT
|
||||||
|
#define HIO_TRIM_UCHARS_RIGHT HIO_TRIM_OOCHARS_RIGHT
|
||||||
|
#define HIO_TRIM_BCHARS_RIGHT HIO_TRIM_OOCHARS_RIGHT
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------ */
|
||||||
|
|
||||||
|
HIO_EXPORT 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_EXPORT 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_EXPORT int hio_comp_ucstr (
|
||||||
|
const hio_uch_t* str1,
|
||||||
|
const hio_uch_t* str2,
|
||||||
|
int ignorecase
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT int hio_comp_bcstr (
|
||||||
|
const hio_bch_t* str1,
|
||||||
|
const hio_bch_t* str2,
|
||||||
|
int ignorecase
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT int hio_comp_ucstr_limited (
|
||||||
|
const hio_uch_t* str1,
|
||||||
|
const hio_uch_t* str2,
|
||||||
|
hio_oow_t maxlen,
|
||||||
|
int ignorecase
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT int hio_comp_bcstr_limited (
|
||||||
|
const hio_bch_t* str1,
|
||||||
|
const hio_bch_t* str2,
|
||||||
|
hio_oow_t maxlen,
|
||||||
|
int ignorecase
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT int hio_comp_uchars_ucstr (
|
||||||
|
const hio_uch_t* str1,
|
||||||
|
hio_oow_t len,
|
||||||
|
const hio_uch_t* str2,
|
||||||
|
int ignorecase
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT int hio_comp_bchars_bcstr (
|
||||||
|
const hio_bch_t* str1,
|
||||||
|
hio_oow_t len,
|
||||||
|
const hio_bch_t* str2,
|
||||||
|
int ignorecase
|
||||||
|
);
|
||||||
|
|
||||||
|
/* ------------------------------------ */
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_concat_uchars_to_ucstr (
|
||||||
|
hio_uch_t* buf,
|
||||||
|
hio_oow_t bsz,
|
||||||
|
const hio_uch_t* src,
|
||||||
|
hio_oow_t len
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_concat_bchars_to_bcstr (
|
||||||
|
hio_bch_t* buf,
|
||||||
|
hio_oow_t bsz,
|
||||||
|
const hio_bch_t* src,
|
||||||
|
hio_oow_t len
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_concat_ucstr (
|
||||||
|
hio_uch_t* buf,
|
||||||
|
hio_oow_t bsz,
|
||||||
|
const hio_uch_t* src
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_concat_bcstr (
|
||||||
|
hio_bch_t* buf,
|
||||||
|
hio_oow_t bsz,
|
||||||
|
const hio_bch_t* src
|
||||||
|
);
|
||||||
|
|
||||||
|
/* ------------------------------------ */
|
||||||
|
|
||||||
|
HIO_EXPORT void hio_copy_uchars (
|
||||||
|
hio_uch_t* dst,
|
||||||
|
const hio_uch_t* src,
|
||||||
|
hio_oow_t len
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT void hio_copy_bchars (
|
||||||
|
hio_bch_t* dst,
|
||||||
|
const hio_bch_t* src,
|
||||||
|
hio_oow_t len
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT void hio_copy_bchars_to_uchars (
|
||||||
|
hio_uch_t* dst,
|
||||||
|
const hio_bch_t* src,
|
||||||
|
hio_oow_t len
|
||||||
|
);
|
||||||
|
HIO_EXPORT void hio_copy_uchars_to_bchars (
|
||||||
|
hio_bch_t* dst,
|
||||||
|
const hio_uch_t* src,
|
||||||
|
hio_oow_t len
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_copy_uchars_to_ucstr (
|
||||||
|
hio_uch_t* dst,
|
||||||
|
hio_oow_t dlen,
|
||||||
|
const hio_uch_t* src,
|
||||||
|
hio_oow_t slen
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_copy_bchars_to_bcstr (
|
||||||
|
hio_bch_t* dst,
|
||||||
|
hio_oow_t dlen,
|
||||||
|
const hio_bch_t* src,
|
||||||
|
hio_oow_t slen
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_copy_uchars_to_ucstr_unlimited (
|
||||||
|
hio_uch_t* dst,
|
||||||
|
const hio_uch_t* src,
|
||||||
|
hio_oow_t len
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_copy_bchars_to_bcstr_unlimited (
|
||||||
|
hio_bch_t* dst,
|
||||||
|
const hio_bch_t* src,
|
||||||
|
hio_oow_t len
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_copy_ucstr_to_uchars (
|
||||||
|
hio_uch_t* dst,
|
||||||
|
hio_oow_t dlen,
|
||||||
|
const hio_uch_t* src
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_copy_bcstr_to_bchars (
|
||||||
|
hio_bch_t* dst,
|
||||||
|
hio_oow_t dlen,
|
||||||
|
const hio_bch_t* src
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_copy_ucstr (
|
||||||
|
hio_uch_t* dst,
|
||||||
|
hio_oow_t len,
|
||||||
|
const hio_uch_t* src
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_copy_bcstr (
|
||||||
|
hio_bch_t* dst,
|
||||||
|
hio_oow_t len,
|
||||||
|
const hio_bch_t* src
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_copy_ucstr_unlimited (
|
||||||
|
hio_uch_t* dst,
|
||||||
|
const hio_uch_t* src
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_copy_bcstr_unlimited (
|
||||||
|
hio_bch_t* dst,
|
||||||
|
const hio_bch_t* src
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_copy_fmt_ucstrs_to_ucstr (
|
||||||
|
hio_uch_t* buf,
|
||||||
|
hio_oow_t bsz,
|
||||||
|
const hio_uch_t* fmt,
|
||||||
|
const hio_uch_t* str[]
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_copy_fmt_bcstrs_to_bcstr (
|
||||||
|
hio_bch_t* buf,
|
||||||
|
hio_oow_t bsz,
|
||||||
|
const hio_bch_t* fmt,
|
||||||
|
const hio_bch_t* str[]
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_copy_fmt_ucses_to_ucstr (
|
||||||
|
hio_uch_t* buf,
|
||||||
|
hio_oow_t bsz,
|
||||||
|
const hio_uch_t* fmt,
|
||||||
|
const hio_ucs_t str[]
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_copy_fmt_bcses_to_bcstr (
|
||||||
|
hio_bch_t* buf,
|
||||||
|
hio_oow_t bsz,
|
||||||
|
const hio_bch_t* fmt,
|
||||||
|
const hio_bcs_t str[]
|
||||||
|
);
|
||||||
|
|
||||||
|
/* ------------------------------------ */
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_count_ucstr (
|
||||||
|
const hio_uch_t* str
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_count_bcstr (
|
||||||
|
const hio_bch_t* str
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_count_ucstr_limited (
|
||||||
|
const hio_uch_t* str,
|
||||||
|
hio_oow_t maxlen
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_count_bcstr_limited (
|
||||||
|
const hio_bch_t* str,
|
||||||
|
hio_oow_t maxlen
|
||||||
|
);
|
||||||
|
|
||||||
|
/* ------------------------------------ */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The hio_equal_uchars() function determines equality of two strings
|
||||||
|
* of the same length \a len.
|
||||||
|
*/
|
||||||
|
HIO_EXPORT int hio_equal_uchars (
|
||||||
|
const hio_uch_t* str1,
|
||||||
|
const hio_uch_t* str2,
|
||||||
|
hio_oow_t len
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT int hio_equal_bchars (
|
||||||
|
const hio_bch_t* str1,
|
||||||
|
const hio_bch_t* str2,
|
||||||
|
hio_oow_t len
|
||||||
|
);
|
||||||
|
|
||||||
|
/* ------------------------------------ */
|
||||||
|
|
||||||
|
|
||||||
|
HIO_EXPORT void hio_fill_uchars (
|
||||||
|
hio_uch_t* dst,
|
||||||
|
const hio_uch_t ch,
|
||||||
|
hio_oow_t len
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT void hio_fill_bchars (
|
||||||
|
hio_bch_t* dst,
|
||||||
|
const hio_bch_t ch,
|
||||||
|
hio_oow_t len
|
||||||
|
);
|
||||||
|
|
||||||
|
/* ------------------------------------ */
|
||||||
|
|
||||||
|
HIO_EXPORT const hio_bch_t* hio_find_bcstr_word_in_bcstr (
|
||||||
|
const hio_bch_t* str,
|
||||||
|
const hio_bch_t* word,
|
||||||
|
hio_bch_t extra_delim,
|
||||||
|
int ignorecase
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT const hio_uch_t* hio_find_ucstr_word_in_ucstr (
|
||||||
|
const hio_uch_t* str,
|
||||||
|
const hio_uch_t* word,
|
||||||
|
hio_uch_t extra_delim,
|
||||||
|
int ignorecase
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_uch_t* hio_find_uchar_in_uchars (
|
||||||
|
const hio_uch_t* ptr,
|
||||||
|
hio_oow_t len,
|
||||||
|
hio_uch_t c
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_bch_t* hio_find_bchar_in_bchars (
|
||||||
|
const hio_bch_t* ptr,
|
||||||
|
hio_oow_t len,
|
||||||
|
hio_bch_t c
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_uch_t* hio_rfind_uchar_in_uchars (
|
||||||
|
const hio_uch_t* ptr,
|
||||||
|
hio_oow_t len,
|
||||||
|
hio_uch_t c
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_bch_t* hio_rfind_bchar_in_bchars (
|
||||||
|
const hio_bch_t* ptr,
|
||||||
|
hio_oow_t len,
|
||||||
|
hio_bch_t c
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_uch_t* hio_find_uchar_in_ucstr (
|
||||||
|
const hio_uch_t* ptr,
|
||||||
|
hio_uch_t c
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_bch_t* hio_find_bchar_in_bcstr (
|
||||||
|
const hio_bch_t* ptr,
|
||||||
|
hio_bch_t c
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_uch_t* hio_rfind_uchar_in_ucstr (
|
||||||
|
const hio_uch_t* ptr,
|
||||||
|
hio_uch_t c
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_bch_t* hio_rfind_bchar_in_bcstr (
|
||||||
|
const hio_bch_t* ptr,
|
||||||
|
hio_bch_t c
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_uch_t* hio_find_uchars_in_uchars (
|
||||||
|
const hio_uch_t* str,
|
||||||
|
hio_oow_t strsz,
|
||||||
|
const hio_uch_t* sub,
|
||||||
|
hio_oow_t subsz,
|
||||||
|
int inorecase
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_bch_t* hio_find_bchars_in_bchars (
|
||||||
|
const hio_bch_t* str,
|
||||||
|
hio_oow_t strsz,
|
||||||
|
const hio_bch_t* sub,
|
||||||
|
hio_oow_t subsz,
|
||||||
|
int inorecase
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_uch_t* hio_rfind_uchars_in_uchars (
|
||||||
|
const hio_uch_t* str,
|
||||||
|
hio_oow_t strsz,
|
||||||
|
const hio_uch_t* sub,
|
||||||
|
hio_oow_t subsz,
|
||||||
|
int inorecase
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_bch_t* hio_rfind_bchars_in_bchars (
|
||||||
|
const hio_bch_t* str,
|
||||||
|
hio_oow_t strsz,
|
||||||
|
const hio_bch_t* sub,
|
||||||
|
hio_oow_t subsz,
|
||||||
|
int inorecase
|
||||||
|
);
|
||||||
|
|
||||||
|
/* ------------------------------------ */
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_rotate_uchars (
|
||||||
|
hio_uch_t* str,
|
||||||
|
hio_oow_t len,
|
||||||
|
int dir,
|
||||||
|
hio_oow_t n
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_rotate_bchars (
|
||||||
|
hio_bch_t* str,
|
||||||
|
hio_oow_t len,
|
||||||
|
int dir,
|
||||||
|
hio_oow_t n
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
HIO_EXPORT hio_uch_t* hio_trim_uchars (
|
||||||
|
const hio_uch_t* str,
|
||||||
|
hio_oow_t* len,
|
||||||
|
int flags
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_bch_t* hio_trim_bchars (
|
||||||
|
const hio_bch_t* str,
|
||||||
|
hio_oow_t* len,
|
||||||
|
int flags
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT 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_EXPORT 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
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(HIO_OOCH_IS_UCH)
|
||||||
|
# define hio_count_oocstr hio_count_ucstr
|
||||||
|
# define hio_count_oocstr_limited hio_count_ucstr_limited
|
||||||
|
|
||||||
|
# define hio_equal_oochars hio_equal_uchars
|
||||||
|
# define hio_comp_oochars hio_comp_uchars
|
||||||
|
# define hio_comp_oocstr_bcstr hio_comp_ucstr_bcstr
|
||||||
|
# define hio_comp_oochars_bcstr hio_comp_uchars_bcstr
|
||||||
|
# define hio_comp_oochars_ucstr hio_comp_uchars_ucstr
|
||||||
|
# define hio_comp_oochars_oocstr hio_comp_uchars_ucstr
|
||||||
|
# define hio_comp_oocstr hio_comp_ucstr
|
||||||
|
|
||||||
|
# define hio_copy_oochars hio_copy_uchars
|
||||||
|
# define hio_copy_bchars_to_oochars hio_copy_bchars_to_uchars
|
||||||
|
# define hio_copy_oochars_to_bchars hio_copy_uchars_to_bchars
|
||||||
|
# define hio_copy_uchars_to_oochars hio_copy_uchars
|
||||||
|
# define hio_copy_oochars_to_uchars hio_copy_uchars
|
||||||
|
|
||||||
|
# define hio_copy_oochars_to_oocstr hio_copy_uchars_to_ucstr
|
||||||
|
# define hio_copy_oochars_to_oocstr_unlimited hio_copy_uchars_to_ucstr_unlimited
|
||||||
|
# define hio_copy_oocstr hio_copy_ucstr
|
||||||
|
# define hio_copy_oocstr_unlimited hio_copy_ucstr_unlimited
|
||||||
|
# define hio_copy_fmt_oocses_to_oocstr hio_copy_fmt_ucses_to_ucstr
|
||||||
|
# define hio_copy_fmt_oocstr_to_oocstr hio_copy_fmt_ucstr_to_ucstr
|
||||||
|
|
||||||
|
# define hio_concat_oochars_to_ucstr hio_concat_uchars_to_ucstr
|
||||||
|
# define hio_concat_oocstr hio_concat_ucstr
|
||||||
|
|
||||||
|
# define hio_fill_oochars hio_fill_uchars
|
||||||
|
# define hio_find_oocstr_word_in_oocstr hio_find_ucstr_word_in_ucstr
|
||||||
|
# define hio_find_oochar_in_oochars hio_find_uchar_in_uchars
|
||||||
|
# define hio_rfind_oochar_in_oochars hio_rfind_uchar_in_uchars
|
||||||
|
# define hio_find_oochar_in_oocstr hio_find_uchar_in_ucstr
|
||||||
|
|
||||||
|
# define hio_trim_oochars hio_trim_uchars
|
||||||
|
# define hio_split_oocstr hio_split_ucstr
|
||||||
|
#else
|
||||||
|
# define hio_count_oocstr hio_count_bcstr
|
||||||
|
# define hio_count_oocstr_limited hio_count_bcstr_limited
|
||||||
|
|
||||||
|
# define hio_equal_oochars hio_equal_bchars
|
||||||
|
# define hio_comp_oochars hio_comp_bchars
|
||||||
|
# define hio_comp_oocstr_bcstr hio_comp_bcstr
|
||||||
|
# define hio_comp_oochars_bcstr hio_comp_bchars_bcstr
|
||||||
|
# define hio_comp_oochars_ucstr hio_comp_bchars_ucstr
|
||||||
|
# define hio_comp_oochars_oocstr hio_comp_bchars_bcstr
|
||||||
|
# define hio_comp_oocstr hio_comp_bcstr
|
||||||
|
|
||||||
|
# define hio_copy_oochars hio_copy_bchars
|
||||||
|
# define hio_copy_bchars_to_oochars hio_copy_bchars
|
||||||
|
# define hio_copy_oochars_to_bchars hio_copy_bchars
|
||||||
|
# define hio_copy_uchars_to_oochars hio_copy_uchars_to_bchars
|
||||||
|
# define hio_copy_oochars_to_uchars hio_copy_bchars_to_uchars
|
||||||
|
|
||||||
|
# define hio_copy_oochars_to_oocstr hio_copy_bchars_to_bcstr
|
||||||
|
# define hio_copy_oochars_to_oocstr_unlimited hio_copy_bchars_to_bcstr_unlimited
|
||||||
|
# define hio_copy_oocstr hio_copy_bcstr
|
||||||
|
# define hio_copy_oocstr_unlimited hio_copy_bcstr_unlimited
|
||||||
|
# define hio_copy_fmt_oocses_to_oocstr hio_copy_fmt_bcses_to_bcstr
|
||||||
|
# define hio_copy_fmt_oocstr_to_oocstr hio_copy_fmt_bcstr_to_bcstr
|
||||||
|
|
||||||
|
# define hio_concat_oochars_to_bcstr hio_concat_bchars_to_bcstr
|
||||||
|
# define hio_concat_oocstr hio_concat_bcstr
|
||||||
|
|
||||||
|
# define hio_fill_oochars hio_fill_bchars
|
||||||
|
# define hio_find_oocstr_word_in_oocstr hio_find_bcstr_word_in_bcstr
|
||||||
|
# define hio_find_oochar_in_oochars hio_find_bchar_in_bchars
|
||||||
|
# define hio_rfind_oochar_in_oochars hio_rfind_bchar_in_bchars
|
||||||
|
# define hio_find_oochar_in_oocstr hio_find_bchar_in_bcstr
|
||||||
|
|
||||||
|
# define hio_trim_oochars hio_trim_bchars
|
||||||
|
# define hio_split_oocstr hio_split_bcstr
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#define HIO_BYTE_TO_BCSTR_RADIXMASK (0xFF)
|
||||||
|
#define HIO_BYTE_TO_BCSTR_LOWERCASE (1 << 8)
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_byte_to_bcstr (
|
||||||
|
hio_uint8_t byte,
|
||||||
|
hio_bch_t* buf,
|
||||||
|
hio_oow_t size,
|
||||||
|
int flagged_radix,
|
||||||
|
hio_bch_t fill
|
||||||
|
);
|
||||||
|
|
||||||
|
#define HIO_BYTE_TO_UCSTR_RADIXMASK (0xFF)
|
||||||
|
#define HIO_BYTE_TO_UCSTR_LOWERCASE (1 << 8)
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_byte_to_ucstr (
|
||||||
|
hio_uint8_t byte,
|
||||||
|
hio_uch_t* buf,
|
||||||
|
hio_oow_t size,
|
||||||
|
int flagged_radix,
|
||||||
|
hio_uch_t fill
|
||||||
|
);
|
||||||
|
|
||||||
|
#if defined(HIO_OOCH_IS_UCH)
|
||||||
|
# define hio_byte_to_oocstr hio_byte_to_ucstr
|
||||||
|
#else
|
||||||
|
# define hio_byte_to_oocstr hio_byte_to_bcstr
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_intmax_to_ucstr (
|
||||||
|
hio_intmax_t value,
|
||||||
|
int radix,
|
||||||
|
const hio_uch_t* prefix,
|
||||||
|
hio_uch_t* buf,
|
||||||
|
hio_oow_t size
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_intmax_to_bcstr (
|
||||||
|
hio_intmax_t value,
|
||||||
|
int radix,
|
||||||
|
const hio_bch_t* prefix,
|
||||||
|
hio_bch_t* buf,
|
||||||
|
hio_oow_t size
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_uintmax_to_ucstr (
|
||||||
|
hio_uintmax_t value,
|
||||||
|
int radix,
|
||||||
|
const hio_uch_t* prefix,
|
||||||
|
hio_uch_t* buf,
|
||||||
|
hio_oow_t size
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT hio_oow_t hio_uintmax_to_bcstr (
|
||||||
|
hio_uintmax_t value,
|
||||||
|
int radix,
|
||||||
|
const hio_bch_t* prefix,
|
||||||
|
hio_bch_t* buf,
|
||||||
|
hio_oow_t size
|
||||||
|
);
|
||||||
|
|
||||||
|
#if defined(HIO_OOCH_IS_UCH)
|
||||||
|
# define hio_intmax_to_oocstr hio_intmax_to_ucstr
|
||||||
|
# define hio_uintmax_to_oocstr hio_uintmax_to_ucstr
|
||||||
|
#else
|
||||||
|
# define hio_intmax_to_oocstr hio_intmax_to_bcstr
|
||||||
|
# define hio_uintmax_to_oocstr hio_uintmax_to_bcstr
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#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_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_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_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_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_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_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_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,
|
||||||
|
hio_oow_t len,
|
||||||
|
int option,
|
||||||
|
const hio_uch_t** endptr,
|
||||||
|
int* is_sober
|
||||||
|
);
|
||||||
|
|
||||||
|
HIO_EXPORT 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_EXPORT 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_EXPORT 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
|
||||||
|
);
|
||||||
|
#if defined(HIO_OOCH_IS_UCH)
|
||||||
|
# define hio_oochars_to_intmax hio_uchars_to_intmax
|
||||||
|
# define hio_oochars_to_uintmax hio_uchars_to_uintmax
|
||||||
|
#else
|
||||||
|
# define hio_oochars_to_intmax hio_bchars_to_intmax
|
||||||
|
# define hio_oochars_to_uintmax hio_bchars_to_uintmax
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Some C++ utilities below */
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
|
||||||
|
/*
|
||||||
|
static inline bool is_space (char c) { return isspace(c); }
|
||||||
|
static inline bool 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, bool(*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, bool(*IS_SPACE)(CHAR_TYPE)>fn_chars_to_uint(hio_chars_to_uint, CHAR_TYPE, UINT_TYPE, IS_SPACE, HIO_CHARS_TO_UINT)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -22,23 +22,13 @@
|
|||||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* Do NOT edit hio-utl.h. Edit hio-utl.h.m4 instead.
|
|
||||||
*
|
|
||||||
* Generate hio-utl.h.m4 with m4
|
|
||||||
* $ m4 hio-utl.h.m4 > hio-utl.h
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _HIO_UTL_H_
|
#ifndef _HIO_UTL_H_
|
||||||
#define _HIO_UTL_H_
|
#define _HIO_UTL_H_
|
||||||
|
|
||||||
#include <hio-cmn.h>
|
#include <hio-cmn.h>
|
||||||
|
#include <hio-str.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* =========================================================================
|
/* =========================================================================
|
||||||
* ENDIAN CHANGE OF A CONSTANT
|
* ENDIAN CHANGE OF A CONSTANT
|
||||||
* ========================================================================= */
|
* ========================================================================= */
|
||||||
@ -238,79 +228,12 @@
|
|||||||
* STRING
|
* STRING
|
||||||
* ========================================================================= */
|
* ========================================================================= */
|
||||||
|
|
||||||
enum hio_trim_oochars_flag_t
|
|
||||||
{
|
|
||||||
HIO_TRIM_OOCHARS_LEFT = (1 << 0), /**< trim leading spaces */
|
|
||||||
#define HIO_TRIM_OOCHARS_LEFT HIO_TRIM_OOCHARS_LEFT
|
|
||||||
#define HIO_TRIM_UCHARS_LEFT HIO_TRIM_OOCHARS_LEFT
|
|
||||||
#define HIO_TRIM_BCHARS_LEFT HIO_TRIM_OOCHARS_LEFT
|
|
||||||
HIO_TRIM_OOCHARS_RIGHT = (1 << 1) /**< trim trailing spaces */
|
|
||||||
#define HIO_TRIM_OOCHARS_RIGHT HIO_TRIM_OOCHARS_RIGHT
|
|
||||||
#define HIO_TRIM_UCHARS_RIGHT HIO_TRIM_OOCHARS_RIGHT
|
|
||||||
#define HIO_TRIM_BCHARS_RIGHT HIO_TRIM_OOCHARS_RIGHT
|
|
||||||
};
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------ */
|
|
||||||
|
|
||||||
HIO_EXPORT 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_EXPORT 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_EXPORT int hio_comp_ucstr (
|
|
||||||
const hio_uch_t* str1,
|
|
||||||
const hio_uch_t* str2,
|
|
||||||
int ignorecase
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT int hio_comp_bcstr (
|
|
||||||
const hio_bch_t* str1,
|
|
||||||
const hio_bch_t* str2,
|
|
||||||
int ignorecase
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT int hio_comp_ucstr_limited (
|
|
||||||
const hio_uch_t* str1,
|
|
||||||
const hio_uch_t* str2,
|
|
||||||
hio_oow_t maxlen,
|
|
||||||
int ignorecase
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT int hio_comp_bcstr_limited (
|
|
||||||
const hio_bch_t* str1,
|
|
||||||
const hio_bch_t* str2,
|
|
||||||
hio_oow_t maxlen,
|
|
||||||
int ignorecase
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT int hio_comp_ucstr_bcstr (
|
HIO_EXPORT int hio_comp_ucstr_bcstr (
|
||||||
const hio_uch_t* str1,
|
const hio_uch_t* str1,
|
||||||
const hio_bch_t* str2,
|
const hio_bch_t* str2,
|
||||||
int ignorecase
|
int ignorecase
|
||||||
);
|
);
|
||||||
|
|
||||||
HIO_EXPORT int hio_comp_uchars_ucstr (
|
|
||||||
const hio_uch_t* str1,
|
|
||||||
hio_oow_t len,
|
|
||||||
const hio_uch_t* str2,
|
|
||||||
int ignorecase
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT int hio_comp_uchars_bcstr (
|
HIO_EXPORT int hio_comp_uchars_bcstr (
|
||||||
const hio_uch_t* str1,
|
const hio_uch_t* str1,
|
||||||
@ -319,13 +242,6 @@ HIO_EXPORT int hio_comp_uchars_bcstr (
|
|||||||
int ignorecase
|
int ignorecase
|
||||||
);
|
);
|
||||||
|
|
||||||
HIO_EXPORT int hio_comp_bchars_bcstr (
|
|
||||||
const hio_bch_t* str1,
|
|
||||||
hio_oow_t len,
|
|
||||||
const hio_bch_t* str2,
|
|
||||||
int ignorecase
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT int hio_comp_bchars_ucstr (
|
HIO_EXPORT int hio_comp_bchars_ucstr (
|
||||||
const hio_bch_t* str1,
|
const hio_bch_t* str1,
|
||||||
hio_oow_t len,
|
hio_oow_t len,
|
||||||
@ -333,534 +249,8 @@ HIO_EXPORT int hio_comp_bchars_ucstr (
|
|||||||
int ignorecase
|
int ignorecase
|
||||||
);
|
);
|
||||||
|
|
||||||
/* ------------------------------------ */
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_concat_uchars_to_ucstr (
|
|
||||||
hio_uch_t* buf,
|
|
||||||
hio_oow_t bsz,
|
|
||||||
const hio_uch_t* src,
|
|
||||||
hio_oow_t len
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_concat_bchars_to_bcstr (
|
|
||||||
hio_bch_t* buf,
|
|
||||||
hio_oow_t bsz,
|
|
||||||
const hio_bch_t* src,
|
|
||||||
hio_oow_t len
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_concat_ucstr (
|
|
||||||
hio_uch_t* buf,
|
|
||||||
hio_oow_t bsz,
|
|
||||||
const hio_uch_t* src
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_concat_bcstr (
|
|
||||||
hio_bch_t* buf,
|
|
||||||
hio_oow_t bsz,
|
|
||||||
const hio_bch_t* src
|
|
||||||
);
|
|
||||||
|
|
||||||
/* ------------------------------------ */
|
|
||||||
|
|
||||||
HIO_EXPORT void hio_copy_uchars (
|
|
||||||
hio_uch_t* dst,
|
|
||||||
const hio_uch_t* src,
|
|
||||||
hio_oow_t len
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT void hio_copy_bchars (
|
|
||||||
hio_bch_t* dst,
|
|
||||||
const hio_bch_t* src,
|
|
||||||
hio_oow_t len
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT void hio_copy_bchars_to_uchars (
|
|
||||||
hio_uch_t* dst,
|
|
||||||
const hio_bch_t* src,
|
|
||||||
hio_oow_t len
|
|
||||||
);
|
|
||||||
HIO_EXPORT void hio_copy_uchars_to_bchars (
|
|
||||||
hio_bch_t* dst,
|
|
||||||
const hio_uch_t* src,
|
|
||||||
hio_oow_t len
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_copy_uchars_to_ucstr (
|
|
||||||
hio_uch_t* dst,
|
|
||||||
hio_oow_t dlen,
|
|
||||||
const hio_uch_t* src,
|
|
||||||
hio_oow_t slen
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_copy_bchars_to_bcstr (
|
|
||||||
hio_bch_t* dst,
|
|
||||||
hio_oow_t dlen,
|
|
||||||
const hio_bch_t* src,
|
|
||||||
hio_oow_t slen
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_copy_uchars_to_ucstr_unlimited (
|
|
||||||
hio_uch_t* dst,
|
|
||||||
const hio_uch_t* src,
|
|
||||||
hio_oow_t len
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_copy_bchars_to_bcstr_unlimited (
|
|
||||||
hio_bch_t* dst,
|
|
||||||
const hio_bch_t* src,
|
|
||||||
hio_oow_t len
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_copy_ucstr_to_uchars (
|
|
||||||
hio_uch_t* dst,
|
|
||||||
hio_oow_t dlen,
|
|
||||||
const hio_uch_t* src
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_copy_bcstr_to_bchars (
|
|
||||||
hio_bch_t* dst,
|
|
||||||
hio_oow_t dlen,
|
|
||||||
const hio_bch_t* src
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_copy_ucstr (
|
|
||||||
hio_uch_t* dst,
|
|
||||||
hio_oow_t len,
|
|
||||||
const hio_uch_t* src
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_copy_bcstr (
|
|
||||||
hio_bch_t* dst,
|
|
||||||
hio_oow_t len,
|
|
||||||
const hio_bch_t* src
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_copy_ucstr_unlimited (
|
|
||||||
hio_uch_t* dst,
|
|
||||||
const hio_uch_t* src
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_copy_bcstr_unlimited (
|
|
||||||
hio_bch_t* dst,
|
|
||||||
const hio_bch_t* src
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_copy_fmt_ucstrs_to_ucstr (
|
|
||||||
hio_uch_t* buf,
|
|
||||||
hio_oow_t bsz,
|
|
||||||
const hio_uch_t* fmt,
|
|
||||||
const hio_uch_t* str[]
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_copy_fmt_bcstrs_to_bcstr (
|
|
||||||
hio_bch_t* buf,
|
|
||||||
hio_oow_t bsz,
|
|
||||||
const hio_bch_t* fmt,
|
|
||||||
const hio_bch_t* str[]
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_copy_fmt_ucses_to_ucstr (
|
|
||||||
hio_uch_t* buf,
|
|
||||||
hio_oow_t bsz,
|
|
||||||
const hio_uch_t* fmt,
|
|
||||||
const hio_ucs_t str[]
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_copy_fmt_bcses_to_bcstr (
|
|
||||||
hio_bch_t* buf,
|
|
||||||
hio_oow_t bsz,
|
|
||||||
const hio_bch_t* fmt,
|
|
||||||
const hio_bcs_t str[]
|
|
||||||
);
|
|
||||||
|
|
||||||
/* ------------------------------------ */
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_count_ucstr (
|
|
||||||
const hio_uch_t* str
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_count_bcstr (
|
|
||||||
const hio_bch_t* str
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_count_ucstr_limited (
|
|
||||||
const hio_uch_t* str,
|
|
||||||
hio_oow_t maxlen
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_count_bcstr_limited (
|
|
||||||
const hio_bch_t* str,
|
|
||||||
hio_oow_t maxlen
|
|
||||||
);
|
|
||||||
|
|
||||||
/* ------------------------------------ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The hio_equal_uchars() function determines equality of two strings
|
|
||||||
* of the same length \a len.
|
|
||||||
*/
|
|
||||||
HIO_EXPORT int hio_equal_uchars (
|
|
||||||
const hio_uch_t* str1,
|
|
||||||
const hio_uch_t* str2,
|
|
||||||
hio_oow_t len
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT int hio_equal_bchars (
|
|
||||||
const hio_bch_t* str1,
|
|
||||||
const hio_bch_t* str2,
|
|
||||||
hio_oow_t len
|
|
||||||
);
|
|
||||||
|
|
||||||
/* ------------------------------------ */
|
|
||||||
|
|
||||||
|
|
||||||
HIO_EXPORT void hio_fill_uchars (
|
|
||||||
hio_uch_t* dst,
|
|
||||||
const hio_uch_t ch,
|
|
||||||
hio_oow_t len
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT void hio_fill_bchars (
|
|
||||||
hio_bch_t* dst,
|
|
||||||
const hio_bch_t ch,
|
|
||||||
hio_oow_t len
|
|
||||||
);
|
|
||||||
|
|
||||||
/* ------------------------------------ */
|
|
||||||
|
|
||||||
HIO_EXPORT const hio_bch_t* hio_find_bcstr_word_in_bcstr (
|
|
||||||
const hio_bch_t* str,
|
|
||||||
const hio_bch_t* word,
|
|
||||||
hio_bch_t extra_delim,
|
|
||||||
int ignorecase
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT const hio_uch_t* hio_find_ucstr_word_in_ucstr (
|
|
||||||
const hio_uch_t* str,
|
|
||||||
const hio_uch_t* word,
|
|
||||||
hio_uch_t extra_delim,
|
|
||||||
int ignorecase
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_uch_t* hio_find_uchar_in_uchars (
|
|
||||||
const hio_uch_t* ptr,
|
|
||||||
hio_oow_t len,
|
|
||||||
hio_uch_t c
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_bch_t* hio_find_bchar_in_bchars (
|
|
||||||
const hio_bch_t* ptr,
|
|
||||||
hio_oow_t len,
|
|
||||||
hio_bch_t c
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_uch_t* hio_rfind_uchar_in_uchars (
|
|
||||||
const hio_uch_t* ptr,
|
|
||||||
hio_oow_t len,
|
|
||||||
hio_uch_t c
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_bch_t* hio_rfind_bchar_in_bchars (
|
|
||||||
const hio_bch_t* ptr,
|
|
||||||
hio_oow_t len,
|
|
||||||
hio_bch_t c
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_uch_t* hio_find_uchar_in_ucstr (
|
|
||||||
const hio_uch_t* ptr,
|
|
||||||
hio_uch_t c
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_bch_t* hio_find_bchar_in_bcstr (
|
|
||||||
const hio_bch_t* ptr,
|
|
||||||
hio_bch_t c
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_uch_t* hio_rfind_uchar_in_ucstr (
|
|
||||||
const hio_uch_t* ptr,
|
|
||||||
hio_uch_t c
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_bch_t* hio_rfind_bchar_in_bcstr (
|
|
||||||
const hio_bch_t* ptr,
|
|
||||||
hio_bch_t c
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_uch_t* hio_find_uchars_in_uchars (
|
|
||||||
const hio_uch_t* str,
|
|
||||||
hio_oow_t strsz,
|
|
||||||
const hio_uch_t* sub,
|
|
||||||
hio_oow_t subsz,
|
|
||||||
int inorecase
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_bch_t* hio_find_bchars_in_bchars (
|
|
||||||
const hio_bch_t* str,
|
|
||||||
hio_oow_t strsz,
|
|
||||||
const hio_bch_t* sub,
|
|
||||||
hio_oow_t subsz,
|
|
||||||
int inorecase
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_uch_t* hio_rfind_uchars_in_uchars (
|
|
||||||
const hio_uch_t* str,
|
|
||||||
hio_oow_t strsz,
|
|
||||||
const hio_uch_t* sub,
|
|
||||||
hio_oow_t subsz,
|
|
||||||
int inorecase
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_bch_t* hio_rfind_bchars_in_bchars (
|
|
||||||
const hio_bch_t* str,
|
|
||||||
hio_oow_t strsz,
|
|
||||||
const hio_bch_t* sub,
|
|
||||||
hio_oow_t subsz,
|
|
||||||
int inorecase
|
|
||||||
);
|
|
||||||
|
|
||||||
/* ------------------------------------ */
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_rotate_uchars (
|
|
||||||
hio_uch_t* str,
|
|
||||||
hio_oow_t len,
|
|
||||||
int dir,
|
|
||||||
hio_oow_t n
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_rotate_bchars (
|
|
||||||
hio_bch_t* str,
|
|
||||||
hio_oow_t len,
|
|
||||||
int dir,
|
|
||||||
hio_oow_t n
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
HIO_EXPORT hio_uch_t* hio_trim_uchars (
|
|
||||||
const hio_uch_t* str,
|
|
||||||
hio_oow_t* len,
|
|
||||||
int flags
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT hio_bch_t* hio_trim_bchars (
|
|
||||||
const hio_bch_t* str,
|
|
||||||
hio_oow_t* len,
|
|
||||||
int flags
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT 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_EXPORT 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
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(HIO_OOCH_IS_UCH)
|
|
||||||
# define hio_count_oocstr hio_count_ucstr
|
|
||||||
# define hio_count_oocstr_limited hio_count_ucstr_limited
|
|
||||||
|
|
||||||
# define hio_equal_oochars hio_equal_uchars
|
|
||||||
# define hio_comp_oochars hio_comp_uchars
|
|
||||||
# define hio_comp_oocstr_bcstr hio_comp_ucstr_bcstr
|
|
||||||
# define hio_comp_oochars_bcstr hio_comp_uchars_bcstr
|
|
||||||
# define hio_comp_oochars_ucstr hio_comp_uchars_ucstr
|
|
||||||
# define hio_comp_oochars_oocstr hio_comp_uchars_ucstr
|
|
||||||
# define hio_comp_oocstr hio_comp_ucstr
|
|
||||||
|
|
||||||
# define hio_copy_oochars hio_copy_uchars
|
|
||||||
# define hio_copy_bchars_to_oochars hio_copy_bchars_to_uchars
|
|
||||||
# define hio_copy_oochars_to_bchars hio_copy_uchars_to_bchars
|
|
||||||
# define hio_copy_uchars_to_oochars hio_copy_uchars
|
|
||||||
# define hio_copy_oochars_to_uchars hio_copy_uchars
|
|
||||||
|
|
||||||
# define hio_copy_oochars_to_oocstr hio_copy_uchars_to_ucstr
|
|
||||||
# define hio_copy_oochars_to_oocstr_unlimited hio_copy_uchars_to_ucstr_unlimited
|
|
||||||
# define hio_copy_oocstr hio_copy_ucstr
|
|
||||||
# define hio_copy_oocstr_unlimited hio_copy_ucstr_unlimited
|
|
||||||
# define hio_copy_fmt_oocses_to_oocstr hio_copy_fmt_ucses_to_ucstr
|
|
||||||
# define hio_copy_fmt_oocstr_to_oocstr hio_copy_fmt_ucstr_to_ucstr
|
|
||||||
|
|
||||||
# define hio_concat_oochars_to_ucstr hio_concat_uchars_to_ucstr
|
|
||||||
# define hio_concat_oocstr hio_concat_ucstr
|
|
||||||
|
|
||||||
# define hio_fill_oochars hio_fill_uchars
|
|
||||||
# define hio_find_oocstr_word_in_oocstr hio_find_ucstr_word_in_ucstr
|
|
||||||
# define hio_find_oochar_in_oochars hio_find_uchar_in_uchars
|
|
||||||
# define hio_rfind_oochar_in_oochars hio_rfind_uchar_in_uchars
|
|
||||||
# define hio_find_oochar_in_oocstr hio_find_uchar_in_ucstr
|
|
||||||
|
|
||||||
# define hio_trim_oochars hio_trim_uchars
|
|
||||||
# define hio_split_oocstr hio_split_ucstr
|
|
||||||
#else
|
|
||||||
# define hio_count_oocstr hio_count_bcstr
|
|
||||||
# define hio_count_oocstr_limited hio_count_bcstr_limited
|
|
||||||
|
|
||||||
# define hio_equal_oochars hio_equal_bchars
|
|
||||||
# define hio_comp_oochars hio_comp_bchars
|
|
||||||
# define hio_comp_oocstr_bcstr hio_comp_bcstr
|
|
||||||
# define hio_comp_oochars_bcstr hio_comp_bchars_bcstr
|
|
||||||
# define hio_comp_oochars_ucstr hio_comp_bchars_ucstr
|
|
||||||
# define hio_comp_oochars_oocstr hio_comp_bchars_bcstr
|
|
||||||
# define hio_comp_oocstr hio_comp_bcstr
|
|
||||||
|
|
||||||
# define hio_copy_oochars hio_copy_bchars
|
|
||||||
# define hio_copy_bchars_to_oochars hio_copy_bchars
|
|
||||||
# define hio_copy_oochars_to_bchars hio_copy_bchars
|
|
||||||
# define hio_copy_uchars_to_oochars hio_copy_uchars_to_bchars
|
|
||||||
# define hio_copy_oochars_to_uchars hio_copy_bchars_to_uchars
|
|
||||||
|
|
||||||
# define hio_copy_oochars_to_oocstr hio_copy_bchars_to_bcstr
|
|
||||||
# define hio_copy_oochars_to_oocstr_unlimited hio_copy_bchars_to_bcstr_unlimited
|
|
||||||
# define hio_copy_oocstr hio_copy_bcstr
|
|
||||||
# define hio_copy_oocstr_unlimited hio_copy_bcstr_unlimited
|
|
||||||
# define hio_copy_fmt_oocses_to_oocstr hio_copy_fmt_bcses_to_bcstr
|
|
||||||
# define hio_copy_fmt_oocstr_to_oocstr hio_copy_fmt_bcstr_to_bcstr
|
|
||||||
|
|
||||||
# define hio_concat_oochars_to_bcstr hio_concat_bchars_to_bcstr
|
|
||||||
# define hio_concat_oocstr hio_concat_bcstr
|
|
||||||
|
|
||||||
# define hio_fill_oochars hio_fill_bchars
|
|
||||||
# define hio_find_oocstr_word_in_oocstr hio_find_bcstr_word_in_bcstr
|
|
||||||
# define hio_find_oochar_in_oochars hio_find_bchar_in_bchars
|
|
||||||
# define hio_rfind_oochar_in_oochars hio_rfind_bchar_in_bchars
|
|
||||||
# define hio_find_oochar_in_oocstr hio_find_bchar_in_bcstr
|
|
||||||
|
|
||||||
# define hio_trim_oochars hio_trim_bchars
|
|
||||||
# define hio_split_oocstr hio_split_bcstr
|
|
||||||
#endif
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#define HIO_BYTE_TO_BCSTR_RADIXMASK (0xFF)
|
|
||||||
#define HIO_BYTE_TO_BCSTR_LOWERCASE (1 << 8)
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_byte_to_bcstr (
|
|
||||||
hio_uint8_t byte,
|
|
||||||
hio_bch_t* buf,
|
|
||||||
hio_oow_t size,
|
|
||||||
int flagged_radix,
|
|
||||||
hio_bch_t fill
|
|
||||||
);
|
|
||||||
|
|
||||||
#define HIO_BYTE_TO_UCSTR_RADIXMASK (0xFF)
|
|
||||||
#define HIO_BYTE_TO_UCSTR_LOWERCASE (1 << 8)
|
|
||||||
|
|
||||||
HIO_EXPORT hio_oow_t hio_byte_to_ucstr (
|
|
||||||
hio_uint8_t byte,
|
|
||||||
hio_uch_t* buf,
|
|
||||||
hio_oow_t size,
|
|
||||||
int flagged_radix,
|
|
||||||
hio_uch_t fill
|
|
||||||
);
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
#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_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_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_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_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_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_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_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,
|
|
||||||
hio_oow_t len,
|
|
||||||
int option,
|
|
||||||
const hio_uch_t** endptr,
|
|
||||||
int* is_sober
|
|
||||||
);
|
|
||||||
|
|
||||||
HIO_EXPORT 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_EXPORT 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_EXPORT 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
|
|
||||||
);
|
|
||||||
#if defined(HIO_OOCH_IS_UCH)
|
|
||||||
# define hio_oochars_to_intmax hio_uchars_to_intmax
|
|
||||||
# define hio_oochars_to_uintmax hio_uchars_to_uintmax
|
|
||||||
#else
|
|
||||||
# define hio_oochars_to_intmax hio_bchars_to_intmax
|
|
||||||
# define hio_oochars_to_uintmax hio_bchars_to_uintmax
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
#if defined(HIO_OOCH_IS_UCH)
|
|
||||||
# define hio_conv_oocstr_to_bcstr_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr) hio_conv_ucstr_to_bcstr_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr)
|
|
||||||
# define hio_conv_oochars_to_bchars_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr) hio_conv_uchars_to_bchars_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr)
|
|
||||||
#else
|
|
||||||
# define hio_conv_oocstr_to_ucstr_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr) hio_conv_bcstr_to_ucstr_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr,0)
|
|
||||||
# define hio_conv_oochars_to_uchars_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr) hio_conv_bchars_to_uchars_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr,0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
HIO_EXPORT int hio_conv_bcstr_to_ucstr_with_cmgr (
|
HIO_EXPORT int hio_conv_bcstr_to_ucstr_with_cmgr (
|
||||||
const hio_bch_t* bcs,
|
const hio_bch_t* bcs,
|
||||||
hio_oow_t* bcslen,
|
hio_oow_t* bcslen,
|
||||||
@ -895,6 +285,15 @@ HIO_EXPORT int hio_conv_uchars_to_bchars_with_cmgr (
|
|||||||
hio_cmgr_t* cmgr
|
hio_cmgr_t* cmgr
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#if defined(HIO_OOCH_IS_UCH)
|
||||||
|
# define hio_conv_oocstr_to_bcstr_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr) hio_conv_ucstr_to_bcstr_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr)
|
||||||
|
# define hio_conv_oochars_to_bchars_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr) hio_conv_uchars_to_bchars_with_cmgr(oocs,oocslen,bcs,bcslen,cmgr)
|
||||||
|
#else
|
||||||
|
# define hio_conv_oocstr_to_ucstr_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr) hio_conv_bcstr_to_ucstr_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr,0)
|
||||||
|
# define hio_conv_oochars_to_uchars_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr) hio_conv_bchars_to_uchars_with_cmgr(oocs,oocslen,ucs,ucslen,cmgr,0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
HIO_EXPORT hio_cmgr_t* hio_get_utf8_cmgr (
|
HIO_EXPORT hio_cmgr_t* hio_get_utf8_cmgr (
|
||||||
@ -1310,13 +709,11 @@ template<typename CHAR_TYPE, typename INT_TYPE, bool(*IS_SPACE)(CHAR_TYPE)>INT_T
|
|||||||
}
|
}
|
||||||
else if (rem >= 2 && base == 16)
|
else if (rem >= 2 && base == 16)
|
||||||
{
|
{
|
||||||
if (*p == '0' &&
|
if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
||||||
(*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
|
||||||
}
|
}
|
||||||
else if (rem >= 2 && base == 2)
|
else if (rem >= 2 && base == 2)
|
||||||
{
|
{
|
||||||
if (*p == '0' &&
|
if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
||||||
(*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* process the digits */
|
/* process the digits */
|
||||||
@ -1420,13 +817,11 @@ template<typename CHAR_TYPE, typename UINT_TYPE, bool(*IS_SPACE)(CHAR_TYPE)>UINT
|
|||||||
}
|
}
|
||||||
else if (rem >= 2 && base == 16)
|
else if (rem >= 2 && base == 16)
|
||||||
{
|
{
|
||||||
if (*p == '0' &&
|
if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
||||||
(*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
|
||||||
}
|
}
|
||||||
else if (rem >= 2 && base == 2)
|
else if (rem >= 2 && base == 2)
|
||||||
{
|
{
|
||||||
if (*p == '0' &&
|
if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
||||||
(*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* process the digits */
|
/* process the digits */
|
||||||
|
1266
hio/lib/hio-utl.h.m4
1266
hio/lib/hio-utl.h.m4
File diff suppressed because it is too large
Load Diff
@ -33,6 +33,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#if defined(HAVE_PTY_H)
|
#if defined(HAVE_PTY_H)
|
||||||
# include <pty.h>
|
# include <pty.h>
|
||||||
|
@ -1737,6 +1737,750 @@ exit_point:
|
|||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hio_uch_t* hio_tokenize_uchars (const hio_uch_t* s, hio_oow_t len, const hio_uch_t* delim, hio_oow_t delim_len, hio_ucs_t* tok, int ignorecase)
|
||||||
|
{
|
||||||
|
const hio_uch_t* p = s, *d;
|
||||||
|
const hio_uch_t* end = s + len;
|
||||||
|
const hio_uch_t* sp = HIO_NULL, * ep = HIO_NULL;
|
||||||
|
const hio_uch_t* delim_end = delim + delim_len;
|
||||||
|
hio_uch_t c;
|
||||||
|
int delim_mode;
|
||||||
|
|
||||||
|
#define __DELIM_NULL 0
|
||||||
|
#define __DELIM_EMPTY 1
|
||||||
|
#define __DELIM_SPACES 2
|
||||||
|
#define __DELIM_NOSPACES 3
|
||||||
|
#define __DELIM_COMPOSITE 4
|
||||||
|
if (delim == HIO_NULL) delim_mode = __DELIM_NULL;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
delim_mode = __DELIM_EMPTY;
|
||||||
|
|
||||||
|
for (d = delim; d < delim_end; d++)
|
||||||
|
{
|
||||||
|
if (hio_is_uch_space(*d))
|
||||||
|
{
|
||||||
|
if (delim_mode == __DELIM_EMPTY)
|
||||||
|
delim_mode = __DELIM_SPACES;
|
||||||
|
else if (delim_mode == __DELIM_NOSPACES)
|
||||||
|
{
|
||||||
|
delim_mode = __DELIM_COMPOSITE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (delim_mode == __DELIM_EMPTY)
|
||||||
|
delim_mode = __DELIM_NOSPACES;
|
||||||
|
else if (delim_mode == __DELIM_SPACES)
|
||||||
|
{
|
||||||
|
delim_mode = __DELIM_COMPOSITE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: verify the following statement... */
|
||||||
|
if (delim_mode == __DELIM_SPACES && delim_len == 1 && delim[0] != ' ') delim_mode = __DELIM_NOSPACES;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delim_mode == __DELIM_NULL)
|
||||||
|
{
|
||||||
|
/* when HIO_NULL is given as "delim", it trims off the
|
||||||
|
* leading and trailing spaces characters off the source
|
||||||
|
* string "s" eventually. */
|
||||||
|
|
||||||
|
while (p < end && hio_is_uch_space(*p)) p++;
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
c = *p;
|
||||||
|
|
||||||
|
if (!hio_is_uch_space(c))
|
||||||
|
{
|
||||||
|
if (sp == HIO_NULL) sp = p;
|
||||||
|
ep = p;
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (delim_mode == __DELIM_EMPTY)
|
||||||
|
{
|
||||||
|
/* each character in the source string "s" becomes a token. */
|
||||||
|
if (p < end)
|
||||||
|
{
|
||||||
|
c = *p;
|
||||||
|
sp = p;
|
||||||
|
ep = p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (delim_mode == __DELIM_SPACES)
|
||||||
|
{
|
||||||
|
/* each token is delimited by space characters. all leading
|
||||||
|
* and trailing spaces are removed. */
|
||||||
|
|
||||||
|
while (p < end && hio_is_uch_space(*p)) p++;
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
c = *p;
|
||||||
|
if (hio_is_uch_space(c)) break;
|
||||||
|
if (sp == HIO_NULL) sp = p;
|
||||||
|
ep = p++;
|
||||||
|
}
|
||||||
|
while (p < end && hio_is_uch_space(*p)) p++;
|
||||||
|
}
|
||||||
|
else if (delim_mode == __DELIM_NOSPACES)
|
||||||
|
{
|
||||||
|
/* each token is delimited by one of charaters
|
||||||
|
* in the delimeter set "delim". */
|
||||||
|
if (ignorecase)
|
||||||
|
{
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
c = hio_to_uch_lower(*p);
|
||||||
|
for (d = delim; d < delim_end; d++)
|
||||||
|
{
|
||||||
|
if (c == hio_to_uch_lower(*d)) goto exit_loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sp == HIO_NULL) sp = p;
|
||||||
|
ep = p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
c = *p;
|
||||||
|
for (d = delim; d < delim_end; d++)
|
||||||
|
{
|
||||||
|
if (c == *d) goto exit_loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sp == HIO_NULL) sp = p;
|
||||||
|
ep = p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else /* if (delim_mode == __DELIM_COMPOSITE) */
|
||||||
|
{
|
||||||
|
/* each token is delimited by one of non-space charaters
|
||||||
|
* in the delimeter set "delim". however, all space characters
|
||||||
|
* surrounding the token are removed */
|
||||||
|
while (p < end && hio_is_uch_space(*p)) p++;
|
||||||
|
if (ignorecase)
|
||||||
|
{
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
c = hio_to_uch_lower(*p);
|
||||||
|
if (hio_is_uch_space(c))
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (d = delim; d < delim_end; d++)
|
||||||
|
{
|
||||||
|
if (c == hio_to_uch_lower(*d)) goto exit_loop;
|
||||||
|
}
|
||||||
|
if (sp == HIO_NULL) sp = p;
|
||||||
|
ep = p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
c = *p;
|
||||||
|
if (hio_is_uch_space(c))
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (d = delim; d < delim_end; d++)
|
||||||
|
{
|
||||||
|
if (c == *d) goto exit_loop;
|
||||||
|
}
|
||||||
|
if (sp == HIO_NULL) sp = p;
|
||||||
|
ep = p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exit_loop:
|
||||||
|
if (sp == HIO_NULL)
|
||||||
|
{
|
||||||
|
tok->ptr = HIO_NULL;
|
||||||
|
tok->len = (hio_oow_t)0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tok->ptr = (hio_uch_t*)sp;
|
||||||
|
tok->len = ep - sp + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if HIO_NULL is returned, this function should not be called again */
|
||||||
|
if (p >= end) return HIO_NULL;
|
||||||
|
if (delim_mode == __DELIM_EMPTY || delim_mode == __DELIM_SPACES) return (hio_uch_t*)p;
|
||||||
|
return (hio_uch_t*)++p;
|
||||||
|
}
|
||||||
|
|
||||||
|
hio_bch_t* hio_tokenize_bchars (const hio_bch_t* s, hio_oow_t len, const hio_bch_t* delim, hio_oow_t delim_len, hio_bcs_t* tok, int ignorecase)
|
||||||
|
{
|
||||||
|
const hio_bch_t* p = s, *d;
|
||||||
|
const hio_bch_t* end = s + len;
|
||||||
|
const hio_bch_t* sp = HIO_NULL, * ep = HIO_NULL;
|
||||||
|
const hio_bch_t* delim_end = delim + delim_len;
|
||||||
|
hio_bch_t c;
|
||||||
|
int delim_mode;
|
||||||
|
|
||||||
|
#define __DELIM_NULL 0
|
||||||
|
#define __DELIM_EMPTY 1
|
||||||
|
#define __DELIM_SPACES 2
|
||||||
|
#define __DELIM_NOSPACES 3
|
||||||
|
#define __DELIM_COMPOSITE 4
|
||||||
|
if (delim == HIO_NULL) delim_mode = __DELIM_NULL;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
delim_mode = __DELIM_EMPTY;
|
||||||
|
|
||||||
|
for (d = delim; d < delim_end; d++)
|
||||||
|
{
|
||||||
|
if (hio_is_bch_space(*d))
|
||||||
|
{
|
||||||
|
if (delim_mode == __DELIM_EMPTY)
|
||||||
|
delim_mode = __DELIM_SPACES;
|
||||||
|
else if (delim_mode == __DELIM_NOSPACES)
|
||||||
|
{
|
||||||
|
delim_mode = __DELIM_COMPOSITE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (delim_mode == __DELIM_EMPTY)
|
||||||
|
delim_mode = __DELIM_NOSPACES;
|
||||||
|
else if (delim_mode == __DELIM_SPACES)
|
||||||
|
{
|
||||||
|
delim_mode = __DELIM_COMPOSITE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: verify the following statement... */
|
||||||
|
if (delim_mode == __DELIM_SPACES && delim_len == 1 && delim[0] != ' ') delim_mode = __DELIM_NOSPACES;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delim_mode == __DELIM_NULL)
|
||||||
|
{
|
||||||
|
/* when HIO_NULL is given as "delim", it trims off the
|
||||||
|
* leading and trailing spaces characters off the source
|
||||||
|
* string "s" eventually. */
|
||||||
|
|
||||||
|
while (p < end && hio_is_bch_space(*p)) p++;
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
c = *p;
|
||||||
|
|
||||||
|
if (!hio_is_bch_space(c))
|
||||||
|
{
|
||||||
|
if (sp == HIO_NULL) sp = p;
|
||||||
|
ep = p;
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (delim_mode == __DELIM_EMPTY)
|
||||||
|
{
|
||||||
|
/* each character in the source string "s" becomes a token. */
|
||||||
|
if (p < end)
|
||||||
|
{
|
||||||
|
c = *p;
|
||||||
|
sp = p;
|
||||||
|
ep = p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (delim_mode == __DELIM_SPACES)
|
||||||
|
{
|
||||||
|
/* each token is delimited by space characters. all leading
|
||||||
|
* and trailing spaces are removed. */
|
||||||
|
|
||||||
|
while (p < end && hio_is_bch_space(*p)) p++;
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
c = *p;
|
||||||
|
if (hio_is_bch_space(c)) break;
|
||||||
|
if (sp == HIO_NULL) sp = p;
|
||||||
|
ep = p++;
|
||||||
|
}
|
||||||
|
while (p < end && hio_is_bch_space(*p)) p++;
|
||||||
|
}
|
||||||
|
else if (delim_mode == __DELIM_NOSPACES)
|
||||||
|
{
|
||||||
|
/* each token is delimited by one of charaters
|
||||||
|
* in the delimeter set "delim". */
|
||||||
|
if (ignorecase)
|
||||||
|
{
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
c = hio_to_bch_lower(*p);
|
||||||
|
for (d = delim; d < delim_end; d++)
|
||||||
|
{
|
||||||
|
if (c == hio_to_bch_lower(*d)) goto exit_loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sp == HIO_NULL) sp = p;
|
||||||
|
ep = p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
c = *p;
|
||||||
|
for (d = delim; d < delim_end; d++)
|
||||||
|
{
|
||||||
|
if (c == *d) goto exit_loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sp == HIO_NULL) sp = p;
|
||||||
|
ep = p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else /* if (delim_mode == __DELIM_COMPOSITE) */
|
||||||
|
{
|
||||||
|
/* each token is delimited by one of non-space charaters
|
||||||
|
* in the delimeter set "delim". however, all space characters
|
||||||
|
* surrounding the token are removed */
|
||||||
|
while (p < end && hio_is_bch_space(*p)) p++;
|
||||||
|
if (ignorecase)
|
||||||
|
{
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
c = hio_to_bch_lower(*p);
|
||||||
|
if (hio_is_bch_space(c))
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (d = delim; d < delim_end; d++)
|
||||||
|
{
|
||||||
|
if (c == hio_to_bch_lower(*d)) goto exit_loop;
|
||||||
|
}
|
||||||
|
if (sp == HIO_NULL) sp = p;
|
||||||
|
ep = p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
c = *p;
|
||||||
|
if (hio_is_bch_space(c))
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (d = delim; d < delim_end; d++)
|
||||||
|
{
|
||||||
|
if (c == *d) goto exit_loop;
|
||||||
|
}
|
||||||
|
if (sp == HIO_NULL) sp = p;
|
||||||
|
ep = p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exit_loop:
|
||||||
|
if (sp == HIO_NULL)
|
||||||
|
{
|
||||||
|
tok->ptr = HIO_NULL;
|
||||||
|
tok->len = (hio_oow_t)0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tok->ptr = (hio_bch_t*)sp;
|
||||||
|
tok->len = ep - sp + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if HIO_NULL is returned, this function should not be called again */
|
||||||
|
if (p >= end) return HIO_NULL;
|
||||||
|
if (delim_mode == __DELIM_EMPTY || delim_mode == __DELIM_SPACES) return (hio_bch_t*)p;
|
||||||
|
return (hio_bch_t*)++p;
|
||||||
|
}
|
||||||
|
|
||||||
|
hio_oow_t hio_byte_to_ucstr (hio_uint8_t byte, hio_uch_t* buf, hio_oow_t size, int flagged_radix, hio_uch_t fill)
|
||||||
|
{
|
||||||
|
hio_uch_t tmp[(HIO_SIZEOF(hio_uint8_t) * HIO_BITS_PER_BYTE)];
|
||||||
|
hio_uch_t* p = tmp, * bp = buf, * be = buf + size - 1;
|
||||||
|
int radix;
|
||||||
|
hio_uch_t radix_char;
|
||||||
|
|
||||||
|
radix = (flagged_radix & HIO_BYTE_TO_UCSTR_RADIXMASK);
|
||||||
|
radix_char = (flagged_radix & HIO_BYTE_TO_UCSTR_LOWERCASE)? 'a': 'A';
|
||||||
|
if (radix < 2 || radix > 36 || size <= 0) return 0;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
hio_uint8_t digit = byte % radix;
|
||||||
|
if (digit < 10) *p++ = digit + '0';
|
||||||
|
else *p++ = digit + radix_char - 10;
|
||||||
|
byte /= radix;
|
||||||
|
}
|
||||||
|
while (byte > 0);
|
||||||
|
|
||||||
|
if (fill != '\0')
|
||||||
|
{
|
||||||
|
while (size - 1 > p - tmp)
|
||||||
|
{
|
||||||
|
*bp++ = fill;
|
||||||
|
size--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (p > tmp && bp < be) *bp++ = *--p;
|
||||||
|
*bp = '\0';
|
||||||
|
return bp - buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
hio_oow_t hio_byte_to_bcstr (hio_uint8_t byte, hio_bch_t* buf, hio_oow_t size, int flagged_radix, hio_bch_t fill)
|
||||||
|
{
|
||||||
|
hio_bch_t tmp[(HIO_SIZEOF(hio_uint8_t) * HIO_BITS_PER_BYTE)];
|
||||||
|
hio_bch_t* p = tmp, * bp = buf, * be = buf + size - 1;
|
||||||
|
int radix;
|
||||||
|
hio_bch_t radix_char;
|
||||||
|
|
||||||
|
radix = (flagged_radix & HIO_BYTE_TO_BCSTR_RADIXMASK);
|
||||||
|
radix_char = (flagged_radix & HIO_BYTE_TO_BCSTR_LOWERCASE)? 'a': 'A';
|
||||||
|
if (radix < 2 || radix > 36 || size <= 0) return 0;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
hio_uint8_t digit = byte % radix;
|
||||||
|
if (digit < 10) *p++ = digit + '0';
|
||||||
|
else *p++ = digit + radix_char - 10;
|
||||||
|
byte /= radix;
|
||||||
|
}
|
||||||
|
while (byte > 0);
|
||||||
|
|
||||||
|
if (fill != '\0')
|
||||||
|
{
|
||||||
|
while (size - 1 > p - tmp)
|
||||||
|
{
|
||||||
|
*bp++ = fill;
|
||||||
|
size--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (p > tmp && bp < be) *bp++ = *--p;
|
||||||
|
*bp = '\0';
|
||||||
|
return bp - buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
hio_oow_t hio_intmax_to_ucstr (hio_intmax_t value, int radix, const hio_uch_t* prefix, hio_uch_t* buf, hio_oow_t size)
|
||||||
|
{
|
||||||
|
hio_intmax_t t, rem;
|
||||||
|
hio_oow_t len, ret, i;
|
||||||
|
hio_oow_t prefix_len;
|
||||||
|
|
||||||
|
prefix_len = (prefix != HIO_NULL)? hio_count_ucstr(prefix): 0;
|
||||||
|
|
||||||
|
t = value;
|
||||||
|
if (t == 0)
|
||||||
|
{
|
||||||
|
/* zero */
|
||||||
|
if (buf == HIO_NULL)
|
||||||
|
{
|
||||||
|
/* if buf is not given,
|
||||||
|
* return the number of bytes required */
|
||||||
|
return prefix_len + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size < prefix_len+1)
|
||||||
|
{
|
||||||
|
/* buffer too small */
|
||||||
|
return (hio_oow_t)-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < prefix_len; i++) buf[i] = prefix[i];
|
||||||
|
buf[prefix_len] = '0';
|
||||||
|
if (size > prefix_len+1) buf[prefix_len+1] = '\0';
|
||||||
|
return prefix_len+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* non-zero values */
|
||||||
|
len = prefix_len;
|
||||||
|
if (t < 0) { t = -t; len++; }
|
||||||
|
while (t > 0) { len++; t /= radix; }
|
||||||
|
|
||||||
|
if (buf == HIO_NULL)
|
||||||
|
{
|
||||||
|
/* if buf is not given, return the number of bytes required */
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size < len) return (hio_oow_t)-1; /* buffer too small */
|
||||||
|
if (size > len) buf[len] = '\0';
|
||||||
|
ret = len;
|
||||||
|
|
||||||
|
t = value;
|
||||||
|
if (t < 0) t = -t;
|
||||||
|
|
||||||
|
while (t > 0)
|
||||||
|
{
|
||||||
|
rem = t % radix;
|
||||||
|
if (rem >= 10)
|
||||||
|
buf[--len] = (hio_uch_t)rem + 'a' - 10;
|
||||||
|
else
|
||||||
|
buf[--len] = (hio_uch_t)rem + '0';
|
||||||
|
t /= radix;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value < 0)
|
||||||
|
{
|
||||||
|
for (i = 1; i <= prefix_len; i++)
|
||||||
|
{
|
||||||
|
buf[i] = prefix[i-1];
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
buf[--len] = '-';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = 0; i < prefix_len; i++) buf[i] = prefix[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
hio_oow_t hio_intmax_to_bcstr (hio_intmax_t value, int radix, const hio_bch_t* prefix, hio_bch_t* buf, hio_oow_t size)
|
||||||
|
{
|
||||||
|
hio_intmax_t t, rem;
|
||||||
|
hio_oow_t len, ret, i;
|
||||||
|
hio_oow_t prefix_len;
|
||||||
|
|
||||||
|
prefix_len = (prefix != HIO_NULL)? hio_count_bcstr(prefix): 0;
|
||||||
|
|
||||||
|
t = value;
|
||||||
|
if (t == 0)
|
||||||
|
{
|
||||||
|
/* zero */
|
||||||
|
if (buf == HIO_NULL)
|
||||||
|
{
|
||||||
|
/* if buf is not given,
|
||||||
|
* return the number of bytes required */
|
||||||
|
return prefix_len + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size < prefix_len+1)
|
||||||
|
{
|
||||||
|
/* buffer too small */
|
||||||
|
return (hio_oow_t)-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < prefix_len; i++) buf[i] = prefix[i];
|
||||||
|
buf[prefix_len] = '0';
|
||||||
|
if (size > prefix_len+1) buf[prefix_len+1] = '\0';
|
||||||
|
return prefix_len+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* non-zero values */
|
||||||
|
len = prefix_len;
|
||||||
|
if (t < 0) { t = -t; len++; }
|
||||||
|
while (t > 0) { len++; t /= radix; }
|
||||||
|
|
||||||
|
if (buf == HIO_NULL)
|
||||||
|
{
|
||||||
|
/* if buf is not given, return the number of bytes required */
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size < len) return (hio_oow_t)-1; /* buffer too small */
|
||||||
|
if (size > len) buf[len] = '\0';
|
||||||
|
ret = len;
|
||||||
|
|
||||||
|
t = value;
|
||||||
|
if (t < 0) t = -t;
|
||||||
|
|
||||||
|
while (t > 0)
|
||||||
|
{
|
||||||
|
rem = t % radix;
|
||||||
|
if (rem >= 10)
|
||||||
|
buf[--len] = (hio_bch_t)rem + 'a' - 10;
|
||||||
|
else
|
||||||
|
buf[--len] = (hio_bch_t)rem + '0';
|
||||||
|
t /= radix;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value < 0)
|
||||||
|
{
|
||||||
|
for (i = 1; i <= prefix_len; i++)
|
||||||
|
{
|
||||||
|
buf[i] = prefix[i-1];
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
buf[--len] = '-';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = 0; i < prefix_len; i++) buf[i] = prefix[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
hio_oow_t hio_uintmax_to_ucstr (hio_uintmax_t value, int radix, const hio_uch_t* prefix, hio_uch_t* buf, hio_oow_t size)
|
||||||
|
{
|
||||||
|
hio_uintmax_t t, rem;
|
||||||
|
hio_oow_t len, ret, i;
|
||||||
|
hio_oow_t prefix_len;
|
||||||
|
|
||||||
|
prefix_len = (prefix != HIO_NULL)? hio_count_ucstr(prefix): 0;
|
||||||
|
|
||||||
|
t = value;
|
||||||
|
if (t == 0)
|
||||||
|
{
|
||||||
|
/* zero */
|
||||||
|
if (buf == HIO_NULL)
|
||||||
|
{
|
||||||
|
/* if buf is not given,
|
||||||
|
* return the number of bytes required */
|
||||||
|
return prefix_len + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size < prefix_len+1)
|
||||||
|
{
|
||||||
|
/* buffer too small */
|
||||||
|
return (hio_oow_t)-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < prefix_len; i++) buf[i] = prefix[i];
|
||||||
|
buf[prefix_len] = '0';
|
||||||
|
if (size > prefix_len+1) buf[prefix_len+1] = '\0';
|
||||||
|
return prefix_len+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* non-zero values */
|
||||||
|
len = prefix_len;
|
||||||
|
if (t < 0) { t = -t; len++; }
|
||||||
|
while (t > 0) { len++; t /= radix; }
|
||||||
|
|
||||||
|
if (buf == HIO_NULL)
|
||||||
|
{
|
||||||
|
/* if buf is not given, return the number of bytes required */
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size < len) return (hio_oow_t)-1; /* buffer too small */
|
||||||
|
if (size > len) buf[len] = '\0';
|
||||||
|
ret = len;
|
||||||
|
|
||||||
|
t = value;
|
||||||
|
if (t < 0) t = -t;
|
||||||
|
|
||||||
|
while (t > 0)
|
||||||
|
{
|
||||||
|
rem = t % radix;
|
||||||
|
if (rem >= 10)
|
||||||
|
buf[--len] = (hio_uch_t)rem + 'a' - 10;
|
||||||
|
else
|
||||||
|
buf[--len] = (hio_uch_t)rem + '0';
|
||||||
|
t /= radix;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value < 0)
|
||||||
|
{
|
||||||
|
for (i = 1; i <= prefix_len; i++)
|
||||||
|
{
|
||||||
|
buf[i] = prefix[i-1];
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
buf[--len] = '-';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = 0; i < prefix_len; i++) buf[i] = prefix[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
hio_oow_t hio_uintmax_to_bcstr (hio_uintmax_t value, int radix, const hio_bch_t* prefix, hio_bch_t* buf, hio_oow_t size)
|
||||||
|
{
|
||||||
|
hio_uintmax_t t, rem;
|
||||||
|
hio_oow_t len, ret, i;
|
||||||
|
hio_oow_t prefix_len;
|
||||||
|
|
||||||
|
prefix_len = (prefix != HIO_NULL)? hio_count_bcstr(prefix): 0;
|
||||||
|
|
||||||
|
t = value;
|
||||||
|
if (t == 0)
|
||||||
|
{
|
||||||
|
/* zero */
|
||||||
|
if (buf == HIO_NULL)
|
||||||
|
{
|
||||||
|
/* if buf is not given,
|
||||||
|
* return the number of bytes required */
|
||||||
|
return prefix_len + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size < prefix_len+1)
|
||||||
|
{
|
||||||
|
/* buffer too small */
|
||||||
|
return (hio_oow_t)-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < prefix_len; i++) buf[i] = prefix[i];
|
||||||
|
buf[prefix_len] = '0';
|
||||||
|
if (size > prefix_len+1) buf[prefix_len+1] = '\0';
|
||||||
|
return prefix_len+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* non-zero values */
|
||||||
|
len = prefix_len;
|
||||||
|
if (t < 0) { t = -t; len++; }
|
||||||
|
while (t > 0) { len++; t /= radix; }
|
||||||
|
|
||||||
|
if (buf == HIO_NULL)
|
||||||
|
{
|
||||||
|
/* if buf is not given, return the number of bytes required */
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size < len) return (hio_oow_t)-1; /* buffer too small */
|
||||||
|
if (size > len) buf[len] = '\0';
|
||||||
|
ret = len;
|
||||||
|
|
||||||
|
t = value;
|
||||||
|
if (t < 0) t = -t;
|
||||||
|
|
||||||
|
while (t > 0)
|
||||||
|
{
|
||||||
|
rem = t % radix;
|
||||||
|
if (rem >= 10)
|
||||||
|
buf[--len] = (hio_bch_t)rem + 'a' - 10;
|
||||||
|
else
|
||||||
|
buf[--len] = (hio_bch_t)rem + '0';
|
||||||
|
t /= radix;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value < 0)
|
||||||
|
{
|
||||||
|
for (i = 1; i <= prefix_len; i++)
|
||||||
|
{
|
||||||
|
buf[i] = prefix[i-1];
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
buf[--len] = '-';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = 0; i < prefix_len; i++) buf[i] = prefix[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
@ -1790,13 +2534,11 @@ hio_intmax_t hio_uchars_to_intmax (const hio_uch_t* str, hio_oow_t len, int opti
|
|||||||
}
|
}
|
||||||
else if (rem >= 2 && base == 16)
|
else if (rem >= 2 && base == 16)
|
||||||
{
|
{
|
||||||
if (*p == '0' &&
|
if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
||||||
(*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
|
||||||
}
|
}
|
||||||
else if (rem >= 2 && base == 2)
|
else if (rem >= 2 && base == 2)
|
||||||
{
|
{
|
||||||
if (*p == '0' &&
|
if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
||||||
(*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* process the digits */
|
/* process the digits */
|
||||||
@ -1905,13 +2647,11 @@ hio_intmax_t hio_bchars_to_intmax (const hio_bch_t* str, hio_oow_t len, int opti
|
|||||||
}
|
}
|
||||||
else if (rem >= 2 && base == 16)
|
else if (rem >= 2 && base == 16)
|
||||||
{
|
{
|
||||||
if (*p == '0' &&
|
if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
||||||
(*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
|
||||||
}
|
}
|
||||||
else if (rem >= 2 && base == 2)
|
else if (rem >= 2 && base == 2)
|
||||||
{
|
{
|
||||||
if (*p == '0' &&
|
if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
||||||
(*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* process the digits */
|
/* process the digits */
|
||||||
@ -2015,13 +2755,11 @@ hio_uintmax_t hio_uchars_to_uintmax (const hio_uch_t* str, hio_oow_t len, int op
|
|||||||
}
|
}
|
||||||
else if (rem >= 2 && base == 16)
|
else if (rem >= 2 && base == 16)
|
||||||
{
|
{
|
||||||
if (*p == '0' &&
|
if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
||||||
(*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
|
||||||
}
|
}
|
||||||
else if (rem >= 2 && base == 2)
|
else if (rem >= 2 && base == 2)
|
||||||
{
|
{
|
||||||
if (*p == '0' &&
|
if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
||||||
(*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* process the digits */
|
/* process the digits */
|
||||||
@ -2125,13 +2863,11 @@ hio_uintmax_t hio_bchars_to_uintmax (const hio_bch_t* str, hio_oow_t len, int op
|
|||||||
}
|
}
|
||||||
else if (rem >= 2 && base == 16)
|
else if (rem >= 2 && base == 16)
|
||||||
{
|
{
|
||||||
if (*p == '0' &&
|
if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
||||||
(*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
|
||||||
}
|
}
|
||||||
else if (rem >= 2 && base == 2)
|
else if (rem >= 2 && base == 2)
|
||||||
{
|
{
|
||||||
if (*p == '0' &&
|
if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
||||||
(*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* process the digits */
|
/* process the digits */
|
||||||
|
@ -117,6 +117,17 @@ 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 --
|
dnl --
|
||||||
|
fn_tokenize_chars(hio_tokenize_uchars, hio_uch_t, hio_ucs_t, hio_is_uch_space, hio_to_uch_lower)
|
||||||
|
fn_tokenize_chars(hio_tokenize_bchars, hio_bch_t, hio_bcs_t, hio_is_bch_space, hio_to_bch_lower)
|
||||||
|
dnl --
|
||||||
|
fn_byte_to_cstr(hio_byte_to_ucstr, hio_uch_t, HIO_BYTE_TO_UCSTR)
|
||||||
|
fn_byte_to_cstr(hio_byte_to_bcstr, hio_bch_t, HIO_BYTE_TO_BCSTR)
|
||||||
|
dnl --
|
||||||
|
fn_int_to_cstr(hio_intmax_to_ucstr, hio_uch_t, hio_intmax_t, hio_count_ucstr)
|
||||||
|
fn_int_to_cstr(hio_intmax_to_bcstr, hio_bch_t, hio_intmax_t, hio_count_bcstr)
|
||||||
|
fn_int_to_cstr(hio_uintmax_to_ucstr, hio_uch_t, hio_uintmax_t, hio_count_ucstr)
|
||||||
|
fn_int_to_cstr(hio_uintmax_to_bcstr, hio_bch_t, hio_uintmax_t, hio_count_bcstr)
|
||||||
|
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 --
|
dnl --
|
||||||
|
@ -331,8 +331,8 @@ fini:
|
|||||||
popdef([[_fn_name_]])popdef([[_char_type_]])dnl
|
popdef([[_fn_name_]])popdef([[_char_type_]])dnl
|
||||||
]])dnl
|
]])dnl
|
||||||
dnl ---------------------------------------------------------------------------
|
dnl ---------------------------------------------------------------------------
|
||||||
define([[fn_copy_fmt_cses_to_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_cs_t_]], $3)dnl
|
define([[fn_copy_fmt_cses_to_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_cs_type_]], $3)dnl
|
||||||
hio_oow_t _fn_name_ (_char_type_* buf, hio_oow_t bsz, const _char_type_* fmt, const _cs_t_ str[])
|
hio_oow_t _fn_name_ (_char_type_* buf, hio_oow_t bsz, const _char_type_* fmt, const _cs_type_ str[])
|
||||||
{
|
{
|
||||||
_char_type_* b = buf;
|
_char_type_* b = buf;
|
||||||
_char_type_* end = buf + bsz - 1;
|
_char_type_* end = buf + bsz - 1;
|
||||||
@ -392,7 +392,7 @@ fini:
|
|||||||
*b = '\0';
|
*b = '\0';
|
||||||
return b - buf;
|
return b - buf;
|
||||||
}
|
}
|
||||||
popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_cs_t_]])dnl
|
popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_cs_type_]])dnl
|
||||||
]])dnl
|
]])dnl
|
||||||
dnl ---------------------------------------------------------------------------
|
dnl ---------------------------------------------------------------------------
|
||||||
define([[fn_count_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
|
define([[fn_count_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
|
||||||
@ -934,6 +934,310 @@ exit_point:
|
|||||||
}
|
}
|
||||||
popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_is_space_]])popdef([[_copy_str_unlimited_]])dnl
|
popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_is_space_]])popdef([[_copy_str_unlimited_]])dnl
|
||||||
]])dnl
|
]])dnl
|
||||||
|
define([[fn_tokenize_chars]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_cs_type_]], $3)pushdef([[_is_space_]], $4)pushdef([[_to_lower_]], $5)dnl
|
||||||
|
_char_type_* _fn_name_ (const _char_type_* s, hio_oow_t len, const _char_type_* delim, hio_oow_t delim_len, _cs_type_* tok, int ignorecase)
|
||||||
|
{
|
||||||
|
const _char_type_* p = s, *d;
|
||||||
|
const _char_type_* end = s + len;
|
||||||
|
const _char_type_* sp = HIO_NULL, * ep = HIO_NULL;
|
||||||
|
const _char_type_* delim_end = delim + delim_len;
|
||||||
|
_char_type_ c;
|
||||||
|
int delim_mode;
|
||||||
|
|
||||||
|
#define __DELIM_NULL 0
|
||||||
|
#define __DELIM_EMPTY 1
|
||||||
|
#define __DELIM_SPACES 2
|
||||||
|
#define __DELIM_NOSPACES 3
|
||||||
|
#define __DELIM_COMPOSITE 4
|
||||||
|
if (delim == HIO_NULL) delim_mode = __DELIM_NULL;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
delim_mode = __DELIM_EMPTY;
|
||||||
|
|
||||||
|
for (d = delim; d < delim_end; d++)
|
||||||
|
{
|
||||||
|
if (_is_space_()(*d))
|
||||||
|
{
|
||||||
|
if (delim_mode == __DELIM_EMPTY)
|
||||||
|
delim_mode = __DELIM_SPACES;
|
||||||
|
else if (delim_mode == __DELIM_NOSPACES)
|
||||||
|
{
|
||||||
|
delim_mode = __DELIM_COMPOSITE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (delim_mode == __DELIM_EMPTY)
|
||||||
|
delim_mode = __DELIM_NOSPACES;
|
||||||
|
else if (delim_mode == __DELIM_SPACES)
|
||||||
|
{
|
||||||
|
delim_mode = __DELIM_COMPOSITE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: verify the following statement... */
|
||||||
|
if (delim_mode == __DELIM_SPACES && delim_len == 1 && delim[0] != ' ') delim_mode = __DELIM_NOSPACES;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delim_mode == __DELIM_NULL)
|
||||||
|
{
|
||||||
|
/* when HIO_NULL is given as "delim", it trims off the
|
||||||
|
* leading and trailing spaces characters off the source
|
||||||
|
* string "s" eventually. */
|
||||||
|
|
||||||
|
while (p < end && _is_space_()(*p)) p++;
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
c = *p;
|
||||||
|
|
||||||
|
if (!_is_space_()(c))
|
||||||
|
{
|
||||||
|
if (sp == HIO_NULL) sp = p;
|
||||||
|
ep = p;
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (delim_mode == __DELIM_EMPTY)
|
||||||
|
{
|
||||||
|
/* each character in the source string "s" becomes a token. */
|
||||||
|
if (p < end)
|
||||||
|
{
|
||||||
|
c = *p;
|
||||||
|
sp = p;
|
||||||
|
ep = p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (delim_mode == __DELIM_SPACES)
|
||||||
|
{
|
||||||
|
/* each token is delimited by space characters. all leading
|
||||||
|
* and trailing spaces are removed. */
|
||||||
|
|
||||||
|
while (p < end && _is_space_()(*p)) p++;
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
c = *p;
|
||||||
|
if (_is_space_()(c)) break;
|
||||||
|
if (sp == HIO_NULL) sp = p;
|
||||||
|
ep = p++;
|
||||||
|
}
|
||||||
|
while (p < end && _is_space_()(*p)) p++;
|
||||||
|
}
|
||||||
|
else if (delim_mode == __DELIM_NOSPACES)
|
||||||
|
{
|
||||||
|
/* each token is delimited by one of charaters
|
||||||
|
* in the delimeter set "delim". */
|
||||||
|
if (ignorecase)
|
||||||
|
{
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
c = _to_lower_()(*p);
|
||||||
|
for (d = delim; d < delim_end; d++)
|
||||||
|
{
|
||||||
|
if (c == _to_lower_()(*d)) goto exit_loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sp == HIO_NULL) sp = p;
|
||||||
|
ep = p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
c = *p;
|
||||||
|
for (d = delim; d < delim_end; d++)
|
||||||
|
{
|
||||||
|
if (c == *d) goto exit_loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sp == HIO_NULL) sp = p;
|
||||||
|
ep = p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else /* if (delim_mode == __DELIM_COMPOSITE) */
|
||||||
|
{
|
||||||
|
/* each token is delimited by one of non-space charaters
|
||||||
|
* in the delimeter set "delim". however, all space characters
|
||||||
|
* surrounding the token are removed */
|
||||||
|
while (p < end && _is_space_()(*p)) p++;
|
||||||
|
if (ignorecase)
|
||||||
|
{
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
c = _to_lower_()(*p);
|
||||||
|
if (_is_space_()(c))
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (d = delim; d < delim_end; d++)
|
||||||
|
{
|
||||||
|
if (c == _to_lower_()(*d)) goto exit_loop;
|
||||||
|
}
|
||||||
|
if (sp == HIO_NULL) sp = p;
|
||||||
|
ep = p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
c = *p;
|
||||||
|
if (_is_space_()(c))
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (d = delim; d < delim_end; d++)
|
||||||
|
{
|
||||||
|
if (c == *d) goto exit_loop;
|
||||||
|
}
|
||||||
|
if (sp == HIO_NULL) sp = p;
|
||||||
|
ep = p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exit_loop:
|
||||||
|
if (sp == HIO_NULL)
|
||||||
|
{
|
||||||
|
tok->ptr = HIO_NULL;
|
||||||
|
tok->len = (hio_oow_t)0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tok->ptr = (_char_type_*)sp;
|
||||||
|
tok->len = ep - sp + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if HIO_NULL is returned, this function should not be called again */
|
||||||
|
if (p >= end) return HIO_NULL;
|
||||||
|
if (delim_mode == __DELIM_EMPTY || delim_mode == __DELIM_SPACES) return (_char_type_*)p;
|
||||||
|
return (_char_type_*)++p;
|
||||||
|
}
|
||||||
|
popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_cs_type_]])popdef([[_is_space_]])popdef([[_to_lower_]])dnl
|
||||||
|
]])dnl
|
||||||
|
dnl ---------------------------------------------------------------------------
|
||||||
|
define([[fn_byte_to_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_prefix_]], $3)dnl
|
||||||
|
hio_oow_t _fn_name_ (hio_uint8_t byte, _char_type_* buf, hio_oow_t size, int flagged_radix, _char_type_ fill)
|
||||||
|
{
|
||||||
|
_char_type_ tmp[(HIO_SIZEOF(hio_uint8_t) * HIO_BITS_PER_BYTE)];
|
||||||
|
_char_type_* p = tmp, * bp = buf, * be = buf + size - 1;
|
||||||
|
int radix;
|
||||||
|
_char_type_ radix_char;
|
||||||
|
|
||||||
|
radix = (flagged_radix & _prefix_()_RADIXMASK);
|
||||||
|
radix_char = (flagged_radix & _prefix_()_LOWERCASE)? 'a': 'A';
|
||||||
|
if (radix < 2 || radix > 36 || size <= 0) return 0;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
hio_uint8_t digit = byte % radix;
|
||||||
|
if (digit < 10) *p++ = digit + '0';
|
||||||
|
else *p++ = digit + radix_char - 10;
|
||||||
|
byte /= radix;
|
||||||
|
}
|
||||||
|
while (byte > 0);
|
||||||
|
|
||||||
|
if (fill != '\0')
|
||||||
|
{
|
||||||
|
while (size - 1 > p - tmp)
|
||||||
|
{
|
||||||
|
*bp++ = fill;
|
||||||
|
size--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (p > tmp && bp < be) *bp++ = *--p;
|
||||||
|
*bp = '\0';
|
||||||
|
return bp - buf;
|
||||||
|
}
|
||||||
|
popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_cs_type_]])popdef([[_prefix_]])dnl
|
||||||
|
dnl ---------------------------------------------------------------------------
|
||||||
|
]])dnl
|
||||||
|
define([[fn_int_to_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)pushdef([[_int_type_]], $3)pushdef([[_count_cstr_]], $4)dnl
|
||||||
|
hio_oow_t _fn_name_ (_int_type_ value, int radix, const _char_type_* prefix, _char_type_* buf, hio_oow_t size)
|
||||||
|
{
|
||||||
|
_int_type_ t, rem;
|
||||||
|
hio_oow_t len, ret, i;
|
||||||
|
hio_oow_t prefix_len;
|
||||||
|
|
||||||
|
prefix_len = (prefix != HIO_NULL)? _count_cstr_()(prefix): 0;
|
||||||
|
|
||||||
|
t = value;
|
||||||
|
if (t == 0)
|
||||||
|
{
|
||||||
|
/* zero */
|
||||||
|
if (buf == HIO_NULL)
|
||||||
|
{
|
||||||
|
/* if buf is not given,
|
||||||
|
* return the number of bytes required */
|
||||||
|
return prefix_len + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size < prefix_len+1)
|
||||||
|
{
|
||||||
|
/* buffer too small */
|
||||||
|
return (hio_oow_t)-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < prefix_len; i++) buf[i] = prefix[i];
|
||||||
|
buf[prefix_len] = '0';
|
||||||
|
if (size > prefix_len+1) buf[prefix_len+1] = '\0';
|
||||||
|
return prefix_len+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* non-zero values */
|
||||||
|
len = prefix_len;
|
||||||
|
if (t < 0) { t = -t; len++; }
|
||||||
|
while (t > 0) { len++; t /= radix; }
|
||||||
|
|
||||||
|
if (buf == HIO_NULL)
|
||||||
|
{
|
||||||
|
/* if buf is not given, return the number of bytes required */
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size < len) return (hio_oow_t)-1; /* buffer too small */
|
||||||
|
if (size > len) buf[len] = '\0';
|
||||||
|
ret = len;
|
||||||
|
|
||||||
|
t = value;
|
||||||
|
if (t < 0) t = -t;
|
||||||
|
|
||||||
|
while (t > 0)
|
||||||
|
{
|
||||||
|
rem = t % radix;
|
||||||
|
if (rem >= 10)
|
||||||
|
buf[--len] = (_char_type_)rem + 'a' - 10;
|
||||||
|
else
|
||||||
|
buf[--len] = (_char_type_)rem + '0';
|
||||||
|
t /= radix;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value < 0)
|
||||||
|
{
|
||||||
|
for (i = 1; i <= prefix_len; i++)
|
||||||
|
{
|
||||||
|
buf[i] = prefix[i-1];
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
buf[--len] = '-';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = 0; i < prefix_len; i++) buf[i] = prefix[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
popdef([[_fn_name_]])popdef([[_char_type_]])popdef([[_int_type_]])popdef([[_count_cstr_]])dnl
|
||||||
|
]])dnl
|
||||||
dnl ---------------------------------------------------------------------------
|
dnl ---------------------------------------------------------------------------
|
||||||
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
|
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)
|
||||||
@ -989,13 +1293,11 @@ _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _
|
|||||||
}
|
}
|
||||||
else if (rem >= 2 && base == 16)
|
else if (rem >= 2 && base == 16)
|
||||||
{
|
{
|
||||||
if (*p == '0' &&
|
if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
||||||
(*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
|
||||||
}
|
}
|
||||||
else if (rem >= 2 && base == 2)
|
else if (rem >= 2 && base == 2)
|
||||||
{
|
{
|
||||||
if (*p == '0' &&
|
if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
||||||
(*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* process the digits */
|
/* process the digits */
|
||||||
@ -1102,13 +1404,11 @@ _int_type_ _fn_name_ (const _char_type_* str, hio_oow_t len, int option, const _
|
|||||||
}
|
}
|
||||||
else if (rem >= 2 && base == 16)
|
else if (rem >= 2 && base == 16)
|
||||||
{
|
{
|
||||||
if (*p == '0' &&
|
if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
||||||
(*(p + 1) == 'x' || *(p + 1) == 'X')) p += 2;
|
|
||||||
}
|
}
|
||||||
else if (rem >= 2 && base == 2)
|
else if (rem >= 2 && base == 2)
|
||||||
{
|
{
|
||||||
if (*p == '0' &&
|
if (*p == '0' && (*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
||||||
(*(p + 1) == 'b' || *(p + 1) == 'B')) p += 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* process the digits */
|
/* process the digits */
|
||||||
|
@ -180,76 +180,6 @@ const hio_uch_t* hio_find_ucstr_word_in_ucstr (const hio_uch_t* str, const hio_u
|
|||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
|
|
||||||
hio_oow_t hio_byte_to_ucstr (hio_oob_t byte, hio_uch_t* buf, hio_oow_t size, int flagged_radix, hio_uch_t fill)
|
|
||||||
{
|
|
||||||
hio_uch_t tmp[(HIO_SIZEOF(hio_oob_t) * HIO_BITS_PER_BYTE)];
|
|
||||||
hio_uch_t* p = tmp, * bp = buf, * be = buf + size - 1;
|
|
||||||
int radix;
|
|
||||||
hio_uch_t radix_char;
|
|
||||||
|
|
||||||
radix = (flagged_radix & HIO_BYTE_TO_UCSTR_RADIXMASK);
|
|
||||||
radix_char = (flagged_radix & HIO_BYTE_TO_UCSTR_LOWERCASE)? 'a': 'A';
|
|
||||||
if (radix < 2 || radix > 36 || size <= 0) return 0;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
hio_uint8_t digit = byte % radix;
|
|
||||||
if (digit < 10) *p++ = digit + '0';
|
|
||||||
else *p++ = digit + radix_char - 10;
|
|
||||||
byte /= radix;
|
|
||||||
}
|
|
||||||
while (byte > 0);
|
|
||||||
|
|
||||||
if (fill != '\0')
|
|
||||||
{
|
|
||||||
while (size - 1 > p - tmp)
|
|
||||||
{
|
|
||||||
*bp++ = fill;
|
|
||||||
size--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (p > tmp && bp < be) *bp++ = *--p;
|
|
||||||
*bp = '\0';
|
|
||||||
return bp - buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
hio_oow_t hio_byte_to_bcstr (hio_uint8_t byte, hio_bch_t* buf, hio_oow_t size, int flagged_radix, hio_bch_t fill)
|
|
||||||
{
|
|
||||||
hio_bch_t tmp[(HIO_SIZEOF(hio_uint8_t) * HIO_BITS_PER_BYTE)];
|
|
||||||
hio_bch_t* p = tmp, * bp = buf, * be = buf + size - 1;
|
|
||||||
int radix;
|
|
||||||
hio_bch_t radix_char;
|
|
||||||
|
|
||||||
radix = (flagged_radix & HIO_BYTE_TO_BCSTR_RADIXMASK);
|
|
||||||
radix_char = (flagged_radix & HIO_BYTE_TO_BCSTR_LOWERCASE)? 'a': 'A';
|
|
||||||
if (radix < 2 || radix > 36 || size <= 0) return 0;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
hio_uint8_t digit = byte % radix;
|
|
||||||
if (digit < 10) *p++ = digit + '0';
|
|
||||||
else *p++ = digit + radix_char - 10;
|
|
||||||
byte /= radix;
|
|
||||||
}
|
|
||||||
while (byte > 0);
|
|
||||||
|
|
||||||
if (fill != '\0')
|
|
||||||
{
|
|
||||||
while (size - 1 > p - tmp)
|
|
||||||
{
|
|
||||||
*bp++ = fill;
|
|
||||||
size--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (p > tmp && bp < be) *bp++ = *--p;
|
|
||||||
*bp = '\0';
|
|
||||||
return bp - buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ========================================================================= */
|
|
||||||
|
|
||||||
HIO_INLINE int hio_conv_bchars_to_uchars_with_cmgr (
|
HIO_INLINE int hio_conv_bchars_to_uchars_with_cmgr (
|
||||||
const hio_bch_t* bcs, hio_oow_t* bcslen,
|
const hio_bch_t* bcs, hio_oow_t* bcslen,
|
||||||
hio_uch_t* ucs, hio_oow_t* ucslen, hio_cmgr_t* cmgr, int all)
|
hio_uch_t* ucs, hio_oow_t* ucslen, hio_cmgr_t* cmgr, int all)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user