added hcl_copy_ucstr_to_bcstr(), hcl_copy_bcstr_to_ucstr(), hcl_errnum_to_errbcstr(), hcl_errnum_to_errucstr()
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
dc01f41773
commit
e5dc214a59
25
lib/err.c
25
lib/err.c
@ -172,6 +172,31 @@ const hcl_ooch_t* hcl_errnum_to_errstr (hcl_errnum_t errnum)
|
||||
return (errnum >= 0 && errnum < HCL_COUNTOF(errstr))? errstr[errnum]: e_unknown;
|
||||
}
|
||||
|
||||
const hcl_bch_t* hcl_errnum_to_errbcstr (hcl_errnum_t errnum, hcl_bch_t* buf, hcl_oow_t len)
|
||||
{
|
||||
static hcl_bch_t e_unknown[] = {'u','n','k','n','o','w','n',' ','e','r','r','o','r','\0'};
|
||||
|
||||
/* it's ok to copy without conversion because the messages above are simple acsii text */
|
||||
#if defined(HCL_OOCH_IS_BCH)
|
||||
hcl_copy_bcstr(buf, len, (errnum >= 0 && errnum < HCL_COUNTOF(errstr))? errstr[errnum]: e_unknown);
|
||||
#else
|
||||
hcl_copy_ucstr_to_bcstr(buf, len, (errnum >= 0 && errnum < HCL_COUNTOF(errstr))? errstr[errnum]: e_unknown);
|
||||
#endif
|
||||
return buf;
|
||||
}
|
||||
|
||||
const hcl_uch_t* hcl_errnum_to_errucstr (hcl_errnum_t errnum, hcl_uch_t* buf, hcl_oow_t len)
|
||||
{
|
||||
static hcl_uch_t e_unknown[] = {'u','n','k','n','o','w','n',' ','e','r','r','o','r','\0'};
|
||||
/* it's ok to copy without conversion because the messages above are simple acsii text */
|
||||
#if defined(HCL_OOCH_IS_BCH)
|
||||
hcl_copy_bcstr_to_ucstr(buf, len, (errnum >= 0 && errnum < HCL_COUNTOF(errstr))? errstr[errnum]: e_unknown);
|
||||
#else
|
||||
hcl_copy_ucstr(buf, len, (errnum >= 0 && errnum < HCL_COUNTOF(errstr))? errstr[errnum]: e_unknown);
|
||||
#endif
|
||||
return buf;
|
||||
}
|
||||
|
||||
static const hcl_bch_t* synerr_to_errstr (hcl_synerrnum_t errnum)
|
||||
{
|
||||
static hcl_bch_t e_unknown[] = "unknown error";
|
||||
|
@ -452,6 +452,18 @@ HCL_EXPORT void hcl_copy_uchars_to_bchars (
|
||||
hcl_oow_t len
|
||||
);
|
||||
|
||||
HCL_EXPORT hcl_oow_t hcl_copy_bcstr_to_ucstr (
|
||||
hcl_uch_t* dst,
|
||||
hcl_oow_t len,
|
||||
const hcl_bch_t* src
|
||||
);
|
||||
|
||||
HCL_EXPORT hcl_oow_t hcl_copy_ucstr_to_bcstr (
|
||||
hcl_bch_t* dst,
|
||||
hcl_oow_t len,
|
||||
const hcl_uch_t* src
|
||||
);
|
||||
|
||||
HCL_EXPORT hcl_oow_t hcl_copy_uchars_to_ucstr_unlimited (
|
||||
hcl_uch_t* dst,
|
||||
const hcl_uch_t* src,
|
||||
|
12
lib/hcl.h
12
lib/hcl.h
@ -2119,6 +2119,18 @@ HCL_EXPORT const hcl_ooch_t* hcl_errnum_to_errstr (
|
||||
hcl_errnum_t errnum
|
||||
);
|
||||
|
||||
HCL_EXPORT const hcl_bch_t* hcl_errnum_to_errbcstr (
|
||||
hcl_errnum_t errnum,
|
||||
hcl_bch_t* buf,
|
||||
hcl_oow_t len
|
||||
);
|
||||
|
||||
HCL_EXPORT const hcl_uch_t* hcl_errnum_to_errucstr (
|
||||
hcl_errnum_t errnum,
|
||||
hcl_uch_t* buf,
|
||||
hcl_oow_t len
|
||||
);
|
||||
|
||||
/**
|
||||
* The hcl_getoption() function gets the value of an option
|
||||
* specified by \a id into the buffer pointed to by \a value.
|
||||
|
36
lib/utl.c
36
lib/utl.c
@ -229,6 +229,42 @@ void hcl_copy_uchars_to_bchars (hcl_bch_t* dst, const hcl_uch_t* src, hcl_oow_t
|
||||
for (i = 0; i < len; i++) dst[i] = src[i];
|
||||
}
|
||||
|
||||
hcl_oow_t hcl_copy_bcstr_to_ucstr (hcl_uch_t* dst, hcl_oow_t len, const hcl_bch_t* src)
|
||||
{
|
||||
/* copy without conversions.
|
||||
* the code is the same as hcl_copy_bcstr() except type of src */
|
||||
hcl_uch_t* p, * p2;
|
||||
|
||||
p = dst; p2 = dst + len - 1;
|
||||
|
||||
while (p < p2)
|
||||
{
|
||||
if (*src == '\0') break;
|
||||
*p++ = *src++;
|
||||
}
|
||||
|
||||
if (len > 0) *p = '\0';
|
||||
return p - dst;
|
||||
}
|
||||
|
||||
hcl_oow_t hcl_copy_ucstr_to_bcstr (hcl_bch_t* dst, hcl_oow_t len, const hcl_uch_t* src)
|
||||
{
|
||||
/* copy without conversions */
|
||||
hcl_bch_t* p, * p2;
|
||||
|
||||
p = dst; p2 = dst + len - 1;
|
||||
|
||||
while (p < p2)
|
||||
{
|
||||
if (*src == '\0') break;
|
||||
*p++ = *src++;
|
||||
}
|
||||
|
||||
if (len > 0) *p = '\0';
|
||||
return p - dst;
|
||||
}
|
||||
|
||||
|
||||
hcl_oow_t hcl_copy_uchars_to_ucstr (hcl_uch_t* dst, hcl_oow_t dlen, const hcl_uch_t* src, hcl_oow_t slen)
|
||||
{
|
||||
hcl_oow_t i;
|
||||
|
Loading…
x
Reference in New Issue
Block a user