migrated cmgr functions from utl-str.c to utl-cmgr.c

This commit is contained in:
hyung-hwan 2022-06-13 10:29:55 +00:00
parent 3245885936
commit d2564be683
4 changed files with 194 additions and 154 deletions

View File

@ -124,6 +124,7 @@ libhawk_la_SOURCES = \
utf16.c \ utf16.c \
utf8.c \ utf8.c \
utl-ass.c \ utl-ass.c \
utl-cmgr.c \
utl-rnd.c\ utl-rnd.c\
utl-sort.c \ utl-sort.c \
utl-str.c \ utl-str.c \

View File

@ -241,13 +241,13 @@ am__libhawk_la_SOURCES_DIST = hawk.h hawk-arr.h hawk-chr.h hawk-cmn.h \
tre-compile.c tre-compile.h tre-match-bt.c tre-match-pa.c \ tre-compile.c tre-compile.h tre-match-bt.c tre-match-pa.c \
tre-match-ut.h tre-mem.c tre-mem.h tre-parse.c tre-parse.h \ tre-match-ut.h tre-mem.c tre-mem.h tre-parse.c tre-parse.h \
tre-stack.h tre-stack.c tre.c tree-prv.h tree.c uch-prop.h \ tre-stack.h tre-stack.c tre.c tree-prv.h tree.c uch-prop.h \
uch-case.h utf16.c utf8.c utl-ass.c utl-rnd.c utl-sort.c \ uch-case.h utf16.c utf8.c utl-ass.c utl-cmgr.c utl-rnd.c \
utl-str.c utl-sys.c utl.c val-prv.h val.c xma.c hawk-cli.h \ utl-sort.c utl-str.c utl-sys.c utl.c val-prv.h val.c xma.c \
hawk-fio.h hawk-mtx.h hawk-pio.h hawk-sio.h hawk-tio.h \ hawk-cli.h hawk-fio.h hawk-mtx.h hawk-pio.h hawk-sio.h \
cli-imp.h cli.c fio.c mtx.c pio.c sio.c syscall.h tio.c std.c \ hawk-tio.h cli-imp.h cli.c fio.c mtx.c pio.c sio.c syscall.h \
std-sed.c Hawk.cpp Std.cpp Sed.cpp Std-Sed.cpp mod-hawk.c \ tio.c std.c std-sed.c Hawk.cpp Std.cpp Sed.cpp Std-Sed.cpp \
mod-hawk.h mod-math.c mod-math.h mod-str.c mod-str.h mod-sys.c \ mod-hawk.c mod-hawk.h mod-math.c mod-math.h mod-str.c \
mod-sys.h mod-str.h mod-sys.c mod-sys.h
am__objects_1 = am__objects_1 =
am__objects_2 = $(am__objects_1) am__objects_2 = $(am__objects_1)
@ENABLE_CXX_TRUE@am__objects_3 = libhawk_la-Hawk.lo libhawk_la-Std.lo \ @ENABLE_CXX_TRUE@am__objects_3 = libhawk_la-Hawk.lo libhawk_la-Std.lo \
@ -269,7 +269,8 @@ am_libhawk_la_OBJECTS = $(am__objects_2) libhawk_la-arr.lo \
libhawk_la-tre-match-pa.lo libhawk_la-tre-mem.lo \ libhawk_la-tre-match-pa.lo libhawk_la-tre-mem.lo \
libhawk_la-tre-parse.lo libhawk_la-tre-stack.lo \ libhawk_la-tre-parse.lo libhawk_la-tre-stack.lo \
libhawk_la-tre.lo libhawk_la-tree.lo libhawk_la-utf16.lo \ libhawk_la-tre.lo libhawk_la-tree.lo libhawk_la-utf16.lo \
libhawk_la-utf8.lo libhawk_la-utl-ass.lo libhawk_la-utl-rnd.lo \ libhawk_la-utf8.lo libhawk_la-utl-ass.lo \
libhawk_la-utl-cmgr.lo libhawk_la-utl-rnd.lo \
libhawk_la-utl-sort.lo libhawk_la-utl-str.lo \ libhawk_la-utl-sort.lo libhawk_la-utl-str.lo \
libhawk_la-utl-sys.lo libhawk_la-utl.lo libhawk_la-val.lo \ libhawk_la-utl-sys.lo libhawk_la-utl.lo libhawk_la-val.lo \
libhawk_la-xma.lo libhawk_la-cli.lo libhawk_la-fio.lo \ libhawk_la-xma.lo libhawk_la-cli.lo libhawk_la-fio.lo \
@ -329,6 +330,7 @@ am__depfiles_remade = ./$(DEPDIR)/libhawk_hawk_la-mod-hawk.Plo \
./$(DEPDIR)/libhawk_la-utf16.Plo \ ./$(DEPDIR)/libhawk_la-utf16.Plo \
./$(DEPDIR)/libhawk_la-utf8.Plo \ ./$(DEPDIR)/libhawk_la-utf8.Plo \
./$(DEPDIR)/libhawk_la-utl-ass.Plo \ ./$(DEPDIR)/libhawk_la-utl-ass.Plo \
./$(DEPDIR)/libhawk_la-utl-cmgr.Plo \
./$(DEPDIR)/libhawk_la-utl-rnd.Plo \ ./$(DEPDIR)/libhawk_la-utl-rnd.Plo \
./$(DEPDIR)/libhawk_la-utl-sort.Plo \ ./$(DEPDIR)/libhawk_la-utl-sort.Plo \
./$(DEPDIR)/libhawk_la-utl-str.Plo \ ./$(DEPDIR)/libhawk_la-utl-str.Plo \
@ -614,11 +616,11 @@ libhawk_la_SOURCES = $(pkginclude_HEADERS) arr.c chr.c dir.c ecs-imp.h \
tre-compile.c tre-compile.h tre-match-bt.c tre-match-pa.c \ tre-compile.c tre-compile.h tre-match-bt.c tre-match-pa.c \
tre-match-ut.h tre-mem.c tre-mem.h tre-parse.c tre-parse.h \ tre-match-ut.h tre-mem.c tre-mem.h tre-parse.c tre-parse.h \
tre-stack.h tre-stack.c tre.c tree-prv.h tree.c uch-prop.h \ tre-stack.h tre-stack.c tre.c tree-prv.h tree.c uch-prop.h \
uch-case.h utf16.c utf8.c utl-ass.c utl-rnd.c utl-sort.c \ uch-case.h utf16.c utf8.c utl-ass.c utl-cmgr.c utl-rnd.c \
utl-str.c utl-sys.c utl.c val-prv.h val.c xma.c hawk-cli.h \ utl-sort.c utl-str.c utl-sys.c utl.c val-prv.h val.c xma.c \
hawk-fio.h hawk-mtx.h hawk-pio.h hawk-sio.h hawk-tio.h \ hawk-cli.h hawk-fio.h hawk-mtx.h hawk-pio.h hawk-sio.h \
cli-imp.h cli.c fio.c mtx.c pio.c sio.c syscall.h tio.c std.c \ hawk-tio.h cli-imp.h cli.c fio.c mtx.c pio.c sio.c syscall.h \
std-sed.c $(am__append_8) $(am__append_9) tio.c std.c std-sed.c $(am__append_8) $(am__append_9)
libhawk_la_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) $(CPPFLAGS_PFMOD) \ libhawk_la_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) $(CPPFLAGS_PFMOD) \
$(am__append_3) $(am__append_3)
libhawk_la_CFLAGS = $(CFLAGS_ALL_COMMON) libhawk_la_CFLAGS = $(CFLAGS_ALL_COMMON)
@ -828,6 +830,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-utf16.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-utf16.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-utf8.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-utf8.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-utl-ass.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-utl-ass.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-utl-cmgr.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-utl-rnd.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-utl-rnd.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-utl-sort.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-utl-sort.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-utl-str.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-utl-str.Plo@am__quote@ # am--include-marker
@ -1135,6 +1138,13 @@ libhawk_la-utl-ass.lo: utl-ass.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(libhawk_la_CFLAGS) $(CFLAGS) -c -o libhawk_la-utl-ass.lo `test -f 'utl-ass.c' || echo '$(srcdir)/'`utl-ass.c @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(libhawk_la_CFLAGS) $(CFLAGS) -c -o libhawk_la-utl-ass.lo `test -f 'utl-ass.c' || echo '$(srcdir)/'`utl-ass.c
libhawk_la-utl-cmgr.lo: utl-cmgr.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(libhawk_la_CFLAGS) $(CFLAGS) -MT libhawk_la-utl-cmgr.lo -MD -MP -MF $(DEPDIR)/libhawk_la-utl-cmgr.Tpo -c -o libhawk_la-utl-cmgr.lo `test -f 'utl-cmgr.c' || echo '$(srcdir)/'`utl-cmgr.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhawk_la-utl-cmgr.Tpo $(DEPDIR)/libhawk_la-utl-cmgr.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='utl-cmgr.c' object='libhawk_la-utl-cmgr.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(libhawk_la_CFLAGS) $(CFLAGS) -c -o libhawk_la-utl-cmgr.lo `test -f 'utl-cmgr.c' || echo '$(srcdir)/'`utl-cmgr.c
libhawk_la-utl-rnd.lo: utl-rnd.c libhawk_la-utl-rnd.lo: utl-rnd.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(libhawk_la_CFLAGS) $(CFLAGS) -MT libhawk_la-utl-rnd.lo -MD -MP -MF $(DEPDIR)/libhawk_la-utl-rnd.Tpo -c -o libhawk_la-utl-rnd.lo `test -f 'utl-rnd.c' || echo '$(srcdir)/'`utl-rnd.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(libhawk_la_CFLAGS) $(CFLAGS) -MT libhawk_la-utl-rnd.lo -MD -MP -MF $(DEPDIR)/libhawk_la-utl-rnd.Tpo -c -o libhawk_la-utl-rnd.lo `test -f 'utl-rnd.c' || echo '$(srcdir)/'`utl-rnd.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhawk_la-utl-rnd.Tpo $(DEPDIR)/libhawk_la-utl-rnd.Plo @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhawk_la-utl-rnd.Tpo $(DEPDIR)/libhawk_la-utl-rnd.Plo
@ -1526,6 +1536,7 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/libhawk_la-utf16.Plo -rm -f ./$(DEPDIR)/libhawk_la-utf16.Plo
-rm -f ./$(DEPDIR)/libhawk_la-utf8.Plo -rm -f ./$(DEPDIR)/libhawk_la-utf8.Plo
-rm -f ./$(DEPDIR)/libhawk_la-utl-ass.Plo -rm -f ./$(DEPDIR)/libhawk_la-utl-ass.Plo
-rm -f ./$(DEPDIR)/libhawk_la-utl-cmgr.Plo
-rm -f ./$(DEPDIR)/libhawk_la-utl-rnd.Plo -rm -f ./$(DEPDIR)/libhawk_la-utl-rnd.Plo
-rm -f ./$(DEPDIR)/libhawk_la-utl-sort.Plo -rm -f ./$(DEPDIR)/libhawk_la-utl-sort.Plo
-rm -f ./$(DEPDIR)/libhawk_la-utl-str.Plo -rm -f ./$(DEPDIR)/libhawk_la-utl-str.Plo
@ -1633,6 +1644,7 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/libhawk_la-utf16.Plo -rm -f ./$(DEPDIR)/libhawk_la-utf16.Plo
-rm -f ./$(DEPDIR)/libhawk_la-utf8.Plo -rm -f ./$(DEPDIR)/libhawk_la-utf8.Plo
-rm -f ./$(DEPDIR)/libhawk_la-utl-ass.Plo -rm -f ./$(DEPDIR)/libhawk_la-utl-ass.Plo
-rm -f ./$(DEPDIR)/libhawk_la-utl-cmgr.Plo
-rm -f ./$(DEPDIR)/libhawk_la-utl-rnd.Plo -rm -f ./$(DEPDIR)/libhawk_la-utl-rnd.Plo
-rm -f ./$(DEPDIR)/libhawk_la-utl-sort.Plo -rm -f ./$(DEPDIR)/libhawk_la-utl-sort.Plo
-rm -f ./$(DEPDIR)/libhawk_la-utl-str.Plo -rm -f ./$(DEPDIR)/libhawk_la-utl-str.Plo

