added moo_get_cmgr_by_id(), moo_get_cmgr_by_name(), and other similar functions

changed the default source input handler to take the @postfix as the encoding specifier
This commit is contained in:
hyunghwan.chung 2019-05-14 10:22:37 +00:00
parent 44b121ee50
commit 2b2ffb5521
8 changed files with 180 additions and 103 deletions

View File

@ -202,11 +202,11 @@ int main (int argc, char* argv[])
moo_oow_t tab_size; moo_oow_t tab_size;
tab_size = 5000; tab_size = 5000;
moo_setoption (moo, MOO_SYMTAB_SIZE, &tab_size); moo_setoption (moo, MOO_OPTION_SYMTAB_SIZE, &tab_size);
tab_size = 5000; tab_size = 5000;
moo_setoption (moo, MOO_SYSDIC_SIZE, &tab_size); moo_setoption (moo, MOO_OPTION_SYSDIC_SIZE, &tab_size);
tab_size = 600; tab_size = 600;
moo_setoption (moo, MOO_PROCSTK_SIZE, &tab_size); moo_setoption (moo, MOO_OPTION_PROCSTK_SIZE, &tab_size);
} }
if (moo_ignite(moo, memsize) <= -1) if (moo_ignite(moo, memsize) <= -1)
@ -226,7 +226,6 @@ int main (int argc, char* argv[])
for (i = opt.ind; i < argc; i++) for (i = opt.ind; i < argc; i++)
{ {
moo_iostd_t in; moo_iostd_t in;
#if 1 #if 1
in.type = MOO_IOSTD_FILEB; in.type = MOO_IOSTD_FILEB;
in.u.fileb.path = argv[i]; in.u.fileb.path = argv[i];

View File

@ -4835,7 +4835,7 @@ static MOO_INLINE int do_return (moo_t* moo, moo_oob_t bcode, moo_oop_t return_v
/* the stack contains the final return value so the stack pointer must be 0. */ /* the stack contains the final return value so the stack pointer must be 0. */
MOO_ASSERT (moo, moo->sp == 0); MOO_ASSERT (moo, moo->sp == 0);
if (moo->option.trait & MOO_AWAIT_PROCS) if (moo->option.trait & MOO_TRAIT_AWAIT_PROCS)
{ {
terminate_process (moo, moo->processor->active); terminate_process (moo, moo->processor->active);
} }

View File

@ -283,6 +283,16 @@
#define MOO_HASH_UCSTR(hv, ptr) MOO_HASH_VPTR(hv, ptr, const moo_uch_t) #define MOO_HASH_UCSTR(hv, ptr) MOO_HASH_VPTR(hv, ptr, const moo_uch_t)
#define MOO_HASH_MORE_UCSTR(hv, ptr) MOO_HASH_MORE_VPTR(hv, ptr, const moo_uch_t) #define MOO_HASH_MORE_UCSTR(hv, ptr) MOO_HASH_MORE_VPTR(hv, ptr, const moo_uch_t)
/* =========================================================================
* CMGR
* ========================================================================= */
enum moo_cmgr_id_t
{
MOO_CMGR_UTF8,
MOO_CMGR_UTF16,
MOO_CMGR_MB8,
};
typedef enum moo_cmgr_id_t moo_cmgr_id_t;
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" { extern "C" {
@ -590,10 +600,30 @@ MOO_EXPORT int moo_conv_uchars_to_bchars_with_cmgr (
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
MOO_EXPORT moo_cmgr_t* moo_get_utf8_cmgr ( MOO_EXPORT moo_cmgr_t* moo_get_cmgr_by_id (
void moo_cmgr_id_t id
); );
MOO_EXPORT moo_cmgr_t* moo_get_cmgr_by_bcstr (
const moo_bch_t* name
);
MOO_EXPORT moo_cmgr_t* moo_get_cmgr_by_ucstr (
const moo_uch_t* name
);
#if defined(MOO_OOCH_IS_UCH)
# define moo_get_cmgr_by_name(name) moo_get_cmgr_by_ucstr(name)
#else
# define moo_get_cmgr_by_name(name) moo_get_cmgr_by_bcstr(name)
#endif
#define moo_get_utf8_cmgr() moo_get_cmgr_by_id(MOO_CMGR_UTF8)
#define moo_get_utf16_cmgr() moo_get_cmgr_by_id(MOO_CMGR_UTF16)
#define moo_get_mb8_cmgr() moo_get_cmgr_by_id(MOO_CMGR_MB8)
/* ------------------------------------------------------------------------- */
/** /**
* The moo_conv_uchars_to_utf8() function converts a unicode character string \a ucs * The moo_conv_uchars_to_utf8() function converts a unicode character string \a ucs
* to a UTF8 string and writes it into the buffer pointed to by \a bcs, but * to a UTF8 string and writes it into the buffer pointed to by \a bcs, but
@ -691,10 +721,6 @@ MOO_EXPORT moo_oow_t moo_utf8_to_uc (
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
MOO_EXPORT moo_cmgr_t* moo_get_utf16_cmgr (
void
);
MOO_EXPORT int moo_conv_uchars_to_utf16 ( MOO_EXPORT int moo_conv_uchars_to_utf16 (
const moo_uch_t* ucs, const moo_uch_t* ucs,
moo_oow_t* ucslen, moo_oow_t* ucslen,
@ -738,10 +764,6 @@ MOO_EXPORT moo_oow_t moo_utf16_to_uc (
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
MOO_EXPORT moo_cmgr_t* moo_get_mb8_cmgr (
void
);
MOO_EXPORT int moo_conv_uchars_to_mb8 ( MOO_EXPORT int moo_conv_uchars_to_mb8 (
const moo_uch_t* ucs, const moo_uch_t* ucs,
moo_oow_t* ucslen, moo_oow_t* ucslen,

View File

@ -297,22 +297,22 @@ int moo_setoption (moo_t* moo, moo_option_t id, const void* value)
{ {
switch (id) switch (id)
{ {
case MOO_TRAIT: case MOO_OPTION_TRAIT:
moo->option.trait = *(moo_bitmask_t*)value; moo->option.trait = *(moo_bitmask_t*)value;
#if defined(MOO_BUILD_DEBUG) #if defined(MOO_BUILD_DEBUG)
moo->option.karatsuba_cutoff = ((moo->option.trait & MOO_DEBUG_BIGINT)? MOO_KARATSUBA_CUTOFF_DEBUG: MOO_KARATSUBA_CUTOFF); moo->option.karatsuba_cutoff = ((moo->option.trait & MOO_TRAIT_DEBUG_BIGINT)? MOO_KARATSUBA_CUTOFF_DEBUG: MOO_KARATSUBA_CUTOFF);
#endif #endif
return 0; return 0;
case MOO_LOG_MASK: case MOO_OPTION_LOG_MASK:
moo->option.log_mask = *(moo_bitmask_t*)value; moo->option.log_mask = *(moo_bitmask_t*)value;
return 0; return 0;
case MOO_LOG_MAXCAPA: case MOO_OPTION_LOG_MAXCAPA:
moo->option.log_maxcapa = *(moo_oow_t*)value; moo->option.log_maxcapa = *(moo_oow_t*)value;
return 0; return 0;
case MOO_SYMTAB_SIZE: case MOO_OPTION_SYMTAB_SIZE:
{ {
moo_oow_t w; moo_oow_t w;
@ -323,7 +323,7 @@ int moo_setoption (moo_t* moo, moo_option_t id, const void* value)
return 0; return 0;
} }
case MOO_SYSDIC_SIZE: case MOO_OPTION_SYSDIC_SIZE:
{ {
moo_oow_t w; moo_oow_t w;
@ -334,7 +334,7 @@ int moo_setoption (moo_t* moo, moo_option_t id, const void* value)
return 0; return 0;
} }
case MOO_PROCSTK_SIZE: case MOO_OPTION_PROCSTK_SIZE:
{ {
moo_oow_t w; moo_oow_t w;
@ -345,7 +345,7 @@ int moo_setoption (moo_t* moo, moo_option_t id, const void* value)
return 0; return 0;
} }
case MOO_MOD_INCTX: case MOO_OPTION_MOD_INCTX:
moo->option.mod_inctx = *(void**)value; moo->option.mod_inctx = *(void**)value;
return 0; return 0;
} }
@ -357,33 +357,33 @@ einval:
int moo_getoption (moo_t* moo, moo_option_t id, void* value) int moo_getoption (moo_t* moo, moo_option_t id, void* value)
{ {
switch (id) switch (id)
{ {
case MOO_TRAIT: case MOO_OPTION_TRAIT:
*(moo_bitmask_t*)value = moo->option.trait; *(moo_bitmask_t*)value = moo->option.trait;
return 0; return 0;
case MOO_LOG_MASK: case MOO_OPTION_LOG_MASK:
*(moo_bitmask_t*)value = moo->option.log_mask; *(moo_bitmask_t*)value = moo->option.log_mask;
return 0; return 0;
case MOO_LOG_MAXCAPA: case MOO_OPTION_LOG_MAXCAPA:
*(moo_oow_t*)value = moo->option.log_maxcapa; *(moo_oow_t*)value = moo->option.log_maxcapa;
return 0; return 0;
case MOO_SYMTAB_SIZE: case MOO_OPTION_SYMTAB_SIZE:
*(moo_oow_t*)value = moo->option.dfl_symtab_size; *(moo_oow_t*)value = moo->option.dfl_symtab_size;
return 0; return 0;
case MOO_SYSDIC_SIZE: case MOO_OPTION_SYSDIC_SIZE:
*(moo_oow_t*)value = moo->option.dfl_sysdic_size; *(moo_oow_t*)value = moo->option.dfl_sysdic_size;
return 0; return 0;
case MOO_PROCSTK_SIZE: case MOO_OPTION_PROCSTK_SIZE:
*(moo_oow_t*)value = moo->option.dfl_procstk_size; *(moo_oow_t*)value = moo->option.dfl_procstk_size;
return 0; return 0;
case MOO_MOD_INCTX: case MOO_OPTION_MOD_INCTX:
*(void**)value = moo->option.mod_inctx; *(void**)value = moo->option.mod_inctx;
return 0; return 0;
}; };
@ -392,14 +392,14 @@ int moo_getoption (moo_t* moo, moo_option_t id, void* value)
return -1; return -1;
} }
moo_evtcb_t* moo_regevtcb (moo_t* moo, moo_evtcb_t* tmpl) moo_evtcb_t* moo_regevtcb (moo_t* moo, moo_evtcb_t* cb)
{ {
moo_evtcb_t* actual; moo_evtcb_t* actual;
actual = (moo_evtcb_t*)moo_allocmem(moo, MOO_SIZEOF(*actual)); actual = (moo_evtcb_t*)moo_allocmem(moo, MOO_SIZEOF(*actual));
if (!actual) return MOO_NULL; if (!actual) return MOO_NULL;
*actual = *tmpl; *actual = *cb;
actual->next = moo->evtcb_list; actual->next = moo->evtcb_list;
actual->prev = MOO_NULL; actual->prev = MOO_NULL;
moo->evtcb_list = actual; moo->evtcb_list = actual;

View File

@ -95,13 +95,13 @@ typedef enum moo_errnum_t moo_errnum_t;
enum moo_option_t enum moo_option_t
{ {
MOO_TRAIT, MOO_OPTION_TRAIT,
MOO_LOG_MASK, MOO_OPTION_LOG_MASK,
MOO_LOG_MAXCAPA, MOO_OPTION_LOG_MAXCAPA,
MOO_SYMTAB_SIZE, /* default system table size */ MOO_OPTION_SYMTAB_SIZE, /* default system table size */
MOO_SYSDIC_SIZE, /* default system dictionary size */ MOO_OPTION_SYSDIC_SIZE, /* default system dictionary size */
MOO_PROCSTK_SIZE, /* default process stack size */ MOO_OPTION_PROCSTK_SIZE, /* default process stack size */
MOO_MOD_INCTX MOO_OPTION_MOD_INCTX
}; };
typedef enum moo_option_t moo_option_t; typedef enum moo_option_t moo_option_t;
@ -119,15 +119,15 @@ typedef enum moo_option_dflval_t moo_option_dflval_t;
enum moo_trait_t enum moo_trait_t
{ {
MOO_DEBUG_GC = (1u << 0), MOO_TRAIT_DEBUG_GC = (1u << 0),
MOO_DEBUG_BIGINT = (1u << 1), MOO_TRAIT_DEBUG_BIGINT = (1u << 1),
/* perform no garbage collection when the heap is full. /* perform no garbage collection when the heap is full.
* you still can use moo_gc() explicitly. */ * you still can use moo_gc() explicitly. */
MOO_NOGC = (1u << 8), MOO_TRAIT_NOGC = (1u << 8),
/* wait for running process when exiting from the main method */ /* wait for running process when exiting from the main method */
MOO_AWAIT_PROCS = (1u << 9) MOO_TRAIT_AWAIT_PROCS = (1u << 9)
}; };
typedef enum moo_trait_t moo_trait_t; typedef enum moo_trait_t moo_trait_t;
@ -1940,7 +1940,7 @@ MOO_EXPORT int moo_setoption (
MOO_EXPORT moo_evtcb_t* moo_regevtcb ( MOO_EXPORT moo_evtcb_t* moo_regevtcb (
moo_t* moo, moo_t* moo,
moo_evtcb_t* tmpl moo_evtcb_t* cb
); );
MOO_EXPORT void moo_deregevtcb ( MOO_EXPORT void moo_deregevtcb (
@ -1950,7 +1950,7 @@ MOO_EXPORT void moo_deregevtcb (
/** /**
* The moo_gc() function performs garbage collection. * The moo_gc() function performs garbage collection.
* It is not affected by #MOO_NOGC. * It is not affected by #MOO_TRAIT_NOGC.
*/ */
MOO_EXPORT void moo_gc ( MOO_EXPORT void moo_gc (
moo_t* moo moo_t* moo

View File

@ -31,7 +31,7 @@ void* moo_allocbytes (moo_t* moo, moo_oow_t size)
moo_uint8_t* ptr; moo_uint8_t* ptr;
#if defined(MOO_BUILD_DEBUG) #if defined(MOO_BUILD_DEBUG)
if ((moo->option.trait & MOO_DEBUG_GC) && !(moo->option.trait & MOO_NOGC)) moo_gc (moo); if ((moo->option.trait & MOO_TRAIT_DEBUG_GC) && !(moo->option.trait & MOO_TRAIT_NOGC)) moo_gc (moo);
#endif #endif
if (MOO_UNLIKELY(moo->igniting)) if (MOO_UNLIKELY(moo->igniting))
@ -42,7 +42,7 @@ void* moo_allocbytes (moo_t* moo, moo_oow_t size)
else else
{ {
ptr = (moo_uint8_t*)moo_allocheapspace(moo, &moo->heap->curspace, size); ptr = (moo_uint8_t*)moo_allocheapspace(moo, &moo->heap->curspace, size);
if (!ptr && moo->errnum == MOO_EOOMEM && !(moo->option.trait & MOO_NOGC)) if (!ptr && moo->errnum == MOO_EOOMEM && !(moo->option.trait & MOO_TRAIT_NOGC))
{ {
moo_gc (moo); moo_gc (moo);
MOO_LOG4 (moo, MOO_LOG_GC | MOO_LOG_INFO, MOO_LOG4 (moo, MOO_LOG_GC | MOO_LOG_INFO,

View File

@ -258,6 +258,7 @@ struct bb_t
FILE* fp; FILE* fp;
moo_bch_t* fn; moo_bch_t* fn;
moo_cmgr_t* cmgr;
}; };
#if defined(USE_SELECT) #if defined(USE_SELECT)
@ -431,6 +432,7 @@ static MOO_INLINE moo_ooi_t open_input (moo_t* moo, moo_ioarg_t* arg)
{ {
xtn_t* xtn = GET_XTN(moo); xtn_t* xtn = GET_XTN(moo);
bb_t* bb = MOO_NULL; bb_t* bb = MOO_NULL;
moo_bch_t* at;
/* TOOD: support predefined include directory as well */ /* TOOD: support predefined include directory as well */
if (arg->includer) if (arg->includer)
@ -480,6 +482,7 @@ static MOO_INLINE moo_ooi_t open_input (moo_t* moo, moo_ioarg_t* arg)
bb->fn = (moo_bch_t*)(bb + 1); bb->fn = (moo_bch_t*)(bb + 1);
moo_copy_bcstr (bb->fn, bcslen + 1, xtn->in->u.fileb.path); moo_copy_bcstr (bb->fn, bcslen + 1, xtn->in->u.fileb.path);
break; break;
#if defined(MOO_OOCH_IS_UCH) #if defined(MOO_OOCH_IS_UCH)
@ -499,6 +502,7 @@ static MOO_INLINE moo_ooi_t open_input (moo_t* moo, moo_ioarg_t* arg)
bb->fn = (moo_bch_t*)(bb + 1); bb->fn = (moo_bch_t*)(bb + 1);
bcslen += 1; bcslen += 1;
moo_convutobcstr (moo, xtn->in->u.fileu.path, &ucslen, bb->fn, &bcslen); moo_convutobcstr (moo, xtn->in->u.fileu.path, &ucslen, bb->fn, &bcslen);
break; break;
default: default:
@ -507,6 +511,23 @@ static MOO_INLINE moo_ooi_t open_input (moo_t* moo, moo_ioarg_t* arg)
} }
} }
/* the path name can be appened with @encoding */
at = moo_find_bchar_in_bcstr(bb->fn, '@');
if (at && at[1] != '\0')
{
*at = '\0';
bb->cmgr = moo_get_cmgr_by_bcstr(at + 1);
if (!bb->cmgr) bb->cmgr = moo_getcmgr(moo);
}
else if (arg->includer)
{
bb->cmgr = ((bb_t*)arg->includer->handle)->cmgr;
}
else
{
bb->cmgr = moo_getcmgr(moo);
}
/* TODO: support _wfopen or the like */ /* TODO: support _wfopen or the like */
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__) #if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
bb->fp = fopen(bb->fn, "rb"); bb->fp = fopen(bb->fn, "rb");
@ -575,8 +596,13 @@ static MOO_INLINE moo_ooi_t read_input (moo_t* moo, moo_ioarg_t* arg)
ucslen = MOO_COUNTOF(arg->buf); ucslen = MOO_COUNTOF(arg->buf);
/* TODO: use the default cmgr first. /* TODO: use the default cmgr first.
* then fallback to utf8, mb8, etc */ * then fallback to utf8, mb8, etc */
x = moo_convbtooochars(moo, bb->buf, &bcslen, arg->buf, &ucslen); /*x = moo_convbtooochars(moo, bb->buf, &bcslen, arg->buf, &ucslen);*/
if (x <= -1 /*&& ucslen <= 0 */) return -1; x = moo_conv_bchars_to_uchars_with_cmgr(bb->buf, &bcslen, arg->buf, &ucslen, bb->cmgr, 0);
if (x <= -1 /*&& ucslen <= 0 */)
{
moo_seterrbfmt (moo, (x == -2)? MOO_EBUFFULL: MOO_EECERR, "unable to convert source input - %.*hs", bcslen, bb->buf);
return -1;
}
/* if ucslen is greater than 0, i see that some characters have been /* if ucslen is greater than 0, i see that some characters have been
* converted properly */ * converted properly */
@ -3235,8 +3261,8 @@ static struct
moo_bitmask_t mask; moo_bitmask_t mask;
} dbg_mask_table[] = } dbg_mask_table[] =
{ {
{ "bigint", MOO_DEBUG_BIGINT }, { "bigint", MOO_TRAIT_DEBUG_BIGINT },
{ "gc", MOO_DEBUG_GC } { "gc", MOO_TRAIT_DEBUG_GC }
}; };
static int parse_logoptb (moo_t* moo, const moo_bch_t* str, moo_oow_t* xpathlen, moo_bitmask_t* xlogmask) static int parse_logoptb (moo_t* moo, const moo_bch_t* str, moo_oow_t* xpathlen, moo_bitmask_t* xlogmask)
@ -3377,7 +3403,7 @@ static int handle_logoptb (moo_t* moo, const moo_bch_t* str)
#endif #endif
if (str != xstr) moo_freemem (moo, xstr); if (str != xstr) moo_freemem (moo, xstr);
moo_setoption (moo, MOO_LOG_MASK, &logmask); moo_setoption (moo, MOO_OPTION_LOG_MASK, &logmask);
return 0; return 0;
} }
@ -3407,7 +3433,7 @@ static int handle_logoptu (moo_t* moo, const moo_uch_t* str)
#endif #endif
moo_freemem (moo, xstr); moo_freemem (moo, xstr);
moo_setoption (moo, MOO_LOG_MASK, &logmask); moo_setoption (moo, MOO_OPTION_LOG_MASK, &logmask);
return 0; return 0;
} }
@ -3441,9 +3467,9 @@ static int handle_dbgoptb (moo_t* moo, const moo_bch_t* str)
} }
while (cm); while (cm);
moo_getoption (moo, MOO_TRAIT, &trait); moo_getoption (moo, MOO_OPTION_TRAIT, &trait);
trait |= dbgopt; trait |= dbgopt;
moo_setoption (moo, MOO_TRAIT, &trait); moo_setoption (moo, MOO_OPTION_TRAIT, &trait);
return 0; return 0;
} }
@ -3478,9 +3504,9 @@ static int handle_dbgoptu (moo_t* moo, const moo_uch_t* str)
} }
while (cm); while (cm);
moo_getoption (moo, MOO_TRAIT, &trait); moo_getoption (moo, MOO_OPTION_TRAIT, &trait);
trait |= dbgopt; trait |= dbgopt;
moo_setoption (moo, MOO_TRAIT, &trait); moo_setoption (moo, MOO_OPTION_TRAIT, &trait);
return 0; return 0;
} }
@ -3612,15 +3638,15 @@ static void fini_moo (moo_t* moo)
{ {
moo_bitmask_t bm = 0; moo_bitmask_t bm = 0;
moo_getoption (moo, MOO_TRAIT, &bm); moo_getoption (moo, MOO_OPTION_TRAIT, &bm);
/*bm |= MOO_NOGC;*/ /*bm |= MOO_TRAIT_NOGC;*/
bm |= MOO_AWAIT_PROCS; bm |= MOO_TRAIT_AWAIT_PROCS;
moo_setoption (moo, MOO_TRAIT, &bm); moo_setoption (moo, MOO_OPTION_TRAIT, &bm);
/* disable GC logs */ /* disable GC logs */
moo_getoption (moo, MOO_LOG_MASK, &bm); moo_getoption (moo, MOO_OPTION_LOG_MASK, &bm);
bm = ~MOO_LOG_GC; bm = ~MOO_LOG_GC;
moo_setoption (moo, MOO_LOG_MASK, &bm); moo_setoption (moo, MOO_OPTION_LOG_MASK, &bm);
} }
if (handle_cfg_options(moo, cfg) <= -1) if (handle_cfg_options(moo, cfg) <= -1)

