added hio_byte_to_ucstr(), hio_copy_ucstr_to_uchars(), hio_copy_bcstr_to_bchars()

This commit is contained in:
hyung-hwan 2022-06-11 07:01:21 +00:00
parent 0680e69746
commit 12482d8a34
8 changed files with 155 additions and 11 deletions

View File

@ -13,6 +13,10 @@ EXTRA_DIST = \
utl-str.c.m4 \
utl-str.m4
BUILT_SOURCES = \
hio-utl.h \
utl-str.c
##################################################
# MAIN LIBRARY
##################################################
@ -140,10 +144,9 @@ install-data-hook:
uninstall-hook:
@rm -f "$(DESTDIR)$(includedir)/hio-cfg.h"
$(srcdir)/hio-utl.h: utl-str.m4 hio-utl.h.m4
hio-utl.h: utl-str.m4 hio-utl.h.m4
m4 -I$(srcdir) $(srcdir)/hio-utl.h.m4 > $(srcdir)/hio-utl.h
# do NOT put $(srcdir) before utl-str.c
utl-str.c: utl-str.m4 utl-str.c.m4
m4 -I$(srcdir) $(srcdir)/utl-str.c.m4 > $(srcdir)/utl-str.c

View File

@ -434,6 +434,10 @@ EXTRA_DIST = \
utl-str.c.m4 \
utl-str.m4
BUILT_SOURCES = \
hio-utl.h \
utl-str.c
##################################################
# MAIN LIBRARY
@ -471,7 +475,7 @@ libhio_la_CFLAGS = $(CFLAGS_LIB_COMMON) $(am__append_3)
libhio_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) $(am__append_4)
libhio_la_LIBADD = $(LIBADD_LIB_COMMON) $(SSL_LIBS) $(SOCKET_LIBS) \
$(SENDFILE_LIBS) $(am__append_5) $(am__append_6)
all: hio-cfg.h
all: $(BUILT_SOURCES) hio-cfg.h
$(MAKE) $(AM_MAKEFLAGS) all-am
.SUFFIXES:
@ -1053,13 +1057,15 @@ distdir-am: $(DISTFILES)
fi; \
done
check-am: all-am
check: check-am
check: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) check-am
all-am: Makefile $(LTLIBRARIES) $(HEADERS) hio-cfg.h
installdirs:
for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: install-am
install: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
@ -1089,6 +1095,7 @@ distclean-generic:
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
-test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
clean: clean-am
clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
@ -1246,7 +1253,8 @@ ps-am:
uninstall-am: uninstall-includeHEADERS uninstall-libLTLIBRARIES
@$(NORMAL_INSTALL)
$(MAKE) $(AM_MAKEFLAGS) uninstall-hook
.MAKE: all install-am install-data-am install-strip uninstall-am
.MAKE: all check install install-am install-data-am install-strip \
uninstall-am
.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \
clean-generic clean-libLTLIBRARIES clean-libtool cscopelist-am \
@ -1278,10 +1286,9 @@ install-data-hook:
uninstall-hook:
@rm -f "$(DESTDIR)$(includedir)/hio-cfg.h"
$(srcdir)/hio-utl.h: utl-str.m4 hio-utl.h.m4
hio-utl.h: utl-str.m4 hio-utl.h.m4
m4 -I$(srcdir) $(srcdir)/hio-utl.h.m4 > $(srcdir)/hio-utl.h
# do NOT put $(srcdir) before utl-str.c
utl-str.c: utl-str.m4 utl-str.c.m4
m4 -I$(srcdir) $(srcdir)/utl-str.c.m4 > $(srcdir)/utl-str.c

View File

@ -412,6 +412,18 @@ HIO_EXPORT hio_oow_t hio_copy_bchars_to_bcstr_unlimited (
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,
@ -647,6 +659,17 @@ HIO_EXPORT hio_oow_t hio_byte_to_bcstr (
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)

View File

@ -413,6 +413,18 @@ HIO_EXPORT hio_oow_t hio_copy_bchars_to_bcstr_unlimited (
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,
@ -648,6 +660,17 @@ HIO_EXPORT hio_oow_t hio_byte_to_bcstr (
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)

View File

@ -417,6 +417,38 @@ hio_oow_t hio_copy_bchars_to_bcstr_unlimited (hio_bch_t* dst, const hio_bch_t* s
return i;
}
hio_oow_t hio_copy_ucstr_to_uchars (hio_uch_t* dst, hio_oow_t len, const hio_uch_t* src)
{
/* no null termination */
hio_uch_t* p, * p2;
p = dst; p2 = dst + len - 1;
while (p < p2)
{
if (*src == '\0') break;
*p++ = *src++;
}
return p - dst;
}
hio_oow_t hio_copy_bcstr_to_bchars (hio_bch_t* dst, hio_oow_t len, const hio_bch_t* src)
{
/* no null termination */
hio_bch_t* p, * p2;
p = dst; p2 = dst + len - 1;
while (p < p2)
{
if (*src == '\0') break;
*p++ = *src++;
}
return p - dst;
}
hio_oow_t hio_copy_ucstr (hio_uch_t* dst, hio_oow_t len, const hio_uch_t* src)
{
hio_uch_t* p, * p2;

View File

@ -63,6 +63,9 @@ dnl --
fn_copy_chars_to_cstr_unlimited(hio_copy_uchars_to_ucstr_unlimited, hio_uch_t)
fn_copy_chars_to_cstr_unlimited(hio_copy_bchars_to_bcstr_unlimited, hio_bch_t)
dnl --
fn_copy_cstr_to_chars(hio_copy_ucstr_to_uchars, hio_uch_t)
fn_copy_cstr_to_chars(hio_copy_bcstr_to_bchars, hio_bch_t)
dnl --
fn_copy_cstr(hio_copy_ucstr, hio_uch_t)
fn_copy_cstr(hio_copy_bcstr, hio_bch_t)
dnl --

View File

@ -221,6 +221,25 @@ hio_oow_t _fn_name_ (_char_type_* dst, const _char_type_* src, hio_oow_t len)
popdef([[_fn_name_]])popdef([[_char_type_]])dnl
]])dnl
dnl ---------------------------------------------------------------------------
define([[fn_copy_cstr_to_chars]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
hio_oow_t _fn_name_ (_char_type_* dst, hio_oow_t len, const _char_type_* src)
{
/* no null termination */
_char_type_* p, * p2;
p = dst; p2 = dst + len - 1;
while (p < p2)
{
if (*src == '\0') break;
*p++ = *src++;
}
return p - dst;
}
popdef([[_fn_name_]])popdef([[_char_type_]])dnl
]])dnl
dnl ---------------------------------------------------------------------------
define([[fn_copy_cstr]], [[pushdef([[_fn_name_]], $1)pushdef([[_char_type_]], $2)dnl
hio_oow_t _fn_name_ (_char_type_* dst, hio_oow_t len, const _char_type_* src)
{

View File

@ -180,6 +180,40 @@ 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)];