added some partial utf8 related primitives
This commit is contained in:
@ -78,6 +78,7 @@ libmoo_la_SOURCES = \
|
||||
opt.c \
|
||||
pf-basic.c \
|
||||
pf-sys.c \
|
||||
pf-utf8.c \
|
||||
rbt.c \
|
||||
sym.c \
|
||||
utf8.c \
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Makefile.in generated by automake 1.15 from Makefile.am.
|
||||
# Makefile.in generated by automake 1.14.1 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994-2014 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1994-2013 Free Software Foundation, Inc.
|
||||
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -17,17 +17,7 @@
|
||||
|
||||
|
||||
VPATH = @srcdir@
|
||||
am__is_gnu_make = { \
|
||||
if test -z '$(MAKELEVEL)'; then \
|
||||
false; \
|
||||
elif test -n '$(MAKE_HOST)'; then \
|
||||
true; \
|
||||
elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
|
||||
true; \
|
||||
else \
|
||||
false; \
|
||||
fi; \
|
||||
}
|
||||
am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
|
||||
am__make_running_with_option = \
|
||||
case $${target_option-} in \
|
||||
?) ;; \
|
||||
@ -116,6 +106,9 @@ bin_PROGRAMS = moo$(EXEEXT)
|
||||
@ENABLE_STATIC_MODULE_FALSE@moo_DEPENDENCIES = $(am__DEPENDENCIES_5) \
|
||||
@ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1)
|
||||
subdir = lib
|
||||
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
|
||||
$(srcdir)/moo-cfg.h.in $(top_srcdir)/ac/depcomp \
|
||||
$(pkginclude_HEADERS)
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \
|
||||
$(top_srcdir)/m4/ax_cxx_namespace.m4 \
|
||||
@ -125,8 +118,6 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \
|
||||
$(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(pkginclude_HEADERS) \
|
||||
$(am__DIST_COMMON)
|
||||
mkinstalldirs = $(install_sh) -d
|
||||
CONFIG_HEADER = moo-cfg.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
@ -172,8 +163,8 @@ am_libmoo_la_OBJECTS = libmoo_la-bigint.lo libmoo_la-comp.lo \
|
||||
libmoo_la-err.lo libmoo_la-exec.lo libmoo_la-logfmt.lo \
|
||||
libmoo_la-gc.lo libmoo_la-heap.lo libmoo_la-moo.lo \
|
||||
libmoo_la-obj.lo libmoo_la-opt.lo libmoo_la-pf-basic.lo \
|
||||
libmoo_la-pf-sys.lo libmoo_la-rbt.lo libmoo_la-sym.lo \
|
||||
libmoo_la-utf8.lo libmoo_la-utl.lo
|
||||
libmoo_la-pf-sys.lo libmoo_la-pf-utf8.lo libmoo_la-rbt.lo \
|
||||
libmoo_la-sym.lo libmoo_la-utf8.lo libmoo_la-utl.lo
|
||||
libmoo_la_OBJECTS = $(am_libmoo_la_OBJECTS)
|
||||
AM_V_lt = $(am__v_lt_@AM_V@)
|
||||
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
|
||||
@ -250,8 +241,6 @@ am__define_uniq_tagged_files = \
|
||||
done | $(am__uniquify_input)`
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/moo-cfg.h.in \
|
||||
$(top_srcdir)/ac/depcomp
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
pkgincludedir = $(includedir)
|
||||
pkglibdir = $(libdir)
|
||||
@ -305,7 +294,6 @@ LIPO = @LIPO@
|
||||
LN_S = @LN_S@
|
||||
LTDL_LIBS = @LTDL_LIBS@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
MANIFEST_TOOL = @MANIFEST_TOOL@
|
||||
MKDIR_P = @MKDIR_P@
|
||||
@ -400,7 +388,6 @@ pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
runstatedir = @runstatedir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
@ -463,6 +450,7 @@ libmoo_la_SOURCES = \
|
||||
opt.c \
|
||||
pf-basic.c \
|
||||
pf-sys.c \
|
||||
pf-utf8.c \
|
||||
rbt.c \
|
||||
sym.c \
|
||||
utf8.c \
|
||||
@ -498,6 +486,7 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign lib/Makefile'; \
|
||||
$(am__cd) $(top_srcdir) && \
|
||||
$(AUTOMAKE) --foreign lib/Makefile
|
||||
.PRECIOUS: Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
*config.status*) \
|
||||
@ -643,6 +632,7 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-opt.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-pf-basic.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-pf-sys.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-pf-utf8.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-rbt.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-sym.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-utf8.Plo@am__quote@
|
||||
@ -778,6 +768,13 @@ libmoo_la-pf-sys.lo: pf-sys.c
|
||||
@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) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-pf-sys.lo `test -f 'pf-sys.c' || echo '$(srcdir)/'`pf-sys.c
|
||||
|
||||
libmoo_la-pf-utf8.lo: pf-utf8.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-pf-utf8.lo -MD -MP -MF $(DEPDIR)/libmoo_la-pf-utf8.Tpo -c -o libmoo_la-pf-utf8.lo `test -f 'pf-utf8.c' || echo '$(srcdir)/'`pf-utf8.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-pf-utf8.Tpo $(DEPDIR)/libmoo_la-pf-utf8.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pf-utf8.c' object='libmoo_la-pf-utf8.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) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-pf-utf8.lo `test -f 'pf-utf8.c' || echo '$(srcdir)/'`pf-utf8.c
|
||||
|
||||
libmoo_la-rbt.lo: rbt.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-rbt.lo -MD -MP -MF $(DEPDIR)/libmoo_la-rbt.Tpo -c -o libmoo_la-rbt.lo `test -f 'rbt.c' || echo '$(srcdir)/'`rbt.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-rbt.Tpo $(DEPDIR)/libmoo_la-rbt.Plo
|
||||
@ -1060,8 +1057,6 @@ uninstall-am: uninstall-binPROGRAMS uninstall-pkgincludeHEADERS \
|
||||
uninstall-binPROGRAMS uninstall-hook \
|
||||
uninstall-pkgincludeHEADERS uninstall-pkglibLTLIBRARIES
|
||||
|
||||
.PRECIOUS: Makefile
|
||||
|
||||
|
||||
install-data-hook:
|
||||
@echo "#ifndef _MOO_CFG_H_" > "$(DESTDIR)$(pkgincludedir)/moo-cfg.h"
|
||||
|
@ -64,14 +64,15 @@ static moo_ooch_t errstr_28[] = {'*','*','*',' ','u','n','d','e','f','i','n','e'
|
||||
static moo_ooch_t errstr_29[] = {'d','i','v','i','d','e',' ','b','y',' ','z','e','r','o','\0'};
|
||||
static moo_ooch_t errstr_30[] = {'I','/','O',' ','e','r','r','o','r','\0'};
|
||||
static moo_ooch_t errstr_31[] = {'e','n','c','o','d','i','n','g',' ','c','o','n','v','e','r','s','i','o','n',' ','e','r','r','o','r','\0'};
|
||||
static moo_ooch_t errstr_32[] = {'b','u','f','f','e','r',' ','f','u','l','l','\0'};
|
||||
static moo_ooch_t errstr_32[] = {'i','n','s','u','f','f','i','c','i','e','n','t',' ','d','a','t','a',' ','e','n','c','o','d','i','n','g',' ','c','o','n','v','e','r','s','i','o','n','\0'};
|
||||
static moo_ooch_t errstr_33[] = {'b','u','f','f','e','r',' ','f','u','l','l','\0'};
|
||||
static moo_ooch_t* errstr[] =
|
||||
{
|
||||
errstr_0, errstr_1, errstr_2, errstr_3, errstr_4, errstr_5, errstr_6, errstr_7,
|
||||
errstr_8, errstr_9, errstr_10, errstr_11, errstr_12, errstr_13, errstr_14, errstr_15,
|
||||
errstr_16, errstr_17, errstr_18, errstr_19, errstr_20, errstr_21, errstr_22, errstr_23,
|
||||
errstr_24, errstr_25, errstr_26, errstr_27, errstr_28, errstr_29, errstr_30, errstr_31,
|
||||
errstr_32
|
||||
errstr_32, errstr_33
|
||||
};
|
||||
|
||||
#if defined(MOO_INCLUDE_COMPILER)
|
||||
|
@ -3496,7 +3496,7 @@ static pf_t pftab[] =
|
||||
{ "Error_asString", { pf_error_as_string, 0, 0 } },
|
||||
|
||||
{ "MethodContext_goto:", { pf_context_goto, 1, 1 } },
|
||||
|
||||
|
||||
{ "Process_resume", { pf_process_resume, 0, 0 } },
|
||||
{ "Process_sp", { pf_process_sp, 0, 0 } },
|
||||
{ "Process_suspend", { pf_process_suspend, 0, 0 } },
|
||||
@ -3506,7 +3506,7 @@ static pf_t pftab[] =
|
||||
{ "SemaphoreGroup_addSemaphore:", { pf_semaphore_group_add_semaphore, 1, 1 } },
|
||||
{ "SemaphoreGroup_removeSemaphore:", { pf_semaphore_group_remove_semaphore, 1, 1 } },
|
||||
{ "SemaphoreGroup_wait", { pf_semaphore_group_wait, 0, 0 } },
|
||||
|
||||
|
||||
{ "Semaphore_signal", { pf_semaphore_signal, 0, 0 } },
|
||||
{ "Semaphore_signalAfterSecs:", { pf_semaphore_signal_timed, 1, 1 } },
|
||||
{ "Semaphore_signalAfterSecs:nanosecs:", { pf_semaphore_signal_timed, 2, 2 } },
|
||||
@ -3594,7 +3594,10 @@ static pf_t pftab[] =
|
||||
{ "_integer_ne", { pf_integer_ne, 1, 1 } },
|
||||
{ "_integer_negated", { pf_integer_negated, 0, 0 } },
|
||||
{ "_integer_rem", { pf_integer_rem, 1, 1 } },
|
||||
{ "_integer_sub", { pf_integer_sub, 1, 1 } }
|
||||
{ "_integer_sub", { pf_integer_sub, 1, 1 } },
|
||||
|
||||
{ "_utf8_seqlen", { moo_pf_utf8_seqlen, 0, 0 } },
|
||||
{ "_utf8_to_uc", { moo_pf_utf8_to_uc, 0, 0 } },
|
||||
};
|
||||
|
||||
moo_pfbase_t* moo_getpfnum (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len, moo_ooi_t* pfnum)
|
||||
|
@ -288,7 +288,8 @@
|
||||
/* __va_copy is available */
|
||||
#undef HAVE___VA_COPY
|
||||
|
||||
/* Define to the sub-directory where libtool stores uninstalled libraries. */
|
||||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
||||
*/
|
||||
#undef LT_OBJDIR
|
||||
|
||||
/* build release/debug */
|
||||
|
@ -1419,7 +1419,6 @@ moo_pfrc_t moo_pf_basic_shift (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs);
|
||||
moo_pfrc_t moo_pf_is_kind_of (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs);
|
||||
moo_pfrc_t moo_pf_responds_to (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs);
|
||||
|
||||
|
||||
/* ========================================================================= */
|
||||
/* pf-sys.c */
|
||||
/* ========================================================================= */
|
||||
@ -1476,6 +1475,14 @@ moo_pfrc_t moo_pf_smptr_put_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs);
|
||||
|
||||
moo_pfrc_t moo_pf_smptr_as_string (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs);
|
||||
|
||||
|
||||
/* ========================================================================= */
|
||||
/* pf-utf8.c */
|
||||
/* ========================================================================= */
|
||||
moo_pfrc_t moo_pf_utf8_seqlen (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs);
|
||||
moo_pfrc_t moo_pf_utf8_to_uc (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs);
|
||||
moo_pfrc_t moo_pf_uc_to_utf8 (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs);
|
||||
|
||||
/* TODO: remove the following debugging functions */
|
||||
/* ========================================================================= */
|
||||
/* debug.c */
|
||||
|
@ -84,6 +84,7 @@ enum moo_errnum_t
|
||||
MOO_EDIVBY0, /**< divide by zero */
|
||||
MOO_EIOERR, /**< I/O error */
|
||||
MOO_EECERR, /**< encoding conversion error */
|
||||
MOO_EECMORE, /**< insufficient data for encoding conversion */
|
||||
MOO_EBUFFULL, /**< buffer full */
|
||||
|
||||
#if defined(MOO_INCLUDE_COMPILER)
|
||||
|
98
moo/lib/pf-utf8.c
Normal file
98
moo/lib/pf-utf8.c
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2014-2018 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 WAfRRANTIES
|
||||
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 "moo-prv.h"
|
||||
|
||||
|
||||
moo_pfrc_t moo_pf_utf8_seqlen (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
moo_oop_t rcv;
|
||||
moo_uch_t uch;
|
||||
const moo_bch_t* utf8;
|
||||
moo_oow_t size;
|
||||
int n;
|
||||
|
||||
/* the receiver should be a byte array or the like. */
|
||||
rcv = MOO_STACK_GETRCV(moo, nargs);
|
||||
MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, rcv, moo->_byte_array));
|
||||
|
||||
utf8 = (const moo_bch_t*)MOO_OBJ_GET_BYTE_SLOT(rcv);
|
||||
size = MOO_OBJ_GET_SIZE(rcv);
|
||||
|
||||
|
||||
#if 0
|
||||
/* TODO: check the first byte and return bytes required */
|
||||
if ((n = moo_utf8_to_uc(utf8, size, &uch)) == 0)
|
||||
{
|
||||
/* invalid sequence */
|
||||
moo_seterrnum (moo, MOO_EECERR);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
#endif
|
||||
|
||||
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(n));
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
moo_pfrc_t moo_pf_utf8_to_uc (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
moo_oop_t rcv;
|
||||
moo_uch_t uch;
|
||||
const moo_bch_t* utf8;
|
||||
moo_oow_t size;
|
||||
int n;
|
||||
|
||||
/* the receiver should be a byte array or the like. */
|
||||
rcv = MOO_STACK_GETRCV(moo, nargs);
|
||||
MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, rcv, moo->_byte_array));
|
||||
|
||||
/* TODO: accept offset and size */
|
||||
utf8 = (const moo_bch_t*)MOO_OBJ_GET_BYTE_SLOT(rcv);
|
||||
size = MOO_OBJ_GET_SIZE(rcv);
|
||||
|
||||
if ((n = moo_utf8_to_uc(utf8, size, &uch)) == 0)
|
||||
{
|
||||
/* invalid sequence */
|
||||
moo_seterrnum (moo, MOO_EECERR);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
else if (n >= size)
|
||||
{
|
||||
/* incomplete sequence */
|
||||
moo_seterrnum (moo, MOO_EECMORE);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
MOO_STACK_SETRET(moo, nargs, MOO_CHAR_TO_OOP(uch));
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
moo_pfrc_t moo_pf_uc_to_utf8 (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
MOO_STACK_SETRET (moo, nargs, moo->_nil);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
Reference in New Issue
Block a user