2020-04-30 16:20:31 +00:00
|
|
|
/*
|
2020-05-04 08:40:05 +00:00
|
|
|
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
str_t* FN(open) (hio_t* hio, hio_oow_t xtnsize, hio_oow_t capa)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
str_t* str;
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
str = (str_t*)hio_allocmem(hio, HIO_SIZEOF(str_t) + xtnsize);
|
2020-04-30 16:20:31 +00:00
|
|
|
if (str)
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
if (FN(init)(str, hio, capa) <= -1)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_freemem (hio, str);
|
|
|
|
str = HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_MEMSET (str + 1, 0, xtnsize);
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FN(close) (str_t* str)
|
|
|
|
{
|
|
|
|
FN(fini) (str);
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_freemem (str->hio, str);
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
int FN(init) (str_t* str, hio_t* hio, hio_oow_t capa)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_MEMSET (str, 0, HIO_SIZEOF(str_t));
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
str->hio = hio;
|
|
|
|
str->sizer = HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
if (capa == 0) str->val.ptr = HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
else
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
str->val.ptr = (char_t*)hio_allocmem(hio, HIO_SIZEOF(char_t) * (capa + 1));
|
2020-04-30 16:20:31 +00:00
|
|
|
if (!str->val.ptr) return -1;
|
|
|
|
str->val.ptr[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
str->val.len = 0;
|
|
|
|
str->capa = capa;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FN(fini) (str_t* str)
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
if (str->val.ptr) hio_freemem (str->hio, str->val.ptr);
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
int FN(yield) (str_t* str, cstr_t* buf, hio_oow_t newcapa)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
char_t* tmp;
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
if (newcapa == 0) tmp = HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
else
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
tmp = (char_t*)hio_allocmem(str->hio, HIO_SIZEOF(char_t) * (newcapa + 1));
|
2020-04-30 16:20:31 +00:00
|
|
|
if (!tmp) return -1;
|
|
|
|
tmp[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf) *buf = str->val;
|
|
|
|
|
|
|
|
str->val.ptr = tmp;
|
|
|
|
str->val.len = 0;
|
|
|
|
str->capa = newcapa;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
char_t* FN(yieldptr) (str_t* str, hio_oow_t newcapa)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
cstr_t mx;
|
2021-07-22 07:30:20 +00:00
|
|
|
if (FN(yield)(str, &mx, newcapa) <= -1) return HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
return mx.ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t FN(setcapa) (str_t* str, hio_oow_t capa)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
char_t* tmp;
|
|
|
|
|
|
|
|
if (capa == str->capa) return capa;
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
tmp = (char_t*)hio_reallocmem(str->hio, str->val.ptr, HIO_SIZEOF(char_t) * (capa+1));
|
|
|
|
if (!tmp) return (hio_oow_t)-1;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
if (capa < str->val.len)
|
|
|
|
{
|
|
|
|
str->val.len = capa;
|
|
|
|
tmp[capa] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
str->capa = capa;
|
|
|
|
str->val.ptr = tmp;
|
|
|
|
|
|
|
|
return str->capa;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t FN(setlen) (str_t* str, hio_oow_t len)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
if (len == str->val.len) return len;
|
2023-01-11 14:59:41 +00:00
|
|
|
if (len < str->val.len)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
str->val.len = len;
|
|
|
|
str->val.ptr[len] = '\0';
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len > str->capa)
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
if (FN(setcapa)(str, len) == (hio_oow_t)-1) return (hio_oow_t)-1;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (str->val.len < len) str->val.ptr[str->val.len++] = ' ';
|
|
|
|
str->val.ptr[str->val.len] = '\0';
|
|
|
|
return str->val.len;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FN(clear) (str_t* str)
|
|
|
|
{
|
|
|
|
str->val.len = 0;
|
|
|
|
if (str->val.ptr)
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_ASSERT (str->hio, str->capa >= 1);
|
2020-04-30 16:20:31 +00:00
|
|
|
str->val.ptr[0] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FN(swap) (str_t* str, str_t* str1)
|
|
|
|
{
|
|
|
|
str_t tmp;
|
|
|
|
|
|
|
|
tmp.val.ptr = str->val.ptr;
|
|
|
|
tmp.val.len = str->val.len;
|
|
|
|
tmp.capa = str->capa;
|
2021-07-22 07:30:20 +00:00
|
|
|
tmp.hio = str->hio;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
str->val.ptr = str1->val.ptr;
|
|
|
|
str->val.len = str1->val.len;
|
|
|
|
str->capa = str1->capa;
|
2021-07-22 07:30:20 +00:00
|
|
|
str->hio = str1->hio;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
str1->val.ptr = tmp.val.ptr;
|
|
|
|
str1->val.len = tmp.val.len;
|
|
|
|
str1->capa = tmp.capa;
|
2021-07-22 07:30:20 +00:00
|
|
|
str1->hio = tmp.hio;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t FN(cpy) (str_t* str, const char_t* s)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
/* TODO: improve it */
|
|
|
|
return FN(ncpy)(str, s, count_chars(s));
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t FN(ncpy) (str_t* str, const char_t* s, hio_oow_t len)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
if (len > str->capa || str->capa <= 0)
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t tmp;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
/* if the current capacity is 0 and the string len to copy is 0
|
|
|
|
* we can't simply pass 'len' as the new capapcity.
|
|
|
|
* ecs_setcapa() won't do anything the current capacity of 0
|
2023-01-11 14:59:41 +00:00
|
|
|
* is the same as new capacity required. note that when str->capa
|
2021-07-22 07:30:20 +00:00
|
|
|
* is 0, str->val.ptr is HIO_NULL. However, this is copying operation.
|
2020-04-30 16:20:31 +00:00
|
|
|
* Copying a zero-length string may indicate that str->val.ptr must
|
2021-07-22 07:30:20 +00:00
|
|
|
* not be HIO_NULL. so I simply pass 1 as the new capacity */
|
2020-04-30 16:20:31 +00:00
|
|
|
tmp = FN(setcapa)(str, ((str->capa <= 0 && len <= 0)? 1: len));
|
2021-07-22 07:30:20 +00:00
|
|
|
if (tmp == (hio_oow_t)-1) return (hio_oow_t)-1;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_MEMCPY (&str->val.ptr[0], s, len * HIO_SIZEOF(*s));
|
2020-04-30 16:20:31 +00:00
|
|
|
str->val.ptr[len] = '\0';
|
|
|
|
str->val.len = len;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t FN(cat) (str_t* str, const char_t* s)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
/* TODO: improve it. no counting */
|
|
|
|
return FN(ncat)(str, s, count_chars(s));
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
static int FN(resize_for_ncat) (str_t* str, hio_oow_t len)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2023-01-11 14:59:41 +00:00
|
|
|
if (len > str->capa - str->val.len)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t ncapa, mincapa;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
/* let the minimum capacity be as large as
|
2020-04-30 16:20:31 +00:00
|
|
|
* to fit in the new substring */
|
|
|
|
mincapa = str->val.len + len;
|
|
|
|
|
|
|
|
if (!str->sizer)
|
|
|
|
{
|
|
|
|
/* increase the capacity by the length to add */
|
|
|
|
ncapa = mincapa;
|
|
|
|
/* if the new capacity is less than the double,
|
|
|
|
* just double it */
|
|
|
|
if (ncapa < str->capa * 2) ncapa = str->capa * 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* let the user determine the new capacity.
|
|
|
|
* pass the minimum capacity required as a hint */
|
|
|
|
ncapa = str->sizer(str, mincapa);
|
|
|
|
/* if no change in capacity, return current length */
|
|
|
|
if (ncapa == str->capa) return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* change the capacity */
|
|
|
|
do
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
if (FN(setcapa)(str, ncapa) != (hio_oow_t)-1) break;
|
2020-04-30 16:20:31 +00:00
|
|
|
if (ncapa <= mincapa) return -1;
|
|
|
|
ncapa--;
|
|
|
|
}
|
|
|
|
while (1);
|
|
|
|
}
|
|
|
|
else if (str->capa <= 0 && len <= 0)
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_ASSERT (str->hio, str->val.ptr == HIO_NULL);
|
|
|
|
HIO_ASSERT (str->hio, str->val.len <= 0);
|
|
|
|
if (FN(setcapa)(str, 1) == (hio_oow_t)-1) return -1;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t FN(ncat) (str_t* str, const char_t* s, hio_oow_t len)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
int n;
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t i, j;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
n = FN(resize_for_ncat)(str, len);
|
2021-07-22 07:30:20 +00:00
|
|
|
if (n <= -1) return (hio_oow_t)-1;
|
2020-04-30 16:20:31 +00:00
|
|
|
if (n == 0) return str->val.len;
|
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
if (len > str->capa - str->val.len)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
/* copy as many characters as the number of cells available.
|
|
|
|
* if the capacity has been decreased, len is adjusted here */
|
|
|
|
len = str->capa - str->val.len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_MEMCPY (&str->val.ptr[str->val.len], s, len*HIO_SIZEOF(*s));
|
2020-04-30 16:20:31 +00:00
|
|
|
str->val.len += len;
|
|
|
|
str->val.ptr[str->val.len] = T('\0');
|
|
|
|
*/
|
|
|
|
for (i = 0, j = str->val.len ; i < len; j++, i++) str->val.ptr[j] = s[i];
|
|
|
|
str->val.ptr[j] = '\0';
|
|
|
|
str->val.len = j;
|
|
|
|
|
|
|
|
return str->val.len;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t FN(nrcat) (str_t* str, const char_t* s, hio_oow_t len)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
int n;
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t i, j;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
n = FN(resize_for_ncat)(str, len);
|
2021-07-22 07:30:20 +00:00
|
|
|
if (n <= -1) return (hio_oow_t)-1;
|
2020-04-30 16:20:31 +00:00
|
|
|
if (n == 0) return str->val.len;
|
|
|
|
|
|
|
|
if (len > str->capa - str->val.len) len = str->capa - str->val.len;
|
|
|
|
|
|
|
|
for (i = len, j = str->val.len ; i > 0; j++) str->val.ptr[j] = s[--i];
|
|
|
|
str->val.ptr[j] = '\0';
|
|
|
|
str->val.len = j;
|
|
|
|
|
|
|
|
return str->val.len;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t FN(ccat) (str_t* str, char_t c)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
return FN(ncat)(str, &c, 1);
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t FN(nccat) (str_t* str, char_t c, hio_oow_t len)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
while (len > 0)
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
if (FN(ncat)(str, &c, 1) == (hio_oow_t)-1) return (hio_oow_t)-1;
|
2020-04-30 16:20:31 +00:00
|
|
|
len--;
|
|
|
|
}
|
|
|
|
return str->val.len;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t FN(del) (str_t* str, hio_oow_t index, hio_oow_t size)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
if (str->val.ptr && index < str->val.len && size > 0)
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t nidx = index + size;
|
2020-04-30 16:20:31 +00:00
|
|
|
if (nidx >= str->val.len)
|
|
|
|
{
|
|
|
|
str->val.ptr[index] = '\0';
|
|
|
|
str->val.len = index;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_MEMMOVE (&str->val.ptr[index], &str->val.ptr[nidx], HIO_SIZEOF(*str->val.ptr) * (str->val.len - nidx + 1));
|
2020-04-30 16:20:31 +00:00
|
|
|
str->val.len -= size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return str->val.len;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t FN(amend) (str_t* str, hio_oow_t pos, hio_oow_t len, const char_t* repl)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t max_len;
|
|
|
|
hio_oow_t repl_len = count_chars(repl);
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
if (pos >= str->val.len) pos = str->val.len;
|
|
|
|
max_len = str->val.len - pos;
|
|
|
|
if (len > max_len) len = max_len;
|
|
|
|
|
|
|
|
if (len > repl_len)
|
|
|
|
{
|
|
|
|
FN(del) (str, pos, len - repl_len);
|
|
|
|
}
|
|
|
|
else if (len < repl_len)
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t old_ecs_len = str->val.len;
|
|
|
|
if (FN(setlen)(str, str->val.len + repl_len - len) == (hio_oow_t)-1) return (hio_oow_t)-1;
|
|
|
|
HIO_MEMMOVE (&str->val.ptr[pos + repl_len], &str->val.ptr[pos + len], HIO_SIZEOF(*repl) * (old_ecs_len - (pos + len)));
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
if (repl_len > 0) HIO_MEMMOVE (&str->val.ptr[pos], repl, HIO_SIZEOF(*repl) * repl_len);
|
2020-04-30 16:20:31 +00:00
|
|
|
return str->val.len;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
static int FN(put_bchars) (hio_fmtout_t* fmtout, const hio_bch_t* ptr, hio_oow_t len)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
#if defined(BUILD_UECS)
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_uecs_t* uecs = (hio_uecs_t*)fmtout->ctx;
|
|
|
|
if (hio_uecs_ncatbchars(uecs, ptr, len, uecs->hio->_cmgr, 1) == (hio_oow_t)-1) return -1;
|
2020-04-30 16:20:31 +00:00
|
|
|
#else
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_becs_t* becs = (hio_becs_t*)fmtout->ctx;
|
|
|
|
if (hio_becs_ncat(becs, ptr, len) == (hio_oow_t)-1) return -1;
|
2020-04-30 16:20:31 +00:00
|
|
|
#endif
|
|
|
|
return 1; /* success. carry on */
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
static int FN(put_uchars) (hio_fmtout_t* fmtout, const hio_uch_t* ptr, hio_oow_t len)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
#if defined(BUILD_UECS)
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_uecs_t* uecs = (hio_uecs_t*)fmtout->ctx;
|
|
|
|
if (hio_uecs_ncat(uecs, ptr, len) == (hio_oow_t)-1) return -1;
|
2020-04-30 16:20:31 +00:00
|
|
|
#else
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_becs_t* becs = (hio_becs_t*)fmtout->ctx;
|
|
|
|
if (hio_becs_ncatuchars(becs, ptr, len, becs->hio->_cmgr) == (hio_oow_t)-1) return -1;
|
2020-04-30 16:20:31 +00:00
|
|
|
#endif
|
|
|
|
return 1; /* success. carry on */
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t FN(vfcat) (str_t* str, const char_t* fmt, va_list ap)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_fmtout_t fo;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_MEMSET (&fo, 0, HIO_SIZEOF(fo));
|
2020-04-30 16:20:31 +00:00
|
|
|
fo.putbchars = FN(put_bchars);
|
|
|
|
fo.putuchars = FN(put_uchars);
|
|
|
|
fo.ctx = str;
|
|
|
|
|
|
|
|
#if defined(BUILD_UECS)
|
2021-07-22 07:30:20 +00:00
|
|
|
if (hio_ufmt_outv(&fo, fmt, ap) <= -1) return -1;
|
2020-04-30 16:20:31 +00:00
|
|
|
#else
|
2021-07-22 07:30:20 +00:00
|
|
|
if (hio_bfmt_outv(&fo, fmt, ap) <= -1) return -1;
|
2020-04-30 16:20:31 +00:00
|
|
|
#endif
|
|
|
|
return str->val.len;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t FN(fcat) (str_t* str, const char_t* fmt, ...)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t x;
|
2020-04-30 16:20:31 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
|
|
|
x = FN(vfcat)(str, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t FN(vfmt) (str_t* str, const char_t* fmt, va_list ap)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_fmtout_t fo;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_MEMSET (&fo, 0, HIO_SIZEOF(fo));
|
2020-04-30 16:20:31 +00:00
|
|
|
fo.putbchars = FN(put_bchars);
|
|
|
|
fo.putuchars = FN(put_uchars);
|
|
|
|
fo.ctx = str;
|
|
|
|
|
|
|
|
FN(clear) (str);
|
|
|
|
|
|
|
|
#if defined(BUILD_UECS)
|
2021-07-22 07:30:20 +00:00
|
|
|
if (hio_ufmt_outv(&fo, fmt, ap) <= -1) return -1;
|
2020-04-30 16:20:31 +00:00
|
|
|
#else
|
2021-07-22 07:30:20 +00:00
|
|
|
if (hio_bfmt_outv(&fo, fmt, ap) <= -1) return -1;
|
2020-04-30 16:20:31 +00:00
|
|
|
#endif
|
|
|
|
return str->val.len;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t FN(fmt) (str_t* str, const char_t* fmt, ...)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t x;
|
2020-04-30 16:20:31 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
|
|
|
x = FN(vfmt)(str, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|