added more string duplication and conversion functions
This commit is contained in:
@ -651,6 +651,7 @@ int main (int argc, char* argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
moo_oow_t tab_size;
|
||||
|
||||
|
@ -303,7 +303,6 @@ MOO_EXPORT int moo_convutf8toucstr (
|
||||
);
|
||||
|
||||
|
||||
|
||||
MOO_EXPORT moo_oow_t moo_uctoutf8 (
|
||||
moo_uch_t uc,
|
||||
moo_bch_t* utf8,
|
||||
|
@ -1434,6 +1434,66 @@ int moo_convutobcstr (
|
||||
moo_oow_t* bcslen
|
||||
);
|
||||
|
||||
|
||||
#if defined(MOO_OOCH_IS_UCH)
|
||||
# define moo_dupootobchars(moo,oocs,oocslen,bcslen) moo_duputobchars(moo,oocs,oocslen,bcslen)
|
||||
# define moo_dupbtooochars(moo,bcs,bcslen,oocslen) moo_dupbtouchars(moo,bcs,bcslen,oocslen)
|
||||
# define moo_dupootobcstr(moo,oocs,bcslen) moo_duputobcstr(moo,oocs,bcslen)
|
||||
# define moo_dupbtooocstr(moo,bcs,oocslen) moo_dupbtoucstr(moo,bcs,oocslen)
|
||||
#else
|
||||
# define moo_dupootouchars(moo,oocs,oocslen,ucslen) moo_dupbtouchars(moo,oocs,oocslen,ucslen)
|
||||
# define moo_duputooochars(moo,ucs,ucslen,oocslen) moo_duputobchars(moo,ucs,ucslen,oocslen)
|
||||
# define moo_dupootoucstr(moo,oocs,ucslen) moo_dupbtoucstr(moo,oocs,ucslen)
|
||||
# define moo_duputooocstr(moo,ucs,oocslen) moo_duputobcstr(moo,ucs,oocslen)
|
||||
#endif
|
||||
|
||||
|
||||
MOO_EXPORT moo_uch_t* moo_dupbtouchars (
|
||||
moo_t* moo,
|
||||
const moo_bch_t* bcs,
|
||||
moo_oow_t bcslen,
|
||||
moo_oow_t* ucslen
|
||||
);
|
||||
|
||||
MOO_EXPORT moo_bch_t* moo_duputobchars (
|
||||
moo_t* moo,
|
||||
const moo_uch_t* ucs,
|
||||
moo_oow_t ucslen,
|
||||
moo_oow_t* bcslen
|
||||
);
|
||||
|
||||
MOO_EXPORT moo_uch_t* moo_dupbtoucstr (
|
||||
moo_t* moo,
|
||||
const moo_bch_t* bcs,
|
||||
moo_oow_t* ucslen /* optional: length of returned string */
|
||||
);
|
||||
|
||||
MOO_EXPORT moo_bch_t* moo_duputobcstr (
|
||||
moo_t* moo,
|
||||
const moo_uch_t* ucs,
|
||||
moo_oow_t* bcslen /* optional: length of returned string */
|
||||
);
|
||||
|
||||
|
||||
#if defined(MOO_OOCH_IS_UCH)
|
||||
# define moo_dupoochars(moo,oocs,oocslen) moo_dupuchars(moo,oocs,oocslen)
|
||||
#else
|
||||
# define moo_dupoochars(moo,oocs,oocslen) moo_dupbchars(moo,oocs,oocslen)
|
||||
#endif
|
||||
|
||||
MOO_EXPORT moo_uch_t* moo_dupuchars (
|
||||
moo_t* moo,
|
||||
const moo_uch_t* ucs,
|
||||
moo_oow_t ucslen
|
||||
);
|
||||
|
||||
MOO_EXPORT moo_bch_t* moo_dupbchars (
|
||||
moo_t* moo,
|
||||
const moo_bch_t* bcs,
|
||||
moo_oow_t bcslen
|
||||
);
|
||||
|
||||
|
||||
/* =========================================================================
|
||||
* MOO VM LOGGING
|
||||
* ========================================================================= */
|
||||
|
@ -672,40 +672,117 @@ int moo_convutobcstr (moo_t* moo, const moo_uch_t* ucs, moo_oow_t* ucslen, moo_b
|
||||
|
||||
moo_uch_t* moo_dupbtouchars (moo_t* moo, const moo_bch_t* bcs, moo_oow_t bcslen, moo_oow_t* ucslen)
|
||||
{
|
||||
moo_oow_t inlen, reqlen;
|
||||
moo_oow_t inlen, outlen;
|
||||
moo_uch_t* ptr;
|
||||
|
||||
inlen = bcslen;
|
||||
if (moo_convbtouchars (moo, bcs, &inlen, MOO_NULL, &reqlen) <= -1)
|
||||
if (moo_convbtouchars (moo, bcs, &inlen, MOO_NULL, &outlen) <= -1)
|
||||
{
|
||||
/* note it's also an error if no full conversion is possible in this function */
|
||||
/* note it's also an error if no full conversion is made in this function */
|
||||
return MOO_NULL;
|
||||
}
|
||||
|
||||
ptr = moo_allocmem (moo, reqlen * MOO_SIZEOF(moo_uch_t));
|
||||
ptr = moo_allocmem (moo, (outlen + 1) * MOO_SIZEOF(moo_uch_t));
|
||||
if (!ptr) return MOO_NULL;
|
||||
|
||||
inlen = bcslen;
|
||||
moo_convbtouchars (moo, bcs, &inlen, ptr, ucslen);
|
||||
moo_convbtouchars (moo, bcs, &inlen, ptr, &outlen);
|
||||
|
||||
/* moo_convbtouchars() doesn't null-terminate the target.
|
||||
* but in moo_dupbtouchars(), i allocate space. so i don't mind
|
||||
* null-terminating it with 1 extra character overhead */
|
||||
ptr[outlen] = '\0';
|
||||
if (ucslen) *ucslen = outlen;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
moo_bch_t* moo_duputobchars (moo_t* moo, const moo_uch_t* ucs, moo_oow_t ucslen, moo_oow_t* bcslen)
|
||||
{
|
||||
moo_oow_t inlen, reqlen;
|
||||
moo_oow_t inlen, outlen;
|
||||
moo_bch_t* ptr;
|
||||
|
||||
inlen = ucslen;
|
||||
if (moo_convutobchars (moo, ucs, &inlen, MOO_NULL, &reqlen) <= -1)
|
||||
if (moo_convutobchars (moo, ucs, &inlen, MOO_NULL, &outlen) <= -1)
|
||||
{
|
||||
/* note it's also an error if no full conversion is possible in this function */
|
||||
/* note it's also an error if no full conversion is made in this function */
|
||||
return MOO_NULL;
|
||||
}
|
||||
|
||||
ptr = moo_allocmem (moo, reqlen * MOO_SIZEOF(moo_bch_t));
|
||||
ptr = moo_allocmem (moo, (outlen + 1) * MOO_SIZEOF(moo_bch_t));
|
||||
if (!ptr) return MOO_NULL;
|
||||
|
||||
inlen = ucslen;
|
||||
moo_convutobchars (moo, ucs, &inlen, ptr, bcslen);
|
||||
moo_convutobchars (moo, ucs, &inlen, ptr, &outlen);
|
||||
|
||||
ptr[outlen] = '\0';
|
||||
if (bcslen) *bcslen = outlen;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
moo_uch_t* moo_dupbtoucstr (moo_t* moo, const moo_bch_t* bcs, moo_oow_t* ucslen)
|
||||
{
|
||||
moo_oow_t inlen, outlen;
|
||||
moo_uch_t* ptr;
|
||||
|
||||
if (moo_convbtoucstr (moo, bcs, &inlen, MOO_NULL, &outlen) <= -1)
|
||||
{
|
||||
/* note it's also an error if no full conversion is made in this function */
|
||||
return MOO_NULL;
|
||||
}
|
||||
|
||||
outlen++;
|
||||
ptr = moo_allocmem (moo, outlen * MOO_SIZEOF(moo_uch_t));
|
||||
if (!ptr) return MOO_NULL;
|
||||
|
||||
moo_convbtoucstr (moo, bcs, &inlen, ptr, &outlen);
|
||||
if (ucslen) *ucslen = outlen;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
moo_bch_t* moo_duputobcstr (moo_t* moo, const moo_uch_t* ucs, moo_oow_t* bcslen)
|
||||
{
|
||||
moo_oow_t inlen, outlen;
|
||||
moo_bch_t* ptr;
|
||||
|
||||
if (moo_convutobcstr (moo, ucs, &inlen, MOO_NULL, &outlen) <= -1)
|
||||
{
|
||||
/* note it's also an error if no full conversion is made in this function */
|
||||
return MOO_NULL;
|
||||
}
|
||||
|
||||
outlen++;
|
||||
ptr = moo_allocmem (moo, outlen * MOO_SIZEOF(moo_bch_t));
|
||||
if (!ptr) return MOO_NULL;
|
||||
|
||||
moo_convutobcstr (moo, ucs, &inlen, ptr, &outlen);
|
||||
if (bcslen) *bcslen = outlen;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
moo_uch_t* moo_dupuchars (moo_t* moo, const moo_uch_t* ucs, moo_oow_t ucslen)
|
||||
{
|
||||
moo_uch_t* ptr;
|
||||
|
||||
ptr = moo_allocmem (moo, (ucslen + 1) * MOO_SIZEOF(moo_uch_t));
|
||||
if (!ptr) return MOO_NULL;
|
||||
|
||||
moo_copyuchars (ptr, ucs, ucslen);
|
||||
ptr[ucslen] = '\0';
|
||||
return ptr;
|
||||
}
|
||||
|
||||
moo_bch_t* moo_dupbchars (moo_t* moo, const moo_bch_t* bcs, moo_oow_t bcslen)
|
||||
{
|
||||
moo_bch_t* ptr;
|
||||
|
||||
ptr = moo_allocmem (moo, (bcslen + 1) * MOO_SIZEOF(moo_bch_t));
|
||||
if (!ptr) return MOO_NULL;
|
||||
|
||||
moo_copybchars (ptr, bcs, bcslen);
|
||||
ptr[bcslen] = '\0';
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user