168
hawk/lib/utl-cmgr.c Normal file
View File

@ -0,0 +1,168 @@
/*
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.
*/
#include <hawk-utl.h>
#include <hawk-chr.h>
/* ------------------------------------------------------------------------ */
static hawk_cmgr_t builtin_cmgr[] =
{
/* keep the order aligned with hawk_cmgr_id_t values in <hawk-utl.h> */
{ hawk_utf8_to_uc, hawk_uc_to_utf8 },
{ hawk_utf16_to_uc, hawk_uc_to_utf16 },
{ hawk_mb8_to_uc, hawk_uc_to_mb8 }
};
hawk_cmgr_t* hawk_get_cmgr_by_id (hawk_cmgr_id_t id)
{
return &builtin_cmgr[id];
}
static struct
{
const hawk_bch_t* name;
hawk_cmgr_id_t id;
} builtin_cmgr_tab[] =
{
{ "utf8", HAWK_CMGR_UTF8 },
{ "utf16", HAWK_CMGR_UTF16 },
{ "mb8", HAWK_CMGR_MB8 }
};
hawk_cmgr_t* hawk_get_cmgr_by_bcstr (const hawk_bch_t* name)
{
if (name)
{
hawk_oow_t i;
for (i = 0; i < HAWK_COUNTOF(builtin_cmgr_tab); i++)
{
if (hawk_comp_bcstr(name, builtin_cmgr_tab[i].name, 0) == 0)
{
return &builtin_cmgr[builtin_cmgr_tab[i].id];
}
}
}
return HAWK_NULL;
}
hawk_cmgr_t* hawk_get_cmgr_by_ucstr (const hawk_uch_t* name)
{
if (name)
{
hawk_oow_t i;
for (i = 0; i < HAWK_COUNTOF(builtin_cmgr_tab); i++)
{
if (hawk_comp_ucstr_bcstr(name, builtin_cmgr_tab[i].name, 0) == 0)
{
return &builtin_cmgr[builtin_cmgr_tab[i].id];
}
}
}
return HAWK_NULL;
}
/* ------------------------------------------------------------------------ */
int hawk_conv_utf8_to_uchars (const hawk_bch_t* bcs, hawk_oow_t* bcslen, hawk_uch_t* ucs, hawk_oow_t* ucslen)
{
/* the source is length bound */
return hawk_conv_bchars_to_uchars_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[HAWK_CMGR_UTF8], 0);
}
int hawk_conv_uchars_to_utf8 (const hawk_uch_t* ucs, hawk_oow_t* ucslen, hawk_bch_t* bcs, hawk_oow_t* bcslen)
{
/* length bound */
return hawk_conv_uchars_to_bchars_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[HAWK_CMGR_UTF8]);
}
int hawk_conv_utf8_to_ucstr (const hawk_bch_t* bcs, hawk_oow_t* bcslen, hawk_uch_t* ucs, hawk_oow_t* ucslen)
{
/* null-terminated. */
return hawk_conv_bcstr_to_ucstr_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[HAWK_CMGR_UTF8], 0);
}
int hawk_conv_ucstr_to_utf8 (const hawk_uch_t* ucs, hawk_oow_t* ucslen, hawk_bch_t* bcs, hawk_oow_t* bcslen)
{
/* null-terminated */
return hawk_conv_ucstr_to_bcstr_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[HAWK_CMGR_UTF8]);
}
/* ------------------------------------------------------------------------ */
int hawk_conv_utf16_to_uchars (const hawk_bch_t* bcs, hawk_oow_t* bcslen, hawk_uch_t* ucs, hawk_oow_t* ucslen)
{
/* the source is length bound */
return hawk_conv_bchars_to_uchars_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[HAWK_CMGR_UTF16], 0);
}
int hawk_conv_uchars_to_utf16 (const hawk_uch_t* ucs, hawk_oow_t* ucslen, hawk_bch_t* bcs, hawk_oow_t* bcslen)
{
/* length bound */
return hawk_conv_uchars_to_bchars_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[HAWK_CMGR_UTF16]);
}
int hawk_conv_utf16_to_ucstr (const hawk_bch_t* bcs, hawk_oow_t* bcslen, hawk_uch_t* ucs, hawk_oow_t* ucslen)
{
/* null-terminated. */
return hawk_conv_bcstr_to_ucstr_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[HAWK_CMGR_UTF16], 0);
}
int hawk_conv_ucstr_to_utf16 (const hawk_uch_t* ucs, hawk_oow_t* ucslen, hawk_bch_t* bcs, hawk_oow_t* bcslen)
{
/* null-terminated */
return hawk_conv_ucstr_to_bcstr_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[HAWK_CMGR_UTF16]);
}
/* ------------------------------------------------------------------------ */
int hawk_conv_mb8_to_uchars (const hawk_bch_t* bcs, hawk_oow_t* bcslen, hawk_uch_t* ucs, hawk_oow_t* ucslen)
{
/* the source is length bound */
return hawk_conv_bchars_to_uchars_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[HAWK_CMGR_MB8], 0);
}
int hawk_conv_uchars_to_mb8 (const hawk_uch_t* ucs, hawk_oow_t* ucslen, hawk_bch_t* bcs, hawk_oow_t* bcslen)
{
/* length bound */
return hawk_conv_uchars_to_bchars_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[HAWK_CMGR_MB8]);
}
int hawk_conv_mb8_to_ucstr (const hawk_bch_t* bcs, hawk_oow_t* bcslen, hawk_uch_t* ucs, hawk_oow_t* ucslen)
{
/* null-terminated. */
return hawk_conv_bcstr_to_ucstr_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[HAWK_CMGR_MB8], 0);
}
int hawk_conv_ucstr_to_mb8 (const hawk_uch_t* ucs, hawk_oow_t* ucslen, hawk_bch_t* bcs, hawk_oow_t* bcslen)
{
/* null-terminated */
return hawk_conv_ucstr_to_bcstr_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[HAWK_CMGR_MB8]);
}
/* ------------------------------------------------------------------------ */

