reorganized some string functions

This commit is contained in:
hyung-hwan 2022-06-13 14:32:41 +00:00
parent 34d52e208b
commit 46d84e7922
9 changed files with 3181 additions and 760 deletions

View File

@ -31,6 +31,15 @@ CPPFLAGS_PFMOD += -DHAWK_DEFAULT_MODPOSTFIX=\".so\"
endif endif
endif endif
EXTRA_DIST = \
hawk-str.h.m4 \
utl-str.c.m4 \
utl-str.m4
BUILT_SOURCES = \
hawk-str.h \
utl-str.c
################################################## ##################################################
# include files to deploy # include files to deploy
################################################## ##################################################
@ -283,3 +292,11 @@ install-data-hook:
uninstall-hook: uninstall-hook:
@rm -f "$(DESTDIR)$(pkgincludedir)/hawk-cfg.h" @rm -f "$(DESTDIR)$(pkgincludedir)/hawk-cfg.h"
hawk-str.h: utl-str.m4 hawk-str.h.m4
m4 -I$(srcdir) $(srcdir)/hawk-str.h.m4 > $(srcdir)/hawk-str.h
utl-str.c: utl-str.m4 utl-str.c.m4
m4 -I$(srcdir) $(srcdir)/utl-str.c.m4 > $(srcdir)/utl-str.c

View File

