added many charcter handling code
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2023-11-22 00:24:57 +09:00
parent 6a861d2db5
commit 3d47a99cd2
57 changed files with 24011 additions and 138 deletions

126
lib/utl.c
View File

@ -1,6 +1,4 @@
/*
* $Id$
*
Copyright (c) 2016-2018 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -848,43 +846,149 @@ HCL_INLINE int hcl_conv_ucstr_to_bcstr_with_cmgr (const hcl_uch_t* ucs, hcl_oow_
/* ----------------------------------------------------------------------- */
static hcl_cmgr_t utf8_cmgr =
static hcl_cmgr_t builtin_cmgr[] =
{
hcl_utf8_to_uc,
hcl_uc_to_utf8
/* keep the order aligned with hcl_cmgr_id_t values in <hcl-utl.h> */
{ hcl_utf8_to_uc, hcl_uc_to_utf8 },
{ hcl_utf16_to_uc, hcl_uc_to_utf16 },
{ hcl_mb8_to_uc, hcl_uc_to_mb8 }
};
hcl_cmgr_t* hcl_get_utf8_cmgr (void)
hcl_cmgr_t* hcl_get_cmgr_by_id (hcl_cmgr_id_t id)
{
return &utf8_cmgr;
return &builtin_cmgr[id];
}
static struct
{
const hcl_bch_t* name;
hcl_cmgr_id_t id;
} builtin_cmgr_tab[] =
{
{ "utf8", HCL_CMGR_UTF8 },
{ "utf16", HCL_CMGR_UTF16 },
{ "mb8", HCL_CMGR_MB8 }
};
hcl_cmgr_t* hcl_get_cmgr_by_bcstr (const hcl_bch_t* name)
{
if (name)
{
hcl_oow_t i;
for (i = 0; i < HCL_COUNTOF(builtin_cmgr_tab); i++)
{
if (hcl_comp_bcstr(name, builtin_cmgr_tab[i].name) == 0)
{
return &builtin_cmgr[builtin_cmgr_tab[i].id];
}
}
}
return HCL_NULL;
}
hcl_cmgr_t* hcl_get_cmgr_by_ucstr (const hcl_uch_t* name)
{
if (name)
{
hcl_oow_t i;
for (i = 0; i < HCL_COUNTOF(builtin_cmgr_tab); i++)
{
if (hcl_comp_ucstr_bcstr(name, builtin_cmgr_tab[i].name) == 0)
{
return &builtin_cmgr[builtin_cmgr_tab[i].id];
}
}
}
return HCL_NULL;
}
/* ----------------------------------------------------------------------- */
int hcl_conv_utf8_to_uchars (const hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_uch_t* ucs, hcl_oow_t* ucslen)
{
/* the source is length bound */
return hcl_conv_bchars_to_uchars_with_cmgr(bcs, bcslen, ucs, ucslen, &utf8_cmgr, 0);
return hcl_conv_bchars_to_uchars_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[HCL_CMGR_UTF8], 0);
}
int hcl_conv_uchars_to_utf8 (const hcl_uch_t* ucs, hcl_oow_t* ucslen, hcl_bch_t* bcs, hcl_oow_t* bcslen)
{
/* length bound */
return hcl_conv_uchars_to_bchars_with_cmgr(ucs, ucslen, bcs, bcslen, &utf8_cmgr);
return hcl_conv_uchars_to_bchars_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[HCL_CMGR_UTF8]);
}
int hcl_conv_utf8_to_ucstr (const hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_uch_t* ucs, hcl_oow_t* ucslen)
{
/* null-terminated. */
return hcl_conv_bcstr_to_ucstr_with_cmgr(bcs, bcslen, ucs, ucslen, &utf8_cmgr, 0);
return hcl_conv_bcstr_to_ucstr_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[HCL_CMGR_UTF8], 0);
}
int hcl_conv_ucstr_to_utf8 (const hcl_uch_t* ucs, hcl_oow_t* ucslen, hcl_bch_t* bcs, hcl_oow_t* bcslen)
{
/* null-terminated */
return hcl_conv_ucstr_to_bcstr_with_cmgr(ucs, ucslen, bcs, bcslen, &utf8_cmgr);
return hcl_conv_ucstr_to_bcstr_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[HCL_CMGR_UTF8]);
}
/* ----------------------------------------------------------------------- */
int hcl_conv_utf16_to_uchars (const hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_uch_t* ucs, hcl_oow_t* ucslen)
{
/* the source is length bound */
return hcl_conv_bchars_to_uchars_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[HCL_CMGR_UTF16], 0);
}
int hcl_conv_uchars_to_utf16 (const hcl_uch_t* ucs, hcl_oow_t* ucslen, hcl_bch_t* bcs, hcl_oow_t* bcslen)
{
/* length bound */
return hcl_conv_uchars_to_bchars_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[HCL_CMGR_UTF16]);
}
int hcl_conv_utf16_to_ucstr (const hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_uch_t* ucs, hcl_oow_t* ucslen)
{
/* null-terminated. */
return hcl_conv_bcstr_to_ucstr_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[HCL_CMGR_UTF16], 0);
}
int hcl_conv_ucstr_to_utf16 (const hcl_uch_t* ucs, hcl_oow_t* ucslen, hcl_bch_t* bcs, hcl_oow_t* bcslen)
{
/* null-terminated */
return hcl_conv_ucstr_to_bcstr_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[HCL_CMGR_UTF16]);
}
/* ----------------------------------------------------------------------- */
int hcl_conv_mb8_to_uchars (const hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_uch_t* ucs, hcl_oow_t* ucslen)
{
/* the source is length bound */
return hcl_conv_bchars_to_uchars_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[HCL_CMGR_MB8], 0);
}
int hcl_conv_uchars_to_mb8 (const hcl_uch_t* ucs, hcl_oow_t* ucslen, hcl_bch_t* bcs, hcl_oow_t* bcslen)
{
/* length bound */
return hcl_conv_uchars_to_bchars_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[HCL_CMGR_MB8]);
}
int hcl_conv_mb8_to_ucstr (const hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_uch_t* ucs, hcl_oow_t* ucslen)
{
/* null-terminated. */
return hcl_conv_bcstr_to_ucstr_with_cmgr(bcs, bcslen, ucs, ucslen, &builtin_cmgr[HCL_CMGR_MB8], 0);
}
int hcl_conv_ucstr_to_mb8 (const hcl_uch_t* ucs, hcl_oow_t* ucslen, hcl_bch_t* bcs, hcl_oow_t* bcslen)
{
/* null-terminated */
return hcl_conv_ucstr_to_bcstr_with_cmgr(ucs, ucslen, bcs, bcslen, &builtin_cmgr[HCL_CMGR_MB8]);
}
/* ----------------------------------------------------------------------- */
/* ----------------------------------------------------------------------- */
int hcl_convbtouchars (hcl_t* hcl, const hcl_bch_t* bcs, hcl_oow_t* bcslen, hcl_uch_t* ucs, hcl_oow_t* ucslen)
{
/* length bound */