View File

@ -3676,144 +3676,3 @@ int hawk_bchars_to_bin (const hawk_bch_t* hex, hawk_oow_t hexlen, hawk_uint8_t*
return 0; return 0;
} }
/* ------------------------------------------------------------------------ */
static hawk_cmgr_t builtin_cmgr[] =
{
/* keep the order aligned with hawk_cmgr_id_t values in <hawk-utl.h> */
{ hawk_utf8_to_uc, hawk_uc_to_utf8 },
{ hawk_utf16_to_uc, hawk_uc_to_utf16 },
{ hawk_mb8_to_uc, hawk_uc_to_mb8 }
};
hawk_cmgr_t* hawk_get_cmgr_by_id (hawk_cmgr_id_t id)
{
return &builtin_cmgr[id];
}
static struct
{
const hawk_bch_t* name;
hawk_cmgr_id_t id;
} builtin_cmgr_tab[] =
{
{ "utf8", HAWK_CMGR_UTF8 },
{ "utf16", HAWK_CMGR_UTF16 },
{ "mb8", HAWK_CMGR_MB8 }
};
hawk_cmgr_t* hawk_get_cmgr_by_bcstr (const hawk_bch_t* name)
{
if (name)
{
hawk_oow_t i;
for (i = 0; i < HAWK_COUNTOF(builtin_cmgr_tab); i++)
{
if (hawk_comp_bcstr(name, builtin_cmgr_tab[i].name, 0) == 0)
{
return &builtin_cmgr[builtin_cmgr_tab[i].id];
}
}
}
return HAWK_NULL;
}
hawk_cmgr_t* hawk_get_cmgr_by_ucstr (const hawk_uch_t* name)
{
if (name)
{
hawk_oow_t i;
for (i = 0; i < HAWK_COUNTOF(builtin_cmgr_tab); i++)
{
if (hawk_comp_ucstr_bcstr(name, builtin_cmgr_tab[i].name, 0) == 0)
{
return &builtin_cmgr[builtin_cmgr_tab[i].id];
}
}
}
return HAWK_NULL;
}
/* ------------------------------------------------------------------------ */
int hawk_conv_utf8_to_uchars (const hawk_bch_t* bcs, hawk_oow_t* bcslen, hawk_uch_t* ucs, hawk_oow_t* ucslen)
{
/* the source is length bound */
return hawk_conv_bchars_to_uchars_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[HAWK_CMGR_UTF8], 0);
}
int hawk_conv_uchars_to_utf8 (const hawk_uch_t* ucs, hawk_oow_t* ucslen, hawk_bch_t* bcs, hawk_oow_t* bcslen)
{
/* length bound */
return hawk_conv_uchars_to_bchars_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[HAWK_CMGR_UTF8]);
}
int hawk_conv_utf8_to_ucstr (const hawk_bch_t* bcs, hawk_oow_t* bcslen, hawk_uch_t* ucs, hawk_oow_t* ucslen)
{
/* null-terminated. */
return hawk_conv_bcstr_to_ucstr_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[HAWK_CMGR_UTF8], 0);
}
int hawk_conv_ucstr_to_utf8 (const hawk_uch_t* ucs, hawk_oow_t* ucslen, hawk_bch_t* bcs, hawk_oow_t* bcslen)
{
/* null-terminated */
return hawk_conv_ucstr_to_bcstr_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[HAWK_CMGR_UTF8]);
}
/* ------------------------------------------------------------------------ */
int hawk_conv_utf16_to_uchars (const hawk_bch_t* bcs, hawk_oow_t* bcslen, hawk_uch_t* ucs, hawk_oow_t* ucslen)
{
/* the source is length bound */
return hawk_conv_bchars_to_uchars_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[HAWK_CMGR_UTF16], 0);
}
int hawk_conv_uchars_to_utf16 (const hawk_uch_t* ucs, hawk_oow_t* ucslen, hawk_bch_t* bcs, hawk_oow_t* bcslen)
{
/* length bound */
return hawk_conv_uchars_to_bchars_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[HAWK_CMGR_UTF16]);
}
int hawk_conv_utf16_to_ucstr (const hawk_bch_t* bcs, hawk_oow_t* bcslen, hawk_uch_t* ucs, hawk_oow_t* ucslen)
{
/* null-terminated. */
return hawk_conv_bcstr_to_ucstr_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[HAWK_CMGR_UTF16], 0);
}
int hawk_conv_ucstr_to_utf16 (const hawk_uch_t* ucs, hawk_oow_t* ucslen, hawk_bch_t* bcs, hawk_oow_t* bcslen)
{
/* null-terminated */
return hawk_conv_ucstr_to_bcstr_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[HAWK_CMGR_UTF16]);
}
/* ------------------------------------------------------------------------ */
int hawk_conv_mb8_to_uchars (const hawk_bch_t* bcs, hawk_oow_t* bcslen, hawk_uch_t* ucs, hawk_oow_t* ucslen)
{
/* the source is length bound */
return hawk_conv_bchars_to_uchars_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[HAWK_CMGR_MB8], 0);
}
int hawk_conv_uchars_to_mb8 (const hawk_uch_t* ucs, hawk_oow_t* ucslen, hawk_bch_t* bcs, hawk_oow_t* bcslen)
{
/* length bound */
return hawk_conv_uchars_to_bchars_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[HAWK_CMGR_MB8]);
}
int hawk_conv_mb8_to_ucstr (const hawk_bch_t* bcs, hawk_oow_t* bcslen, hawk_uch_t* ucs, hawk_oow_t* ucslen)
{
/* null-terminated. */
return hawk_conv_bcstr_to_ucstr_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[HAWK_CMGR_MB8], 0);
}
int hawk_conv_ucstr_to_mb8 (const hawk_uch_t* ucs, hawk_oow_t* ucslen, hawk_bch_t* bcs, hawk_oow_t* bcslen)
{
/* null-terminated */
return hawk_conv_ucstr_to_bcstr_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[HAWK_CMGR_MB8]);
}
/* ------------------------------------------------------------------------ */