@ -602,6 +602,15 @@ CXXFLAGS_ALL_COMMON =
@WIN32_TRUE@ -DHAWK_DEFAULT_MODPREFIX=\"libhawk-\" \ @WIN32_TRUE@ -DHAWK_DEFAULT_MODPREFIX=\"libhawk-\" \
@WIN32_TRUE@ -DHAWK_DEFAULT_MODPOSTFIX=\"-1.dll\" \ @WIN32_TRUE@ -DHAWK_DEFAULT_MODPOSTFIX=\"-1.dll\" \
@WIN32_TRUE@ $(am__append_1) $(am__append_2) @WIN32_TRUE@ $(am__append_1) $(am__append_2)
EXTRA_DIST = \
hawk-str.h.m4 \
utl-str.c.m4 \
utl-str.m4
BUILT_SOURCES = \
hawk-str.h \
utl-str.c
pkginclude_HEADERS = hawk.h hawk-arr.h hawk-chr.h hawk-cmn.h \ pkginclude_HEADERS = hawk.h hawk-arr.h hawk-chr.h hawk-cmn.h \
hawk-dir.h hawk-ecs.h hawk-fmt.h hawk-gem.h hawk-htb.h \ hawk-dir.h hawk-ecs.h hawk-fmt.h hawk-gem.h hawk-htb.h \
hawk-map.h hawk-rbt.h hawk-pac1.h hawk-skad.h hawk-utl.h \ hawk-map.h hawk-rbt.h hawk-pac1.h hawk-skad.h hawk-utl.h \
@ -675,7 +684,7 @@ libhawk_la_LIBADD = $(LIBM) $(SOCKET_LIBS) $(am__append_4) \
@ENABLE_STATIC_MODULE_FALSE@libhawk_sys_la_CXXFLAGS = $(CXXFLAGS_MOD_COMMON) @ENABLE_STATIC_MODULE_FALSE@libhawk_sys_la_CXXFLAGS = $(CXXFLAGS_MOD_COMMON)
@ENABLE_STATIC_MODULE_FALSE@libhawk_sys_la_LDFLAGS = $(LDFLAGS_MOD_COMMON) @ENABLE_STATIC_MODULE_FALSE@libhawk_sys_la_LDFLAGS = $(LDFLAGS_MOD_COMMON)
@ENABLE_STATIC_MODULE_FALSE@libhawk_sys_la_LIBADD = $(LIBADD_MOD_COMMON) $(SOCKET_LIBS) @ENABLE_STATIC_MODULE_FALSE@libhawk_sys_la_LIBADD = $(LIBADD_MOD_COMMON) $(SOCKET_LIBS)
all: hawk-cfg.h all: $(BUILT_SOURCES) hawk-cfg.h
$(MAKE) $(AM_MAKEFLAGS) all-am $(MAKE) $(AM_MAKEFLAGS) all-am
.SUFFIXES: .SUFFIXES:
@ -1453,13 +1462,15 @@ distdir-am: $(DISTFILES)
fi; \ fi; \
done done
check-am: all-am check-am: all-am
check: check-am check: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) check-am
all-am: Makefile $(LTLIBRARIES) $(HEADERS) hawk-cfg.h all-am: Makefile $(LTLIBRARIES) $(HEADERS) hawk-cfg.h
installdirs: installdirs:
for dir in "$(DESTDIR)$(pkglibdir)" "$(DESTDIR)$(pkgincludedir)"; do \ for dir in "$(DESTDIR)$(pkglibdir)" "$(DESTDIR)$(pkgincludedir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done done
install: install-am install: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) install-am
install-exec: install-exec-am install-exec: install-exec-am
install-data: install-data-am install-data: install-data-am
uninstall: uninstall-am uninstall: uninstall-am
@ -1489,6 +1500,7 @@ distclean-generic:
maintainer-clean-generic: maintainer-clean-generic:
@echo "This command is intended for maintainers to use" @echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild." @echo "it deletes files that may require special tools to rebuild."
-test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
clean: clean-am clean: clean-am
clean-am: clean-generic clean-libtool clean-pkglibLTLIBRARIES \ clean-am: clean-generic clean-libtool clean-pkglibLTLIBRARIES \
@ -1686,7 +1698,8 @@ ps-am:
uninstall-am: uninstall-pkgincludeHEADERS uninstall-pkglibLTLIBRARIES uninstall-am: uninstall-pkgincludeHEADERS uninstall-pkglibLTLIBRARIES
@$(NORMAL_INSTALL) @$(NORMAL_INSTALL)
$(MAKE) $(AM_MAKEFLAGS) uninstall-hook $(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 \ .PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \
clean-generic clean-libtool clean-pkglibLTLIBRARIES \ clean-generic clean-libtool clean-pkglibLTLIBRARIES \
@ -1722,6 +1735,12 @@ install-data-hook:
uninstall-hook: uninstall-hook:
@rm -f "$(DESTDIR)$(pkgincludedir)/hawk-cfg.h" @rm -f "$(DESTDIR)$(pkgincludedir)/hawk-cfg.h"
hawk-str.h: utl-str.m4 hawk-str.h.m4
m4 -I$(srcdir) $(srcdir)/hawk-str.h.m4 > $(srcdir)/hawk-str.h
utl-str.c: utl-str.m4 utl-str.c.m4
m4 -I$(srcdir) $(srcdir)/utl-str.c.m4 > $(srcdir)/utl-str.c
# Tell versions [3.59,3.63) of GNU make to not export all variables. # Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded. # Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT: .NOEXPORT:

View File

@ -482,7 +482,7 @@ void hawk_gem_seterror (hawk_gem_t* gem, const hawk_loc_t* errloc, hawk_errnum_t
errfmt = gem->errstr(gem->errnum); errfmt = gem->errstr(gem->errnum);
HAWK_ASSERT (errfmt != HAWK_NULL); HAWK_ASSERT (errfmt != HAWK_NULL);
hawk_copy_oofcs_to_oochars (gem->errmsg, HAWK_COUNTOF(gem->errmsg), errfmt, errarg); hawk_copy_fmt_oocses_to_oocstr (gem->errmsg, HAWK_COUNTOF(gem->errmsg), errfmt, errarg);
if (errloc != HAWK_NULL) gem->errloc = *errloc; if (errloc != HAWK_NULL) gem->errloc = *errloc;
else HAWK_MEMSET (&gem->errloc, 0, HAWK_SIZEOF(gem->errloc)); else HAWK_MEMSET (&gem->errloc, 0, HAWK_SIZEOF(gem->errloc));

733
hawk/lib/hawk-str.h.m4 Normal file
View File

@ -0,0 +1,733 @@
/*
Copyright (c) 2006-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 hawk-str.h. Edit hawk-str.h.m4 instead.
*
* Generate hawk-str.h.m4 with m4
* $ m4 hawk-str.h.m4 > hawk-str.h
*/
#ifndef _HAWK_STR_H_
#define _HAWK_STR_H_
#include <hawk-cmn.h>
dnl ---------------------------------------------------------------------------
dnl include utl-str.m4 for c++ template functions far below
include(`utl-str.m4')
dnl ---------------------------------------------------------------------------
/* =========================================================================
* STRING
* ========================================================================= */
enum hawk_trim_oochars_flag_t
{
HAWK_TRIM_OOCHARS_LEFT = (1 << 0), /**< trim leading spaces */
#define HAWK_TRIM_OOCHARS_LEFT HAWK_TRIM_OOCHARS_LEFT
#define HAWK_TRIM_UCHARS_LEFT HAWK_TRIM_OOCHARS_LEFT
#define HAWK_TRIM_BCHARS_LEFT HAWK_TRIM_OOCHARS_LEFT
HAWK_TRIM_OOCHARS_RIGHT = (1 << 1) /**< trim trailing spaces */
#define HAWK_TRIM_OOCHARS_RIGHT HAWK_TRIM_OOCHARS_RIGHT
#define HAWK_TRIM_UCHARS_RIGHT HAWK_TRIM_OOCHARS_RIGHT
#define HAWK_TRIM_BCHARS_RIGHT HAWK_TRIM_OOCHARS_RIGHT
};
#if defined(__cplusplus)
extern "C" {
#endif
/* ------------------------------------ */
HAWK_EXPORT int hawk_comp_uchars (
const hawk_uch_t* str1,
hawk_oow_t len1,
const hawk_uch_t* str2,
hawk_oow_t len2,
int ignorecase
);
HAWK_EXPORT int hawk_comp_bchars (
const hawk_bch_t* str1,
hawk_oow_t len1,
const hawk_bch_t* str2,
hawk_oow_t len2,
int ignorecase
);
HAWK_EXPORT int hawk_comp_ucstr (
const hawk_uch_t* str1,
const hawk_uch_t* str2,
int ignorecase
);
HAWK_EXPORT int hawk_comp_bcstr (
const hawk_bch_t* str1,
const hawk_bch_t* str2,
int ignorecase
);
HAWK_EXPORT int hawk_comp_ucstr_limited (
const hawk_uch_t* str1,
const hawk_uch_t* str2,
hawk_oow_t maxlen,
int ignorecase
);
HAWK_EXPORT int hawk_comp_bcstr_limited (
const hawk_bch_t* str1,
const hawk_bch_t* str2,
hawk_oow_t maxlen,
int ignorecase
);
HAWK_EXPORT int hawk_comp_uchars_ucstr (
const hawk_uch_t* str1,
hawk_oow_t len,
const hawk_uch_t* str2,
int ignorecase
);
HAWK_EXPORT int hawk_comp_bchars_bcstr (
const hawk_bch_t* str1,
hawk_oow_t len,
const hawk_bch_t* str2,
int ignorecase
);
/* ------------------------------------ */
HAWK_EXPORT hawk_oow_t hawk_concat_uchars_to_ucstr (
hawk_uch_t* buf,
hawk_oow_t bsz,
const hawk_uch_t* src,
hawk_oow_t len
);
HAWK_EXPORT hawk_oow_t hawk_concat_bchars_to_bcstr (
hawk_bch_t* buf,
hawk_oow_t bsz,
const hawk_bch_t* src,
hawk_oow_t len
);
HAWK_EXPORT hawk_oow_t hawk_concat_ucstr (
hawk_uch_t* buf,
hawk_oow_t bsz,
const hawk_uch_t* src
);
HAWK_EXPORT hawk_oow_t hawk_concat_bcstr (
hawk_bch_t* buf,
hawk_oow_t bsz,
const hawk_bch_t* src
);
/* ------------------------------------ */
HAWK_EXPORT void hawk_copy_uchars (
hawk_uch_t* dst,
const hawk_uch_t* src,
hawk_oow_t len
);
HAWK_EXPORT void hawk_copy_bchars (
hawk_bch_t* dst,
const hawk_bch_t* src,
hawk_oow_t len
);
HAWK_EXPORT void hawk_copy_bchars_to_uchars (
hawk_uch_t* dst,
const hawk_bch_t* src,
hawk_oow_t len
);
HAWK_EXPORT void hawk_copy_uchars_to_bchars (
hawk_bch_t* dst,
const hawk_uch_t* src,
hawk_oow_t len
);
HAWK_EXPORT hawk_oow_t hawk_copy_uchars_to_ucstr (
hawk_uch_t* dst,
hawk_oow_t dlen,
const hawk_uch_t* src,
hawk_oow_t slen
);
HAWK_EXPORT hawk_oow_t hawk_copy_bchars_to_bcstr (
hawk_bch_t* dst,
hawk_oow_t dlen,
const hawk_bch_t* src,
hawk_oow_t slen
);
HAWK_EXPORT hawk_oow_t hawk_copy_uchars_to_ucstr_unlimited (
hawk_uch_t* dst,
const hawk_uch_t* src,
hawk_oow_t len
);
HAWK_EXPORT hawk_oow_t hawk_copy_bchars_to_bcstr_unlimited (
hawk_bch_t* dst,
const hawk_bch_t* src,
hawk_oow_t len
);
HAWK_EXPORT hawk_oow_t hawk_copy_ucstr_to_uchars (
hawk_uch_t* dst,
hawk_oow_t dlen,
const hawk_uch_t* src
);
HAWK_EXPORT hawk_oow_t hawk_copy_bcstr_to_bchars (
hawk_bch_t* dst,
hawk_oow_t dlen,
const hawk_bch_t* src
);
HAWK_EXPORT hawk_oow_t hawk_copy_ucstr (
hawk_uch_t* dst,
hawk_oow_t len,
const hawk_uch_t* src
);
HAWK_EXPORT hawk_oow_t hawk_copy_bcstr (
hawk_bch_t* dst,
hawk_oow_t len,
const hawk_bch_t* src
);
HAWK_EXPORT hawk_oow_t hawk_copy_ucstr_unlimited (
hawk_uch_t* dst,
const hawk_uch_t* src
);
HAWK_EXPORT hawk_oow_t hawk_copy_bcstr_unlimited (
hawk_bch_t* dst,
const hawk_bch_t* src
);
HAWK_EXPORT hawk_oow_t hawk_copy_fmt_ucstrs_to_ucstr (
hawk_uch_t* buf,
hawk_oow_t bsz,
const hawk_uch_t* fmt,
const hawk_uch_t* str[]
);
HAWK_EXPORT hawk_oow_t hawk_copy_fmt_bcstrs_to_bcstr (
hawk_bch_t* buf,
hawk_oow_t bsz,
const hawk_bch_t* fmt,
const hawk_bch_t* str[]
);
HAWK_EXPORT hawk_oow_t hawk_copy_fmt_ucses_to_ucstr (
hawk_uch_t* buf,
hawk_oow_t bsz,
const hawk_uch_t* fmt,
const hawk_ucs_t str[]
);
HAWK_EXPORT hawk_oow_t hawk_copy_fmt_bcses_to_bcstr (
hawk_bch_t* buf,
hawk_oow_t bsz,
const hawk_bch_t* fmt,
const hawk_bcs_t str[]
);
/* ------------------------------------ */
HAWK_EXPORT hawk_oow_t hawk_count_ucstr (
const hawk_uch_t* str
);
HAWK_EXPORT hawk_oow_t hawk_count_bcstr (
const hawk_bch_t* str
);
HAWK_EXPORT hawk_oow_t hawk_count_ucstr_limited (
const hawk_uch_t* str,
hawk_oow_t maxlen
);
HAWK_EXPORT hawk_oow_t hawk_count_bcstr_limited (
const hawk_bch_t* str,
hawk_oow_t maxlen
);
/* ------------------------------------ */
/**
* The hawk_equal_uchars() function determines equality of two strings
* of the same length \a len.
*/
HAWK_EXPORT int hawk_equal_uchars (
const hawk_uch_t* str1,
const hawk_uch_t* str2,
hawk_oow_t len
);
HAWK_EXPORT int hawk_equal_bchars (
const hawk_bch_t* str1,
const hawk_bch_t* str2,
hawk_oow_t len
);
/* ------------------------------------ */
HAWK_EXPORT void hawk_fill_uchars (
hawk_uch_t* dst,
const hawk_uch_t ch,
hawk_oow_t len
);
HAWK_EXPORT void hawk_fill_bchars (
hawk_bch_t* dst,
const hawk_bch_t ch,
hawk_oow_t len
);
/* ------------------------------------ */
HAWK_EXPORT const hawk_bch_t* hawk_find_bcstr_word_in_bcstr (
const hawk_bch_t* str,
const hawk_bch_t* word,
hawk_bch_t extra_delim,
int ignorecase
);
HAWK_EXPORT const hawk_uch_t* hawk_find_ucstr_word_in_ucstr (
const hawk_uch_t* str,
const hawk_uch_t* word,
hawk_uch_t extra_delim,
int ignorecase
);
HAWK_EXPORT hawk_uch_t* hawk_find_uchar_in_uchars (
const hawk_uch_t* ptr,
hawk_oow_t len,
hawk_uch_t c
);
HAWK_EXPORT hawk_bch_t* hawk_find_bchar_in_bchars (
const hawk_bch_t* ptr,
hawk_oow_t len,
hawk_bch_t c
);
HAWK_EXPORT hawk_uch_t* hawk_rfind_uchar_in_uchars (
const hawk_uch_t* ptr,
hawk_oow_t len,
hawk_uch_t c
);
HAWK_EXPORT hawk_bch_t* hawk_rfind_bchar_in_bchars (
const hawk_bch_t* ptr,
hawk_oow_t len,
hawk_bch_t c
);
HAWK_EXPORT hawk_uch_t* hawk_find_uchar_in_ucstr (
const hawk_uch_t* ptr,
hawk_uch_t c
);
HAWK_EXPORT hawk_bch_t* hawk_find_bchar_in_bcstr (
const hawk_bch_t* ptr,
hawk_bch_t c
);
HAWK_EXPORT hawk_uch_t* hawk_rfind_uchar_in_ucstr (
const hawk_uch_t* ptr,
hawk_uch_t c
);
HAWK_EXPORT hawk_bch_t* hawk_rfind_bchar_in_bcstr (
const hawk_bch_t* ptr,
hawk_bch_t c
);
HAWK_EXPORT hawk_uch_t* hawk_find_uchars_in_uchars (
const hawk_uch_t* str,
hawk_oow_t strsz,
const hawk_uch_t* sub,
hawk_oow_t subsz,
int inorecase
);
HAWK_EXPORT hawk_bch_t* hawk_find_bchars_in_bchars (
const hawk_bch_t* str,
hawk_oow_t strsz,
const hawk_bch_t* sub,
hawk_oow_t subsz,
int inorecase
);
HAWK_EXPORT hawk_uch_t* hawk_rfind_uchars_in_uchars (
const hawk_uch_t* str,
hawk_oow_t strsz,
const hawk_uch_t* sub,
hawk_oow_t subsz,
int inorecase
);
HAWK_EXPORT hawk_bch_t* hawk_rfind_bchars_in_bchars (
const hawk_bch_t* str,
hawk_oow_t strsz,
const hawk_bch_t* sub,
hawk_oow_t subsz,
int inorecase
);
/* ------------------------------------ */
HAWK_EXPORT hawk_oow_t hawk_compact_uchars (
hawk_uch_t* str,
hawk_oow_t len
);
HAWK_EXPORT hawk_oow_t hawk_compact_bchars (
hawk_bch_t* str,
hawk_oow_t len
);
HAWK_EXPORT hawk_oow_t hawk_rotate_uchars (
hawk_uch_t* str,
hawk_oow_t len,
int dir,
hawk_oow_t n
);
HAWK_EXPORT hawk_oow_t hawk_rotate_bchars (
hawk_bch_t* str,
hawk_oow_t len,
int dir,
hawk_oow_t n
);
HAWK_EXPORT hawk_uch_t* hawk_trim_uchars (
const hawk_uch_t* str,
hawk_oow_t* len,
int flags
);
HAWK_EXPORT hawk_bch_t* hawk_trim_bchars (
const hawk_bch_t* str,
hawk_oow_t* len,
int flags
);
HAWK_EXPORT int hawk_split_ucstr (
hawk_uch_t* s,
const hawk_uch_t* delim,
hawk_uch_t lquote,
hawk_uch_t rquote,
hawk_uch_t escape
);
HAWK_EXPORT int hawk_split_bcstr (
hawk_bch_t* s,
const hawk_bch_t* delim,
hawk_bch_t lquote,
hawk_bch_t rquote,
hawk_bch_t escape
);
#if defined(HAWK_OOCH_IS_UCH)
# define hawk_count_oocstr hawk_count_ucstr
# define hawk_count_oocstr_limited hawk_count_ucstr_limited
# define hawk_equal_oochars hawk_equal_uchars
# define hawk_comp_oochars hawk_comp_uchars
# define hawk_comp_oocstr_bcstr hawk_comp_ucstr_bcstr
# define hawk_comp_oochars_bcstr hawk_comp_uchars_bcstr
# define hawk_comp_oochars_ucstr hawk_comp_uchars_ucstr
# define hawk_comp_oochars_oocstr hawk_comp_uchars_ucstr
# define hawk_comp_oocstr hawk_comp_ucstr
# define hawk_comp_oocstr_limited hawk_comp_ucstr_limited
# define hawk_copy_oochars hawk_copy_uchars
# define hawk_copy_bchars_to_oochars hawk_copy_bchars_to_uchars
# define hawk_copy_oochars_to_bchars hawk_copy_uchars_to_bchars
# define hawk_copy_uchars_to_oochars hawk_copy_uchars
# define hawk_copy_oochars_to_uchars hawk_copy_uchars
# define hawk_copy_oochars_to_oocstr hawk_copy_uchars_to_ucstr
# define hawk_copy_oochars_to_oocstr_unlimited hawk_copy_uchars_to_ucstr_unlimited
# define hawk_copy_oocstr hawk_copy_ucstr
# define hawk_copy_oocstr_unlimited hawk_copy_ucstr_unlimited
# define hawk_copy_fmt_oocses_to_oocstr hawk_copy_fmt_ucses_to_ucstr
# define hawk_copy_fmt_oocstr_to_oocstr hawk_copy_fmt_ucstr_to_ucstr
# define hawk_concat_oochars_to_ucstr hawk_concat_uchars_to_ucstr
# define hawk_concat_oocstr hawk_concat_ucstr
# define hawk_fill_oochars hawk_fill_uchars
# define hawk_find_oocstr_word_in_oocstr hawk_find_ucstr_word_in_ucstr
# define hawk_find_oochar_in_oochars hawk_find_uchar_in_uchars
# define hawk_rfind_oochar_in_oochars hawk_rfind_uchar_in_uchars
# define hawk_find_oochar_in_oocstr hawk_find_uchar_in_ucstr
# define hawk_find_oochars_in_oochars hawk_find_uchars_in_uchars
# define hawk_rfind_oochars_in_oochars hawk_rfind_uchars_in_uchars
# define hawk_compact_oochars hawk_compact_uchars
# define hawk_rotate_oochars hawk_rotate_uchars
# define hawk_trim_oochars hawk_trim_uchars
# define hawk_split_oocstr hawk_split_ucstr
#else
# define hawk_count_oocstr hawk_count_bcstr
# define hawk_count_oocstr_limited hawk_count_bcstr_limited
# define hawk_equal_oochars hawk_equal_bchars
# define hawk_comp_oochars hawk_comp_bchars
# define hawk_comp_oocstr_bcstr hawk_comp_bcstr
# define hawk_comp_oochars_bcstr hawk_comp_bchars_bcstr
# define hawk_comp_oochars_ucstr hawk_comp_bchars_ucstr
# define hawk_comp_oochars_oocstr hawk_comp_bchars_bcstr
# define hawk_comp_oocstr hawk_comp_bcstr
# define hawk_comp_oocstr_limited hawk_comp_bcstr_limited
# define hawk_copy_oochars hawk_copy_bchars
# define hawk_copy_bchars_to_oochars hawk_copy_bchars
# define hawk_copy_oochars_to_bchars hawk_copy_bchars
# define hawk_copy_uchars_to_oochars hawk_copy_uchars_to_bchars
# define hawk_copy_oochars_to_uchars hawk_copy_bchars_to_uchars
# define hawk_copy_oochars_to_oocstr hawk_copy_bchars_to_bcstr
# define hawk_copy_oochars_to_oocstr_unlimited hawk_copy_bchars_to_bcstr_unlimited
# define hawk_copy_oocstr hawk_copy_bcstr
# define hawk_copy_oocstr_unlimited hawk_copy_bcstr_unlimited
# define hawk_copy_fmt_oocses_to_oocstr hawk_copy_fmt_bcses_to_bcstr
# define hawk_copy_fmt_oocstr_to_oocstr hawk_copy_fmt_bcstr_to_bcstr
# define hawk_concat_oochars_to_bcstr hawk_concat_bchars_to_bcstr
# define hawk_concat_oocstr hawk_concat_bcstr
# define hawk_fill_oochars hawk_fill_bchars
# define hawk_find_oocstr_word_in_oocstr hawk_find_bcstr_word_in_bcstr
# define hawk_find_oochar_in_oochars hawk_find_bchar_in_bchars
# define hawk_rfind_oochar_in_oochars hawk_rfind_bchar_in_bchars
# define hawk_find_oochar_in_oocstr hawk_find_bchar_in_bcstr
# define hawk_find_oochars_in_oochars hawk_find_bchars_in_bchars
# define hawk_rfind_oochars_in_oochars hawk_rfind_bchars_in_bchars
# define hawk_compact_oochars hawk_compact_uchars
# define hawk_rotate_oochars hawk_rotate_uchars
# define hawk_trim_oochars hawk_trim_bchars
# define hawk_split_oocstr hawk_split_bcstr
#endif
/* ------------------------------------------------------------------------- */
#define HAWK_BYTE_TO_OOCSTR_RADIXMASK (0xFF)
#define HAWK_BYTE_TO_OOCSTR_LOWERCASE (1 << 8)
#define HAWK_BYTE_TO_UCSTR_RADIXMASK HAWK_BYTE_TO_OOCSTR_RADIXMASK
#define HAWK_BYTE_TO_UCSTR_LOWERCASE HAWK_BYTE_TO_OOCSTR_LOWERCASE
#define HAWK_BYTE_TO_BCSTR_RADIXMASK HAWK_BYTE_TO_OOCSTR_RADIXMASK
#define HAWK_BYTE_TO_BCSTR_LOWERCASE HAWK_BYTE_TO_OOCSTR_LOWERCASE
HAWK_EXPORT hawk_oow_t hawk_byte_to_bcstr (
hawk_uint8_t byte,
hawk_bch_t* buf,
hawk_oow_t size,
int flagged_radix,
hawk_bch_t fill
);
HAWK_EXPORT hawk_oow_t hawk_byte_to_ucstr (
hawk_uint8_t byte,
hawk_uch_t* buf,
hawk_oow_t size,
int flagged_radix,
hawk_uch_t fill
);
#if defined(HAWK_OOCH_IS_UCH)
# define hawk_byte_to_oocstr hawk_byte_to_ucstr
#else
# define hawk_byte_to_oocstr hawk_byte_to_bcstr
#endif
/* ------------------------------------------------------------------------- */
HAWK_EXPORT hawk_oow_t hawk_int_to_ucstr (
hawk_int_t value,
int radix,
const hawk_uch_t* prefix,
hawk_uch_t* buf,
hawk_oow_t size
);
HAWK_EXPORT hawk_oow_t hawk_int_to_bcstr (
hawk_int_t value,
int radix,
const hawk_bch_t* prefix,
hawk_bch_t* buf,
hawk_oow_t size
);
HAWK_EXPORT hawk_oow_t hawk_uint_to_ucstr (
hawk_uint_t value,
int radix,
const hawk_uch_t* prefix,
hawk_uch_t* buf,
hawk_oow_t size
);
HAWK_EXPORT hawk_oow_t hawk_uint_to_bcstr (
hawk_uint_t value,
int radix,
const hawk_bch_t* prefix,
hawk_bch_t* buf,
hawk_oow_t size
);
#if defined(HAWK_OOCH_IS_UCH)
# define hawk_int_to_oocstr hawk_int_to_ucstr
# define hawk_uint_to_oocstr hawk_uint_to_ucstr
#else
# define hawk_int_to_oocstr hawk_int_to_bcstr
# define hawk_uint_to_oocstr hawk_uint_to_bcstr
#endif
/* ------------------------------------------------------------------------- */
#define HAWK_CHARS_TO_INT_MAKE_OPTION(e,ltrim,rtrim,base) (((!!(e)) << 0) | ((!!(ltrim)) << 2) | ((!!(rtrim)) << 3) | ((base) << 8))
#define HAWK_CHARS_TO_INT_GET_OPTION_E(option) ((option) & 1)
#define HAWK_CHARS_TO_INT_GET_OPTION_LTRIM(option) ((option) & 4)
#define HAWK_CHARS_TO_INT_GET_OPTION_RTRIM(option) ((option) & 8)
#define HAWK_CHARS_TO_INT_GET_OPTION_BASE(option) ((option) >> 8)
#define HAWK_CHARS_TO_UINT_MAKE_OPTION(e,ltrim,rtrim,base) (((!!(e)) << 0) | ((!!(ltrim)) << 2) | ((!!(rtrim)) << 3) | ((base) << 8))
#define HAWK_CHARS_TO_UINT_GET_OPTION_E(option) ((option) & 1)
#define HAWK_CHARS_TO_UINT_GET_OPTION_LTRIM(option) ((option) & 4)
#define HAWK_CHARS_TO_UINT_GET_OPTION_RTRIM(option) ((option) & 8)
#define HAWK_CHARS_TO_UINT_GET_OPTION_BASE(option) ((option) >> 8)
#define HAWK_OOCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HAWK_CHARS_TO_INT_MAKE_OPTION(e,ltrim,rtrim,base)
#define HAWK_OOCHARS_TO_INTMAX_GET_OPTION_E(option) HAWK_CHARS_TO_INT_GET_OPTION_E(option)
#define HAWK_OOCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) HAWK_CHARS_TO_INT_GET_OPTION_LTRIM(option)
#define HAWK_OOCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) HAWK_CHARS_TO_INT_GET_OPTION_RTRIM(option)
#define HAWK_OOCHARS_TO_INTMAX_GET_OPTION_BASE(option) HAWK_CHARS_TO_INT_GET_OPTION_BASE(option)
#define HAWK_OOCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HAWK_CHARS_TO_UINT_MAKE_OPTION(e,ltrim,rtrim,base)
#define HAWK_OOCHARS_TO_UINTMAX_GET_OPTION_E(option) HAWK_CHARS_TO_UINT_GET_OPTION_E(option)
#define HAWK_OOCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) HAWK_CHARS_TO_UINT_GET_OPTION_LTRIM(option)
#define HAWK_OOCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) HAWK_CHARS_TO_UINT_GET_OPTION_RTRIM(option)
#define HAWK_OOCHARS_TO_UINTMAX_GET_OPTION_BASE(option) HAWK_CHARS_TO_UINT_GET_OPTION_BASE(option)
#define HAWK_UCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HAWK_CHARS_TO_INT_MAKE_OPTION(e,ltrim,rtrim,base)
#define HAWK_UCHARS_TO_INTMAX_GET_OPTION_E(option) HAWK_CHARS_TO_INT_GET_OPTION_E(option)
#define HAWK_UCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) HAWK_CHARS_TO_INT_GET_OPTION_LTRIM(option)
#define HAWK_UCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) HAWK_CHARS_TO_INT_GET_OPTION_RTRIM(option)
#define HAWK_UCHARS_TO_INTMAX_GET_OPTION_BASE(option) HAWK_CHARS_TO_INT_GET_OPTION_BASE(option)
#define HAWK_BCHARS_TO_INTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HAWK_CHARS_TO_INT_MAKE_OPTION(e,ltrim,rtrim,base)
#define HAWK_BCHARS_TO_INTMAX_GET_OPTION_E(option) HAWK_CHARS_TO_INT_GET_OPTION_E(option)
#define HAWK_BCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) HAWK_CHARS_TO_INT_GET_OPTION_LTRIM(option)
#define HAWK_BCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) HAWK_CHARS_TO_INT_GET_OPTION_RTRIM(option)
#define HAWK_BCHARS_TO_INTMAX_GET_OPTION_BASE(option) HAWK_CHARS_TO_INT_GET_OPTION_BASE(option)
#define HAWK_UCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HAWK_CHARS_TO_UINT_MAKE_OPTION(e,ltrim,rtrim,base)
#define HAWK_UCHARS_TO_UINTMAX_GET_OPTION_E(option) HAWK_CHARS_TO_UINT_GET_OPTION_E(option)
#define HAWK_UCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) HAWK_CHARS_TO_UINT_GET_OPTION_LTRIM(option)
#define HAWK_UCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) HAWK_CHARS_TO_UINT_GET_OPTION_RTRIM(option)
#define HAWK_UCHARS_TO_UINTMAX_GET_OPTION_BASE(option) HAWK_CHARS_TO_UINT_GET_OPTION_BASE(option)
#define HAWK_BCHARS_TO_UINTMAX_MAKE_OPTION(e,ltrim,rtrim,base) HAWK_CHARS_TO_UINT_MAKE_OPTION(e,ltrim,rtrim,base)
#define HAWK_BCHARS_TO_UINTMAX_GET_OPTION_E(option) HAWK_CHARS_TO_UINT_GET_OPTION_E(option)
#define HAWK_BCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) HAWK_CHARS_TO_UINT_GET_OPTION_LTRIM(option)
#define HAWK_BCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) HAWK_CHARS_TO_UINT_GET_OPTION_RTRIM(option)
#define HAWK_BCHARS_TO_UINTMAX_GET_OPTION_BASE(option) HAWK_CHARS_TO_UINT_GET_OPTION_BASE(option)
HAWK_EXPORT hawk_int_t hawk_uchars_to_int (
const hawk_uch_t* str,
hawk_oow_t len,
int option,
const hawk_uch_t** endptr,
int* is_sober
);
HAWK_EXPORT hawk_int_t hawk_bchars_to_int (
const hawk_bch_t* str,
hawk_oow_t len,
int option,
const hawk_bch_t** endptr,
int* is_sober
);
HAWK_EXPORT hawk_uint_t hawk_uchars_to_uint (
const hawk_uch_t* str,
hawk_oow_t len,
int option,
const hawk_uch_t** endptr,
int* is_sober
);
HAWK_EXPORT hawk_uint_t hawk_bchars_to_uint (
const hawk_bch_t* str,
hawk_oow_t len,
int option,
const hawk_bch_t** endptr,
int* is_sober
);
#if defined(HAWK_OOCH_IS_UCH)
# define hawk_oochars_to_int hawk_uchars_to_int
# define hawk_oochars_to_uint hawk_uchars_to_uint
#else
# define hawk_oochars_to_int hawk_bchars_to_int
# define hawk_oochars_to_uint hawk_bchars_to_uint
#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 = hawk_chars_to_uint<char,unsigned,is_space>("0x12345", 7, 0, NULL, NULL);
unsigned y = hawk_chars_to_uint<wchar_t,unsigned,is_wspace>(L"0x12345", 7, 0, NULL, NULL);
int a = hawk_chars_to_int<char,int,is_space>("-0x12345", 8, 0, NULL, NULL);
int b = hawk_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(hawk_chars_to_int, CHAR_TYPE, INT_TYPE, IS_SPACE, HAWK_CHARS_TO_INT)
template<typename CHAR_TYPE, typename UINT_TYPE, bool(*IS_SPACE)(CHAR_TYPE)>fn_chars_to_uint(hawk_chars_to_uint, CHAR_TYPE, UINT_TYPE, IS_SPACE, HAWK_CHARS_TO_UINT)
#endif
#endif

View File

@ -26,6 +26,7 @@
#define _HAWK_UTL_H_ #define _HAWK_UTL_H_
#include <hawk-cmn.h> #include <hawk-cmn.h>
#include <hawk-str.h>
#include <stdarg.h> #include <stdarg.h>
#define HAWK_EPOCH_YEAR (1970) #define HAWK_EPOCH_YEAR (1970)
@ -233,23 +234,6 @@
#define HAWK_HASH_UCSTR(hv, ptr) HAWK_HASH_VPTR(hv, ptr, const hawk_uch_t) #define HAWK_HASH_UCSTR(hv, ptr) HAWK_HASH_VPTR(hv, ptr, const hawk_uch_t)
#define HAWK_HASH_MORE_UCSTR(hv, ptr) HAWK_HASH_MORE_VPTR(hv, ptr, const hawk_uch_t) #define HAWK_HASH_MORE_UCSTR(hv, ptr) HAWK_HASH_MORE_VPTR(hv, ptr, const hawk_uch_t)
/* =========================================================================
* STRING
* ========================================================================= */
enum hawk_trim_oochars_flag_t
{
HAWK_TRIM_OOCHARS_LEFT = (1 << 0), /**< trim leading spaces */
#define HAWK_TRIM_OOCHARS_LEFT HAWK_TRIM_OOCHARS_LEFT
#define HAWK_TRIM_UCHARS_LEFT HAWK_TRIM_OOCHARS_LEFT
#define HAWK_TRIM_BCHARS_LEFT HAWK_TRIM_OOCHARS_LEFT
HAWK_TRIM_OOCHARS_RIGHT = (1 << 1) /**< trim trailing spaces */
#define HAWK_TRIM_OOCHARS_RIGHT HAWK_TRIM_OOCHARS_RIGHT
#define HAWK_TRIM_UCHARS_RIGHT HAWK_TRIM_OOCHARS_RIGHT
#define HAWK_TRIM_BCHARS_RIGHT HAWK_TRIM_OOCHARS_RIGHT
};
/* ========================================================================= /* =========================================================================
* CMGR * CMGR
* ========================================================================= */ * ========================================================================= */
@ -390,77 +374,12 @@ HAWK_EXPORT hawk_oow_t hawk_hash_bytes_ (
* STRING * STRING
* ========================================================================= */ * ========================================================================= */
/**
* The hawk_equal_uchars() function determines equality of two strings
* of the same length \a len.
*/
HAWK_EXPORT int hawk_equal_uchars (
const hawk_uch_t* str1,
const hawk_uch_t* str2,
hawk_oow_t len
);
HAWK_EXPORT int hawk_equal_bchars (
const hawk_bch_t* str1,
const hawk_bch_t* str2,
hawk_oow_t len
);
HAWK_EXPORT int hawk_comp_uchars (
const hawk_uch_t* str1,
hawk_oow_t len1,
const hawk_uch_t* str2,
hawk_oow_t len2,
int ignorecase
);
HAWK_EXPORT int hawk_comp_bchars (
const hawk_bch_t* str1,
hawk_oow_t len1,
const hawk_bch_t* str2,
hawk_oow_t len2,
int ignorecase
);
HAWK_EXPORT int hawk_comp_ucstr (
const hawk_uch_t* str1,
const hawk_uch_t* str2,
int ignorecase
);
HAWK_EXPORT int hawk_comp_bcstr (
const hawk_bch_t* str1,
const hawk_bch_t* str2,
int ignorecase
);
HAWK_EXPORT int hawk_comp_ucstr_limited (
const hawk_uch_t* str1,
const hawk_uch_t* str2,
hawk_oow_t maxlen,
int ignorecase
);
HAWK_EXPORT int hawk_comp_bcstr_limited (
const hawk_bch_t* str1,
const hawk_bch_t* str2,
hawk_oow_t maxlen,
int ignorecase
);
HAWK_EXPORT int hawk_comp_ucstr_bcstr ( HAWK_EXPORT int hawk_comp_ucstr_bcstr (
const hawk_uch_t* str1, const hawk_uch_t* str1,
const hawk_bch_t* str2, const hawk_bch_t* str2,
int ignorecase int ignorecase
); );
HAWK_EXPORT int hawk_comp_uchars_ucstr (
const hawk_uch_t* str1,
hawk_oow_t len,
const hawk_uch_t* str2,
int ignorecase
);
HAWK_EXPORT int hawk_comp_uchars_bcstr ( HAWK_EXPORT int hawk_comp_uchars_bcstr (
const hawk_uch_t* str1, const hawk_uch_t* str1,
hawk_oow_t len, hawk_oow_t len,
@ -468,13 +387,6 @@ HAWK_EXPORT int hawk_comp_uchars_bcstr (
int ignorecase int ignorecase
); );
HAWK_EXPORT int hawk_comp_bchars_bcstr (
const hawk_bch_t* str1,
hawk_oow_t len,
const hawk_bch_t* str2,
int ignorecase
);
HAWK_EXPORT int hawk_comp_bchars_ucstr ( HAWK_EXPORT int hawk_comp_bchars_ucstr (
const hawk_bch_t* str1, const hawk_bch_t* str1,
hawk_oow_t len, hawk_oow_t len,
@ -482,366 +394,6 @@ HAWK_EXPORT int hawk_comp_bchars_ucstr (
int ignorecase int ignorecase
); );
HAWK_EXPORT void hawk_copy_uchars (
hawk_uch_t* dst,
const hawk_uch_t* src,
hawk_oow_t len
);
HAWK_EXPORT void hawk_copy_bchars (
hawk_bch_t* dst,
const hawk_bch_t* src,
hawk_oow_t len
);
HAWK_EXPORT void hawk_copy_bchars_to_uchars (
hawk_uch_t* dst,
const hawk_bch_t* src,
hawk_oow_t len
);
HAWK_EXPORT void hawk_copy_uchars_to_bchars (
hawk_bch_t* dst,
const hawk_uch_t* src,
hawk_oow_t len
);
HAWK_EXPORT hawk_oow_t hawk_copy_uchars_to_ucstr_unlimited (
hawk_uch_t* dst,
const hawk_uch_t* src,
hawk_oow_t len
);
HAWK_EXPORT hawk_oow_t hawk_copy_bchars_to_bcstr_unlimited (
hawk_bch_t* dst,
const hawk_bch_t* src,
hawk_oow_t len
);
HAWK_EXPORT hawk_oow_t hawk_copy_ucstr_to_uchars (
hawk_uch_t* dst,
hawk_oow_t dlen,
const hawk_uch_t* src
);
HAWK_EXPORT hawk_oow_t hawk_copy_bcstr_to_bchars (
hawk_bch_t* dst,
hawk_oow_t dlen,
const hawk_bch_t* src
);
HAWK_EXPORT hawk_oow_t hawk_copy_ucstr (
hawk_uch_t* dst,
hawk_oow_t len,
const hawk_uch_t* src
);
HAWK_EXPORT hawk_oow_t hawk_copy_bcstr (
hawk_bch_t* dst,
hawk_oow_t len,
const hawk_bch_t* src
);
HAWK_EXPORT hawk_oow_t hawk_copy_uchars_to_ucstr (
hawk_uch_t* dst,
hawk_oow_t dlen,
const hawk_uch_t* src,
hawk_oow_t slen
);
HAWK_EXPORT hawk_oow_t hawk_copy_bchars_to_bcstr (
hawk_bch_t* dst,
hawk_oow_t dlen,
const hawk_bch_t* src,
hawk_oow_t slen
);
HAWK_EXPORT hawk_oow_t hawk_copy_ucstr_unlimited (
hawk_uch_t* dst,
const hawk_uch_t* src
);
HAWK_EXPORT hawk_oow_t hawk_copy_bcstr_unlimited (
hawk_bch_t* dst,
const hawk_bch_t* src
);
HAWK_EXPORT hawk_oow_t hawk_copy_fmt_ucses_to_ucstr (
hawk_uch_t* buf,
hawk_oow_t bsz,
const hawk_uch_t* fmt,
const hawk_ucs_t str[]
);
HAWK_EXPORT hawk_oow_t hawk_copy_fmt_bcses_to_bcstr (
hawk_bch_t* buf,
hawk_oow_t bsz,
const hawk_bch_t* fmt,
const hawk_bcs_t str[]
);
HAWK_EXPORT hawk_oow_t hawk_count_ucstr (
const hawk_uch_t* str
);
HAWK_EXPORT hawk_oow_t hawk_count_ucstr_limited (
const hawk_uch_t* str,
hawk_oow_t maxlen
);
HAWK_EXPORT hawk_oow_t hawk_count_bcstr (
const hawk_bch_t* str
);
HAWK_EXPORT hawk_oow_t hawk_count_bcstr_limited (
const hawk_bch_t* str,
hawk_oow_t maxlen
);
HAWK_EXPORT void hawk_fill_uchars (
hawk_uch_t* dst,
const hawk_uch_t ch,
hawk_oow_t len
);
HAWK_EXPORT void hawk_fill_bchars (
hawk_bch_t* dst,
const hawk_bch_t ch,
hawk_oow_t len
);
HAWK_EXPORT hawk_uch_t* hawk_find_uchar_in_uchars (
const hawk_uch_t* ptr,
hawk_oow_t len,
hawk_uch_t c
);
HAWK_EXPORT hawk_bch_t* hawk_find_bchar_in_bchars (
const hawk_bch_t* ptr,
hawk_oow_t len,
hawk_bch_t c
);
HAWK_EXPORT hawk_uch_t* hawk_rfind_uchar_in_uchars (
const hawk_uch_t* ptr,
hawk_oow_t len,
hawk_uch_t c
);
HAWK_EXPORT hawk_bch_t* hawk_rfind_bchar_in_bchars (
const hawk_bch_t* ptr,
hawk_oow_t len,
hawk_bch_t c
);
HAWK_EXPORT hawk_uch_t* hawk_find_uchar_in_ucstr (
const hawk_uch_t* ptr,
hawk_uch_t c
);
HAWK_EXPORT hawk_uch_t* hawk_rfind_uchar_in_ucstr (
const hawk_uch_t* ptr,
hawk_uch_t c
);
HAWK_EXPORT hawk_bch_t* hawk_find_bchar_in_bcstr (
const hawk_bch_t* ptr,
hawk_bch_t c
);
HAWK_EXPORT hawk_bch_t* hawk_rfind_bchar_in_bcstr (
const hawk_bch_t* ptr,
hawk_bch_t c
);
HAWK_EXPORT hawk_uch_t* hawk_find_uchars_in_uchars (
const hawk_uch_t* str,
hawk_oow_t strsz,
const hawk_uch_t* sub,
hawk_oow_t subsz,
int ignorecase
);
HAWK_EXPORT hawk_bch_t* hawk_find_bchars_in_bchars (
const hawk_bch_t* str,
hawk_oow_t strsz,
const hawk_bch_t* sub,
hawk_oow_t subsz,
int ignorecase
);
HAWK_EXPORT hawk_uch_t* hawk_rfind_uchars_in_uchars (
const hawk_uch_t* str,
hawk_oow_t strsz,
const hawk_uch_t* sub,
hawk_oow_t subsz,
int ignorecase
);
HAWK_EXPORT hawk_bch_t* hawk_rfind_bchars_in_bchars (
const hawk_bch_t* str,
hawk_oow_t strsz,
const hawk_bch_t* sub,
hawk_oow_t subsz,
int ignorecase
);
HAWK_EXPORT hawk_oow_t hawk_compact_uchars (
hawk_uch_t* str,
hawk_oow_t len
);
HAWK_EXPORT hawk_oow_t hawk_compact_bchars (
hawk_bch_t* str,
hawk_oow_t len
);
HAWK_EXPORT hawk_oow_t hawk_rotate_uchars (
hawk_uch_t* str,
hawk_oow_t len,
int dir,
hawk_oow_t n
);
HAWK_EXPORT hawk_oow_t hawk_rotate_bchars (
hawk_bch_t* str,
hawk_oow_t len,
int dir,
hawk_oow_t n
);
HAWK_EXPORT hawk_uch_t* hawk_trim_uchars (
const hawk_uch_t* str,
hawk_oow_t* len,
int flags
);
HAWK_EXPORT hawk_bch_t* hawk_trim_bchars (
const hawk_bch_t* str,
hawk_oow_t* len,
int flags
);
HAWK_EXPORT int hawk_split_ucstr (
hawk_uch_t* s,
const hawk_uch_t* delim,
hawk_uch_t lquote,
hawk_uch_t rquote,
hawk_uch_t escape
);
HAWK_EXPORT int hawk_split_bcstr (
hawk_bch_t* s,
const hawk_bch_t* delim,
hawk_bch_t lquote,
hawk_bch_t rquote,
hawk_bch_t escape
);
HAWK_EXPORT hawk_uch_t* hawk_tokenize_uchars (
const hawk_uch_t* s,
hawk_oow_t len,
const hawk_uch_t* delim,
hawk_oow_t delim_len,
hawk_ucs_t* tok,
int ignorecase
);
HAWK_EXPORT hawk_bch_t* hawk_tokenize_bchars (
const hawk_bch_t* s,
hawk_oow_t len,
const hawk_bch_t* delim,
hawk_oow_t delim_len,
hawk_bcs_t* tok,
int ignorecase
);
#if defined(HAWK_OOCH_IS_UCH)
# define hawk_equal_oochars hawk_equal_uchars
# define hawk_comp_oochars hawk_comp_uchars
# define hawk_comp_oocstr_bcstr hawk_comp_ucstr_bcstr
# define hawk_comp_oochars_bcstr hawk_comp_uchars_bcstr
# define hawk_comp_oochars_ucstr hawk_comp_uchars_ucstr
# define hawk_comp_oochars_oocstr hawk_comp_uchars_ucstr
# define hawk_comp_oocstr hawk_comp_ucstr
# define hawk_comp_oocstr_limited hawk_comp_ucstr_limited
# define hawk_copy_oochars hawk_copy_uchars
# define hawk_copy_bchars_to_oochars hawk_copy_bchars_to_uchars
# define hawk_copy_oochars_to_bchars hawk_copy_uchars_to_bchars
# define hawk_copy_uchars_to_oochars hawk_copy_uchars
# define hawk_copy_oochars_to_uchars hawk_copy_uchars
# define hawk_copy_oochars_to_oocstr hawk_copy_uchars_to_ucstr
# define hawk_copy_oochars_to_oocstr_unlimited hawk_copy_uchars_to_ucstr_unlimited
# define hawk_copy_oocstr_to_oochars hawk_copy_ucstr_to_uchars
# define hawk_copy_oocstr hawk_copy_ucstr
# define hawk_copy_oocstr_unlimited hawk_copy_ucstr_unlimited
# define hawk_copy_oofcs_to_oochars hawk_copy_fmt_ucses_to_ucstr
# define hawk_count_oocstr hawk_count_ucstr
# define hawk_count_oocstr_limited hawk_count_ucstr_limited
# define hawk_fill_oochars hawk_fill_uchars
# define hawk_find_oochar_in_oochars hawk_find_uchar_in_uchars
# define hawk_rfind_oochar_in_oochars hawk_rfind_uchar_in_uchars
# define hawk_find_oochar_in_oocstr hawk_find_uchar_in_ucstr
# define hawk_rfind_oochar_in_oocstr hawk_rfind_uchar_in_ucstr
# define hawk_find_oochars_in_oochars hawk_find_uchars_in_uchars
# define hawk_rfind_oochars_in_oochars hawk_rfind_uchars_in_uchars
# define hawk_compact_oochars hawk_compact_uchars
# define hawk_rotate_oochars hawk_rotate_uchars
# define hawk_trim_oochars hawk_trim_uchars
# define hawk_split_oocstr hawk_split_ucstr
# define hawk_tokenize_oochars hawk_tokenize_uchars
#else
# define hawk_equal_oochars hawk_equal_bchars
# define hawk_comp_oochars hawk_comp_bchars
# define hawk_comp_oocstr_bcstr hawk_comp_bcstr
# define hawk_comp_oochars_bcstr hawk_comp_bchars_bcstr
# define hawk_comp_oochars_ucstr hawk_comp_bchars_ucstr
# define hawk_comp_oochars_oocstr hawk_comp_bchars_bcstr
# define hawk_comp_oocstr hawk_comp_bcstr
# define hawk_comp_oocstr_limited hawk_comp_bcstr_limited
# define hawk_copy_oochars hawk_copy_bchars
# define hawk_copy_bchars_to_oochars hawk_copy_bchars
# define hawk_copy_oochars_to_bchars hawk_copy_bchars
# define hawk_copy_uchars_to_oochars hawk_copy_uchars_to_bchars
# define hawk_copy_oochars_to_uchars hawk_copy_bchars_to_uchars
# define hawk_copy_oochars_to_oocstr hawk_copy_bchars_to_bcstr
# define hawk_copy_oochars_to_oocstr_unlimited hawk_copy_bchars_to_bcstr_unlimited
# define hawk_copy_oocstr_to_oochars hawk_copy_bcstr_to_bchars
# define hawk_copy_oocstr hawk_copy_bcstr
# define hawk_copy_oocstr_unlimited hawk_copy_bcstr_unlimited
# define hawk_copy_oofcs_to_oochars hawk_copy_fmt_bcses_to_bcstr
# define hawk_count_oocstr hawk_count_bcstr
# define hawk_count_oocstr_limited hawk_count_bcstr_limited
# define hawk_fill_oochars hawk_fill_bchars
# define hawk_find_oochar_in_oochars hawk_find_bchar_in_bchars
# define hawk_rfind_oochar_in_oochars hawk_rfind_bchar_in_bchars
# define hawk_find_oochar_in_oocstr hawk_find_bchar_in_bcstr
# define hawk_rfind_oochar_in_oocstr hawk_rfind_bchar_in_bcstr
# define hawk_find_oochars_in_oochars hawk_find_bchars_in_bchars
# define hawk_rfind_oochars_in_oochars hawk_rfind_bchars_in_bchars
# define hawk_compact_oochars hawk_compact_bchars
# define hawk_rotate_oochars hawk_rotate_bchars
# define hawk_trim_oochars hawk_trim_bchars
# define hawk_split_oocstr hawk_split_bcstr
# define hawk_tokenize_oochars hawk_tokenize_bchars
#endif
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
HAWK_EXPORT hawk_oow_t hawk_subst_for_uchars_to_ucstr ( HAWK_EXPORT hawk_oow_t hawk_subst_for_uchars_to_ucstr (
@ -1237,41 +789,6 @@ HAWK_EXPORT int hawk_conv_mb8_to_ucs (
hawk_oow_t* ucslen hawk_oow_t* ucslen
); );
/* =========================================================================
* NUMBER TO STRING CONVERSION
* ========================================================================= */
#define HAWK_BYTE_TO_OOCSTR_RADIXMASK (0xFF)
#define HAWK_BYTE_TO_OOCSTR_LOWERCASE (1 << 8)
#define HAWK_BYTE_TO_UCSTR_RADIXMASK HAWK_BYTE_TO_OOCSTR_RADIXMASK
#define HAWK_BYTE_TO_UCSTR_LOWERCASE HAWK_BYTE_TO_OOCSTR_LOWERCASE
#define HAWK_BYTE_TO_BCSTR_RADIXMASK HAWK_BYTE_TO_OOCSTR_RADIXMASK
#define HAWK_BYTE_TO_BCSTR_LOWERCASE HAWK_BYTE_TO_OOCSTR_LOWERCASE
hawk_oow_t hawk_byte_to_ucstr (
hawk_oob_t byte,
hawk_uch_t* buf,
hawk_oow_t size,
int flagged_radix,
hawk_uch_t fill
);
hawk_oow_t hawk_byte_to_bcstr (
hawk_uint8_t byte,
hawk_bch_t* buf,
hawk_oow_t size,
int flagged_radix,
hawk_bch_t fill
);
#if defined(HAWK_OOCH_IS_UCH)
# define hawk_byte_to_oocstr hawk_byte_to_ucstr
#else
# define hawk_byte_to_oocstr hawk_byte_to_bcstr
#endif
/* ========================================================================= /* =========================================================================
* PATH STRING * PATH STRING
* ========================================================================= */ * ========================================================================= */

File diff suppressed because it is too large Load Diff

138
hawk/lib/utl-str.c.m4 Normal file
View File

@ -0,0 +1,138 @@
/*
Copyright (c) 2006-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 utl-str.c. Edit utl-str.c.m4 instead.
*
* Generate utl-str.c with m4
* $ m4 utl-str.c.m4 > utl-str.c
*/
#include "hawk-prv.h"
#include <hawk-chr.h>
dnl
dnl ---------------------------------------------------------------------------
include(`utl-str.m4')dnl
dnl ---------------------------------------------------------------------------
dnl --
fn_comp_chars(hawk_comp_uchars, hawk_uch_t, hawk_uchu_t, hawk_to_uch_lower)
fn_comp_chars(hawk_comp_bchars, hawk_bch_t, hawk_bchu_t, hawk_to_bch_lower)
dnl --
fn_comp_cstr(hawk_comp_ucstr, hawk_uch_t, hawk_uchu_t, hawk_to_uch_lower)
fn_comp_cstr(hawk_comp_bcstr, hawk_bch_t, hawk_bchu_t, hawk_to_bch_lower)
dnl --
fn_comp_cstr_limited(hawk_comp_ucstr_limited, hawk_uch_t, hawk_uchu_t, hawk_to_uch_lower)
fn_comp_cstr_limited(hawk_comp_bcstr_limited, hawk_bch_t, hawk_bchu_t, hawk_to_bch_lower)
dnl --
fn_comp_chars_cstr(hawk_comp_uchars_ucstr, hawk_uch_t, hawk_uchu_t, hawk_to_uch_lower)
fn_comp_chars_cstr(hawk_comp_bchars_bcstr, hawk_bch_t, hawk_bchu_t, hawk_to_bch_lower)
dnl --
fn_concat_chars_to_cstr(hawk_concat_uchars_to_ucstr, hawk_uch_t, hawk_count_ucstr)
fn_concat_chars_to_cstr(hawk_concat_bchars_to_bcstr, hawk_bch_t, hawk_count_bcstr)
dnl --
fn_concat_cstr(hawk_concat_ucstr, hawk_uch_t, hawk_count_ucstr)
fn_concat_cstr(hawk_concat_bcstr, hawk_bch_t, hawk_count_bcstr)
dnl --
fn_copy_chars(hawk_copy_uchars, hawk_uch_t)
fn_copy_chars(hawk_copy_bchars, hawk_bch_t)
dnl --
fn_copy_chars_to_cstr(hawk_copy_uchars_to_ucstr, hawk_uch_t)
fn_copy_chars_to_cstr(hawk_copy_bchars_to_bcstr, hawk_bch_t)
dnl --
fn_copy_chars_to_cstr_unlimited(hawk_copy_uchars_to_ucstr_unlimited, hawk_uch_t)
fn_copy_chars_to_cstr_unlimited(hawk_copy_bchars_to_bcstr_unlimited, hawk_bch_t)
dnl --
fn_copy_cstr_to_chars(hawk_copy_ucstr_to_uchars, hawk_uch_t)
fn_copy_cstr_to_chars(hawk_copy_bcstr_to_bchars, hawk_bch_t)
dnl --
fn_copy_cstr(hawk_copy_ucstr, hawk_uch_t)
fn_copy_cstr(hawk_copy_bcstr, hawk_bch_t)
dnl --
fn_copy_cstr_unlimited(hawk_copy_ucstr_unlimited, hawk_uch_t)
fn_copy_cstr_unlimited(hawk_copy_bcstr_unlimited, hawk_bch_t)
dnl --
fn_copy_fmt_cstrs_to_cstr(hawk_copy_fmt_ucstrs_to_ucstr, hawk_uch_t)
fn_copy_fmt_cstrs_to_cstr(hawk_copy_fmt_bcstrs_to_bcstr, hawk_bch_t)
dnl --
fn_copy_fmt_cses_to_cstr(hawk_copy_fmt_ucses_to_ucstr, hawk_uch_t, hawk_ucs_t)
fn_copy_fmt_cses_to_cstr(hawk_copy_fmt_bcses_to_bcstr, hawk_bch_t, hawk_bcs_t)
dnl --
fn_count_cstr(hawk_count_ucstr, hawk_uch_t)
fn_count_cstr(hawk_count_bcstr, hawk_bch_t)
dnl --
fn_count_cstr_limited(hawk_count_ucstr_limited, hawk_uch_t)
fn_count_cstr_limited(hawk_count_bcstr_limited, hawk_bch_t)
dnl --
fn_equal_chars(hawk_equal_uchars, hawk_uch_t)
fn_equal_chars(hawk_equal_bchars, hawk_bch_t)
dnl --
fn_fill_chars(hawk_fill_uchars, hawk_uch_t)
fn_fill_chars(hawk_fill_bchars, hawk_bch_t)
dnl --
fn_find_char_in_chars(hawk_find_uchar_in_uchars, hawk_uch_t)
fn_find_char_in_chars(hawk_find_bchar_in_bchars, hawk_bch_t)
dnl --
fn_rfind_char_in_chars(hawk_rfind_uchar_in_uchars, hawk_uch_t)
fn_rfind_char_in_chars(hawk_rfind_bchar_in_bchars, hawk_bch_t)
dnl --
fn_find_char_in_cstr(hawk_find_uchar_in_ucstr, hawk_uch_t)
fn_find_char_in_cstr(hawk_find_bchar_in_bcstr, hawk_bch_t)
dnl --
fn_rfind_char_in_cstr(hawk_rfind_uchar_in_ucstr, hawk_uch_t)
fn_rfind_char_in_cstr(hawk_rfind_bchar_in_bcstr, hawk_bch_t)
dnl --
fn_find_chars_in_chars(hawk_find_uchars_in_uchars, hawk_uch_t, hawk_to_uch_lower)
fn_find_chars_in_chars(hawk_find_bchars_in_bchars, hawk_bch_t, hawk_to_bch_lower)
dnl --
fn_rfind_chars_in_chars(hawk_rfind_uchars_in_uchars, hawk_uch_t, hawk_to_uch_lower)
fn_rfind_chars_in_chars(hawk_rfind_bchars_in_bchars, hawk_bch_t, hawk_to_bch_lower)
dnl --
fn_compact_chars(hawk_compact_uchars, hawk_uch_t, hawk_is_uch_space)
fn_compact_chars(hawk_compact_bchars, hawk_bch_t, hawk_is_bch_space)
dnl --
fn_rotate_chars(hawk_rotate_uchars, hawk_uch_t)
fn_rotate_chars(hawk_rotate_bchars, hawk_bch_t)
dnl --
fn_trim_chars(hawk_trim_uchars, hawk_uch_t, hawk_is_uch_space, HAWK_TRIM_UCHARS)
fn_trim_chars(hawk_trim_bchars, hawk_bch_t, hawk_is_bch_space, HAWK_TRIM_BCHARS)
dnl --
fn_split_cstr(hawk_split_ucstr, hawk_uch_t, hawk_is_uch_space, hawk_copy_ucstr_unlimited)
fn_split_cstr(hawk_split_bcstr, hawk_bch_t, hawk_is_bch_space, hawk_copy_bcstr_unlimited)
dnl --
fn_tokenize_chars(hawk_tokenize_uchars, hawk_uch_t, hawk_ucs_t, hawk_is_uch_space, hawk_to_uch_lower)
fn_tokenize_chars(hawk_tokenize_bchars, hawk_bch_t, hawk_bcs_t, hawk_is_bch_space, hawk_to_bch_lower)
dnl --
fn_byte_to_cstr(hawk_byte_to_ucstr, hawk_uch_t, HAWK_BYTE_TO_UCSTR)
fn_byte_to_cstr(hawk_byte_to_bcstr, hawk_bch_t, HAWK_BYTE_TO_BCSTR)
dnl --
fn_int_to_cstr(hawk_int_to_ucstr, hawk_uch_t, hawk_int_t, hawk_count_ucstr)
fn_int_to_cstr(hawk_int_to_bcstr, hawk_bch_t, hawk_int_t, hawk_count_bcstr)
fn_int_to_cstr(hawk_uint_to_ucstr, hawk_uch_t, hawk_uint_t, hawk_count_ucstr)
fn_int_to_cstr(hawk_uint_to_bcstr, hawk_bch_t, hawk_uint_t, hawk_count_bcstr)
dnl --
fn_chars_to_int(hawk_uchars_to_int, hawk_uch_t, hawk_int_t, hawk_is_uch_space, HAWK_UCHARS_TO_INTMAX)
fn_chars_to_int(hawk_bchars_to_int, hawk_bch_t, hawk_int_t, hawk_is_bch_space, HAWK_BCHARS_TO_INTMAX)
dnl --
fn_chars_to_uint(hawk_uchars_to_uint, hawk_uch_t, hawk_uint_t, hawk_is_uch_space, HAWK_UCHARS_TO_UINTMAX)
fn_chars_to_uint(hawk_bchars_to_uint, hawk_bch_t, hawk_uint_t, hawk_is_bch_space, HAWK_BCHARS_TO_UINTMAX)

1509
hawk/lib/utl-str.m4 Normal file

File diff suppressed because it is too large Load Diff

View File

@ -130,76 +130,6 @@ void hawk_copy_uchars_to_bchars (hawk_bch_t* dst, const hawk_uch_t* src, hawk_oo
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
hawk_oow_t hawk_byte_to_ucstr (hawk_oob_t byte, hawk_uch_t* buf, hawk_oow_t size, int flagged_radix, hawk_uch_t fill)
{
hawk_uch_t tmp[(HAWK_SIZEOF(hawk_oob_t) * HAWK_BITS_PER_BYTE)];
hawk_uch_t* p = tmp, * bp = buf, * be = buf + size - 1;
int radix;
hawk_uch_t radix_char;
radix = (flagged_radix & HAWK_BYTE_TO_UCSTR_RADIXMASK);
radix_char = (flagged_radix & HAWK_BYTE_TO_UCSTR_LOWERCASE)? 'a': 'A';
if (radix < 2 || radix > 36 || size <= 0) return 0;
do
{
hawk_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;
}
hawk_oow_t hawk_byte_to_bcstr (hawk_oob_t byte, hawk_bch_t* buf, hawk_oow_t size, int flagged_radix, hawk_bch_t fill)
{
hawk_bch_t tmp[(HAWK_SIZEOF(hawk_oob_t) * HAWK_BITS_PER_BYTE)];
hawk_bch_t* p = tmp, * bp = buf, * be = buf + size - 1;
int radix;
hawk_bch_t radix_char;
radix = (flagged_radix & HAWK_BYTE_TO_BCSTR_RADIXMASK);
radix_char = (flagged_radix & HAWK_BYTE_TO_BCSTR_LOWERCASE)? 'a': 'A';
if (radix < 2 || radix > 36 || size <= 0) return 0;
do
{
hawk_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;
}
/* ------------------------------------------------------------------------ */
int hawk_conv_bchars_to_uchars_with_cmgr ( int hawk_conv_bchars_to_uchars_with_cmgr (
const hawk_bch_t* bcs, hawk_oow_t* bcslen, const hawk_bch_t* bcs, hawk_oow_t* bcslen,
hawk_uch_t* ucs, hawk_oow_t* ucslen, hawk_cmgr_t* cmgr, int all) hawk_uch_t* ucs, hawk_oow_t* ucslen, hawk_cmgr_t* cmgr, int all)