View File

@ -734,113 +734,143 @@ MOO_INLINE int moo_conv_ucstr_to_bcstr_with_cmgr (
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static moo_cmgr_t utf8_cmgr = static moo_cmgr_t builtin_cmgr[] =
{ {
moo_utf8_to_uc, /* keep the order aligned with moo_cmgr_id_t values in <moo-utl.h> */
moo_uc_to_utf8 { moo_utf8_to_uc, moo_uc_to_utf8 },
{ moo_utf16_to_uc, moo_uc_to_utf16 },
{ moo_mb8_to_uc, moo_uc_to_mb8 }
}; };
moo_cmgr_t* moo_get_utf8_cmgr (void) moo_cmgr_t* moo_get_cmgr_by_id (moo_cmgr_id_t id)
{ {
return &utf8_cmgr; return &builtin_cmgr[id];
} }
static struct
{
const moo_bch_t* name;
moo_cmgr_id_t id;
} builtin_cmgr_tab[] =
{
{ "utf8", MOO_CMGR_UTF8 },
{ "utf16", MOO_CMGR_UTF16 },
{ "mb8", MOO_CMGR_MB8 }
};
moo_cmgr_t* moo_get_cmgr_by_bcstr (const moo_bch_t* name)
{
if (name)
{
moo_oow_t i;
for (i = 0; i < MOO_COUNTOF(builtin_cmgr_tab); i++)
{
if (moo_comp_bcstr(name, builtin_cmgr_tab[i].name) == 0)
{
return &builtin_cmgr[builtin_cmgr_tab[i].id];
}
}
}
return MOO_NULL;
}
moo_cmgr_t* moo_get_cmgr_by_ucstr (const moo_uch_t* name)
{
if (name)
{
moo_oow_t i;
for (i = 0; i < MOO_COUNTOF(builtin_cmgr_tab); i++)
{
if (moo_comp_ucstr_bcstr(name, builtin_cmgr_tab[i].name) == 0)
{
return &builtin_cmgr[builtin_cmgr_tab[i].id];
}
}
}
return MOO_NULL;
}
/* ----------------------------------------------------------------------- */
int moo_conv_utf8_to_uchars (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen) int moo_conv_utf8_to_uchars (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen)
{ {
/* the source is length bound */ /* the source is length bound */
return moo_conv_bchars_to_uchars_with_cmgr(bcs, bcslen, ucs, ucslen, &utf8_cmgr, 0); return moo_conv_bchars_to_uchars_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[MOO_CMGR_UTF8], 0);
} }
int moo_conv_uchars_to_utf8 (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen) int moo_conv_uchars_to_utf8 (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen)
{ {
/* length bound */ /* length bound */
return moo_conv_uchars_to_bchars_with_cmgr(ucs, ucslen, bcs, bcslen, &utf8_cmgr); return moo_conv_uchars_to_bchars_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[MOO_CMGR_UTF8]);
} }
int moo_conv_utf8_to_ucstr (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen) int moo_conv_utf8_to_ucstr (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen)
{ {
/* null-terminated. */ /* null-terminated. */
return moo_conv_bcstr_to_ucstr_with_cmgr(bcs, bcslen, ucs, ucslen, &utf8_cmgr, 0); return moo_conv_bcstr_to_ucstr_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[MOO_CMGR_UTF8], 0);
} }
int moo_conv_ucstr_to_utf8 (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen) int moo_conv_ucstr_to_utf8 (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen)
{ {
/* null-terminated */ /* null-terminated */
return moo_conv_ucstr_to_bcstr_with_cmgr(ucs, ucslen, bcs, bcslen, &utf8_cmgr); return moo_conv_ucstr_to_bcstr_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[MOO_CMGR_UTF8]);
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static moo_cmgr_t utf16_cmgr =
{
moo_utf16_to_uc,
moo_uc_to_utf16
};
moo_cmgr_t* moo_get_utf16_cmgr (void)
{
return &utf16_cmgr;
}
int moo_conv_utf16_to_uchars (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen) int moo_conv_utf16_to_uchars (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen)
{ {
/* the source is length bound */ /* the source is length bound */
return moo_conv_bchars_to_uchars_with_cmgr(bcs, bcslen, ucs, ucslen, &utf16_cmgr, 0); return moo_conv_bchars_to_uchars_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[MOO_CMGR_UTF16], 0);
} }
int moo_conv_uchars_to_utf16 (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen) int moo_conv_uchars_to_utf16 (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen)
{ {
/* length bound */ /* length bound */
return moo_conv_uchars_to_bchars_with_cmgr(ucs, ucslen, bcs, bcslen, &utf16_cmgr); return moo_conv_uchars_to_bchars_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[MOO_CMGR_UTF16]);
} }
int moo_conv_utf16_to_ucstr (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen) int moo_conv_utf16_to_ucstr (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen)
{ {
/* null-terminated. */ /* null-terminated. */
return moo_conv_bcstr_to_ucstr_with_cmgr(bcs, bcslen, ucs, ucslen, &utf16_cmgr, 0); return moo_conv_bcstr_to_ucstr_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[MOO_CMGR_UTF16], 0);
} }
int moo_conv_ucstr_to_utf16 (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen) int moo_conv_ucstr_to_utf16 (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen)
{ {
/* null-terminated */ /* null-terminated */
return moo_conv_ucstr_to_bcstr_with_cmgr(ucs, ucslen, bcs, bcslen, &utf16_cmgr); return moo_conv_ucstr_to_bcstr_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[MOO_CMGR_UTF16]);
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static moo_cmgr_t mb8_cmgr =
{
moo_mb8_to_uc,
moo_uc_to_mb8
};
moo_cmgr_t* moo_get_mb8_cmgr (void)
{
return &mb8_cmgr;
}
int moo_conv_mb8_to_uchars (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen) int moo_conv_mb8_to_uchars (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen)
{ {
/* the source is length bound */ /* the source is length bound */
return moo_conv_bchars_to_uchars_with_cmgr(bcs, bcslen, ucs, ucslen, &mb8_cmgr, 0); return moo_conv_bchars_to_uchars_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[MOO_CMGR_MB8], 0);
} }
int moo_conv_uchars_to_mb8 (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen) int moo_conv_uchars_to_mb8 (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen)
{ {
/* length bound */ /* length bound */
return moo_conv_uchars_to_bchars_with_cmgr(ucs, ucslen, bcs, bcslen, &mb8_cmgr); return moo_conv_uchars_to_bchars_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[MOO_CMGR_MB8]);
} }
int moo_conv_mb8_to_ucstr (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen) int moo_conv_mb8_to_ucstr (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen)
{ {
/* null-terminated. */ /* null-terminated. */
return moo_conv_bcstr_to_ucstr_with_cmgr(bcs, bcslen, ucs, ucslen, &mb8_cmgr, 0); return moo_conv_bcstr_to_ucstr_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[MOO_CMGR_MB8], 0);
} }
int moo_conv_ucstr_to_mb8 (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen) int moo_conv_ucstr_to_mb8 (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen)
{ {
/* null-terminated */ /* null-terminated */
return moo_conv_ucstr_to_bcstr_with_cmgr(ucs, ucslen, bcs, bcslen, &mb8_cmgr); return moo_conv_ucstr_to_bcstr_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[MOO_CMGR_MB8]);
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */