split some common files
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-10-15 16:36:25 +09:00
parent 955b734a79
commit 169c626819
15 changed files with 364 additions and 454 deletions

View File

@ -361,18 +361,6 @@
#define HCL_HASH_UCSTR(hv, ptr) HCL_HASH_VPTR(hv, ptr, const hcl_uch_t)
#define HCL_HASH_MORE_UCSTR(hv, ptr) HCL_HASH_MORE_VPTR(hv, ptr, const hcl_uch_t)
/* =========================================================================
* CMGR
* ========================================================================= */
enum hcl_cmgr_id_t
{
HCL_CMGR_UTF8,
HCL_CMGR_UTF16,
HCL_CMGR_MB8
};
typedef enum hcl_cmgr_id_t hcl_cmgr_id_t;
/* =========================================================================
* PATH-RELATED MACROS
* ========================================================================= */
@ -452,132 +440,6 @@ static HCL_INLINE hcl_oow_t hcl_hash_liwords(const hcl_liw_t* ptr, hcl_oow_t len
# define hcl_hash_oochars(ptr,len) hcl_hash_bchars(ptr,len)
#endif
/* ------------------------------------------------------------------------- */
HCL_EXPORT hcl_cmgr_t* hcl_get_utf8_cmgr (
void
);
HCL_EXPORT hcl_cmgr_t* hcl_get_cmgr_by_id (
hcl_cmgr_id_t id
);
HCL_EXPORT hcl_cmgr_t* hcl_get_cmgr_by_bcstr (
const hcl_bch_t* name
);
HCL_EXPORT hcl_cmgr_t* hcl_get_cmgr_by_ucstr (
const hcl_uch_t* name
);
#if defined(HCL_OOCH_IS_UCH)
# define hcl_get_cmgr_by_name(name) hcl_get_cmgr_by_ucstr(name)
#else
# define hcl_get_cmgr_by_name(name) hcl_get_cmgr_by_bcstr(name)
#endif
#define hcl_get_utf8_cmgr() hcl_get_cmgr_by_id(HCL_CMGR_UTF8)
#define hcl_get_utf16_cmgr() hcl_get_cmgr_by_id(HCL_CMGR_UTF16)
#define hcl_get_mb8_cmgr() hcl_get_cmgr_by_id(HCL_CMGR_MB8)
/**
* The hcl_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
* not more than \a bcslen bytes including the terminating null.
*
* Upon return, \a bcslen is modified to the actual number of bytes written to
* \a bcs excluding the terminating null; \a ucslen is modified to the number of
* wide characters converted.
*
* You may pass #HCL_NULL for \a bcs to dry-run conversion or to get the
* required buffer size for conversion. -2 is never returned in this case.
*
* \return
* - 0 on full conversion,
* - -1 on no or partial conversion for an illegal character encountered,
* - -2 on no or partial conversion for a small buffer.
*
* \code
* const hcl_uch_t ucs[] = { 'H', 'e', 'l', 'l', 'o' };
* hcl_bch_t bcs[10];
* hcl_oow_t ucslen = 5;
* hcl_oow_t bcslen = HCL_COUNTOF(bcs);
* n = hcl_conv_uchars_to_utf8 (ucs, &ucslen, bcs, &bcslen);
* if (n <= -1)
* {
* // conversion error
* }
* \endcode
*/
HCL_EXPORT int hcl_conv_uchars_to_utf8 (
const hcl_uch_t* ucs,
hcl_oow_t* ucslen,
hcl_bch_t* bcs,
hcl_oow_t* bcslen
);
/**
* The hcl_conv_utf8_to_uchars() function converts a UTF8 string to a uncide string.
*
* It never returns -2 if \a ucs is #HCL_NULL.
*
* \code
* const hcl_bch_t* bcs = "test string";
* hcl_uch_t ucs[100];
* hcl_oow_t ucslen = HCL_COUNTOF(buf), n;
* hcl_oow_t bcslen = 11;
* int n;
* n = hcl_conv_utf8_to_uchars (bcs, &bcslen, ucs, &ucslen);
* if (n <= -1) { invalid/incomplenete sequence or buffer to small }
* \endcode
*
* The resulting \a ucslen can still be greater than 0 even if the return
* value is negative. The value indiates the number of characters converted
* before the error has occurred.
*
* \return 0 on success.
* -1 if \a bcs contains an illegal character.
* -2 if the wide-character string buffer is too small.
* -3 if \a bcs is not a complete sequence.
*/
HCL_EXPORT int hcl_conv_utf8_to_uchars (
const hcl_bch_t* bcs,
hcl_oow_t* bcslen,
hcl_uch_t* ucs,
hcl_oow_t* ucslen
);
HCL_EXPORT int hcl_conv_ucstr_to_utf8 (
const hcl_uch_t* ucs,
hcl_oow_t* ucslen,
hcl_bch_t* bcs,
hcl_oow_t* bcslen
);
HCL_EXPORT int hcl_conv_utf8_to_ucstr (
const hcl_bch_t* bcs,
hcl_oow_t* bcslen,
hcl_uch_t* ucs,
hcl_oow_t* ucslen
);
HCL_EXPORT hcl_oow_t hcl_uc_to_utf8 (
hcl_uch_t uc,
hcl_bch_t* utf8,
hcl_oow_t size
);
HCL_EXPORT hcl_oow_t hcl_utf8_to_uc (
const hcl_bch_t* utf8,
hcl_oow_t size,
hcl_uch_t* uc
);
HCL_EXPORT int hcl_ucwidth (
hcl_uch_t uc
);
/* =========================================================================
* TIME CALCULATION WITH OVERFLOW/UNDERFLOW DETECTION
* ========================================================================= */