added qse_mbsfcpy()/qse_wcsfcpy() and related functions
This commit is contained in:
@ -9,7 +9,8 @@ lib_LTLIBRARIES = libqsecmn.la
|
||||
libqsecmn_la_SOURCES = \
|
||||
syscall.h mem.h \
|
||||
mem.c xma.c fma.c chr.c chr_cnv.c rex.c \
|
||||
str_bas.c str_cnv.c str_cpy.c str_dyn.c str_pbrk.c str_spn.c str_utl.c \
|
||||
str_bas.c str_cnv.c str_cpy.c str_dyn.c str_fcpy.c \
|
||||
str_pbrk.c str_put.c str_spn.c str_utl.c \
|
||||
lda.c oht.c htb.c rbt.c sll.c gdl.c dll.c opt.c \
|
||||
tio.c tio_get.c tio_put.c \
|
||||
fio.c pio.c sio.c \
|
||||
|
@ -73,10 +73,10 @@ am__installdirs = "$(DESTDIR)$(libdir)"
|
||||
LTLIBRARIES = $(lib_LTLIBRARIES)
|
||||
libqsecmn_la_DEPENDENCIES =
|
||||
am_libqsecmn_la_OBJECTS = mem.lo xma.lo fma.lo chr.lo chr_cnv.lo \
|
||||
rex.lo str_bas.lo str_cnv.lo str_dyn.lo str_pbrk.lo str_spn.lo \
|
||||
str_utl.lo lda.lo oht.lo htb.lo rbt.lo sll.lo gdl.lo dll.lo \
|
||||
opt.lo tio.lo tio_get.lo tio_put.lo fio.lo pio.lo sio.lo \
|
||||
alg_search.lo alg_sort.lo time.lo misc.lo assert.lo main.lo \
|
||||
rex.lo str_bas.lo str_cnv.lo str_dyn.lo str_fcpy.lo str_pbrk.lo \
|
||||
str_put.lo str_spn.lo str_utl.lo lda.lo oht.lo htb.lo rbt.lo sll.lo \
|
||||
gdl.lo dll.lo opt.lo tio.lo tio_get.lo tio_put.lo fio.lo pio.lo \
|
||||
sio.lo alg_search.lo alg_sort.lo time.lo misc.lo assert.lo main.lo \
|
||||
stdio.lo
|
||||
libqsecmn_la_OBJECTS = $(am_libqsecmn_la_OBJECTS)
|
||||
libqsecmn_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
@ -265,7 +265,8 @@ lib_LTLIBRARIES = libqsecmn.la $(am__append_1)
|
||||
libqsecmn_la_SOURCES = \
|
||||
syscall.h mem.h \
|
||||
mem.c xma.c fma.c chr.c chr_cnv.c rex.c \
|
||||
str_bas.c str_cnv.c str_cpy.c str_dyn.c str_pbrk.c str_spn.c str_utl.c \
|
||||
str_bas.c str_cnv.c str_cpy.c str_dyn.c str_fcpy.c \
|
||||
str_pbrk.c str_put.c str_spn.c str_utl.c \
|
||||
lda.c oht.c htb.c rbt.c sll.c gdl.c dll.c opt.c \
|
||||
tio.c tio_get.c tio_put.c \
|
||||
fio.c pio.c sio.c \
|
||||
@ -386,7 +387,9 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_bas.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_cnv.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_dyn.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_fcpy.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_pbrk.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_put.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_spn.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_utl.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time.Plo@am__quote@
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: str_bas.c 410 2011-03-23 15:07:24Z hyunghwan.chung $
|
||||
* $Id: str_bas.c 411 2011-03-24 14:20:55Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -43,264 +43,6 @@ qse_size_t qse_strbytes (const qse_char_t* str)
|
||||
return (p - str) * QSE_SIZEOF(qse_char_t);
|
||||
}
|
||||
|
||||
qse_size_t qse_strxput (
|
||||
qse_char_t* buf, qse_size_t bsz, const qse_char_t* str)
|
||||
{
|
||||
qse_char_t* p, * p2;
|
||||
|
||||
p = buf; p2 = buf + bsz;
|
||||
|
||||
while (p < p2)
|
||||
{
|
||||
if (*str == QSE_T('\0')) break;
|
||||
*p++ = *str++;
|
||||
}
|
||||
|
||||
return p - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_strxnput (
|
||||
qse_char_t* buf, qse_size_t bsz, const qse_char_t* str, qse_size_t len)
|
||||
{
|
||||
qse_char_t* p, * p2;
|
||||
const qse_char_t* end;
|
||||
|
||||
p = buf; p2 = buf + bsz; end = str + len;
|
||||
|
||||
while (p < p2)
|
||||
{
|
||||
if (str >= end) break;
|
||||
*p++ = *str++;
|
||||
}
|
||||
|
||||
return p - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_strfcpy (
|
||||
qse_char_t* buf, const qse_char_t* fmt, const qse_char_t* str[])
|
||||
{
|
||||
qse_char_t* b = buf;
|
||||
const qse_char_t* f = fmt;
|
||||
|
||||
while (*f != QSE_T('\0'))
|
||||
{
|
||||
if (*f == QSE_T('$'))
|
||||
{
|
||||
if (f[1] == QSE_T('{') &&
|
||||
(f[2] >= QSE_T('0') && f[2] <= QSE_T('9')))
|
||||
{
|
||||
const qse_char_t* tmp;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_T('0'));
|
||||
while (*f >= QSE_T('0') && *f <= QSE_T('9'));
|
||||
|
||||
if (*f != QSE_T('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx];
|
||||
while (*tmp != QSE_T('\0')) *b++ = *tmp++;
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_T('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
*b = QSE_T('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_strfncpy (
|
||||
qse_char_t* buf, const qse_char_t* fmt, const qse_cstr_t str[])
|
||||
{
|
||||
qse_char_t* b = buf;
|
||||
const qse_char_t* f = fmt;
|
||||
|
||||
while (*f != QSE_T('\0'))
|
||||
{
|
||||
if (*f == QSE_T('\\'))
|
||||
{
|
||||
// get the escaped character and treat it normally.
|
||||
// if the escaper is the last character, treat it
|
||||
// normally also.
|
||||
if (f[1] != QSE_T('\0')) f++;
|
||||
}
|
||||
else if (*f == QSE_T('$'))
|
||||
{
|
||||
if (f[1] == QSE_T('{') &&
|
||||
(f[2] >= QSE_T('0') && f[2] <= QSE_T('9')))
|
||||
{
|
||||
const qse_char_t* tmp, * tmpend;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_T('0'));
|
||||
while (*f >= QSE_T('0') && *f <= QSE_T('9'));
|
||||
|
||||
if (*f != QSE_T('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx].ptr;
|
||||
tmpend = tmp + str[idx].len;
|
||||
|
||||
while (tmp < tmpend) *b++ = *tmp++;
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_T('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
*b = QSE_T('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_strxfcpy (
|
||||
qse_char_t* buf, qse_size_t bsz,
|
||||
const qse_char_t* fmt, const qse_char_t* str[])
|
||||
{
|
||||
qse_char_t* b = buf;
|
||||
qse_char_t* end = buf + bsz - 1;
|
||||
const qse_char_t* f = fmt;
|
||||
|
||||
if (bsz <= 0) return 0;
|
||||
|
||||
while (*f != QSE_T('\0'))
|
||||
{
|
||||
if (*f == QSE_T('\\'))
|
||||
{
|
||||
// get the escaped character and treat it normally.
|
||||
// if the escaper is the last character, treat it
|
||||
// normally also.
|
||||
if (f[1] != QSE_T('\0')) f++;
|
||||
}
|
||||
else if (*f == QSE_T('$'))
|
||||
{
|
||||
if (f[1] == QSE_T('{') &&
|
||||
(f[2] >= QSE_T('0') && f[2] <= QSE_T('9')))
|
||||
{
|
||||
const qse_char_t* tmp;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_T('0'));
|
||||
while (*f >= QSE_T('0') && *f <= QSE_T('9'));
|
||||
|
||||
if (*f != QSE_T('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx];
|
||||
while (*tmp != QSE_T('\0'))
|
||||
{
|
||||
if (b >= end) goto fini;
|
||||
*b++ = *tmp++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_T('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
if (b >= end) break;
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
fini:
|
||||
*b = QSE_T('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_strxfncpy (
|
||||
qse_char_t* buf, qse_size_t bsz,
|
||||
const qse_char_t* fmt, const qse_cstr_t str[])
|
||||
{
|
||||
qse_char_t* b = buf;
|
||||
qse_char_t* end = buf + bsz - 1;
|
||||
const qse_char_t* f = fmt;
|
||||
|
||||
if (bsz <= 0) return 0;
|
||||
|
||||
while (*f != QSE_T('\0'))
|
||||
{
|
||||
if (*f == QSE_T('\\'))
|
||||
{
|
||||
// get the escaped character and treat it normally.
|
||||
// if the escaper is the last character, treat it
|
||||
// normally also.
|
||||
if (f[1] != QSE_T('\0')) f++;
|
||||
}
|
||||
else if (*f == QSE_T('$'))
|
||||
{
|
||||
if (f[1] == QSE_T('{') &&
|
||||
(f[2] >= QSE_T('0') && f[2] <= QSE_T('9')))
|
||||
{
|
||||
const qse_char_t* tmp, * tmpend;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_T('0'));
|
||||
while (*f >= QSE_T('0') && *f <= QSE_T('9'));
|
||||
|
||||
if (*f != QSE_T('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx].ptr;
|
||||
tmpend = tmp + str[idx].len;
|
||||
|
||||
while (tmp < tmpend)
|
||||
{
|
||||
if (b >= end) goto fini;
|
||||
*b++ = *tmp++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_T('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
if (b >= end) break;
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
fini:
|
||||
*b = QSE_T('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_strxsubst (
|
||||
qse_char_t* buf, qse_size_t bsz, const qse_char_t* fmt,
|
||||
qse_strxsubst_subst_t subst, void* ctx)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: str_cnv.c 402 2011-03-18 15:07:21Z hyunghwan.chung $
|
||||
* $Id$
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
|
471
qse/lib/cmn/str_fcpy.c
Normal file
471
qse/lib/cmn/str_fcpy.c
Normal file
@ -0,0 +1,471 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
|
||||
QSE is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
QSE is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <qse/cmn/str.h>
|
||||
|
||||
qse_size_t qse_mbsfcpy (
|
||||
qse_mchar_t* buf, const qse_mchar_t* fmt, const qse_mchar_t* str[])
|
||||
{
|
||||
qse_mchar_t* b = buf;
|
||||
const qse_mchar_t* f = fmt;
|
||||
|
||||
while (*f != QSE_MT('\0'))
|
||||
{
|
||||
if (*f == QSE_MT('$'))
|
||||
{
|
||||
if (f[1] == QSE_MT('{') &&
|
||||
(f[2] >= QSE_MT('0') && f[2] <= QSE_MT('9')))
|
||||
{
|
||||
const qse_mchar_t* tmp;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_MT('0'));
|
||||
while (*f >= QSE_MT('0') && *f <= QSE_MT('9'));
|
||||
|
||||
if (*f != QSE_MT('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx];
|
||||
while (*tmp != QSE_MT('\0')) *b++ = *tmp++;
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_MT('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
*b = QSE_MT('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_mbsfncpy (
|
||||
qse_mchar_t* buf, const qse_mchar_t* fmt, const qse_mcstr_t str[])
|
||||
{
|
||||
qse_mchar_t* b = buf;
|
||||
const qse_mchar_t* f = fmt;
|
||||
|
||||
while (*f != QSE_MT('\0'))
|
||||
{
|
||||
if (*f == QSE_MT('\\'))
|
||||
{
|
||||
// get the escaped character and treat it normally.
|
||||
// if the escaper is the last character, treat it
|
||||
// normally also.
|
||||
if (f[1] != QSE_MT('\0')) f++;
|
||||
}
|
||||
else if (*f == QSE_MT('$'))
|
||||
{
|
||||
if (f[1] == QSE_MT('{') &&
|
||||
(f[2] >= QSE_MT('0') && f[2] <= QSE_MT('9')))
|
||||
{
|
||||
const qse_mchar_t* tmp, * tmpend;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_MT('0'));
|
||||
while (*f >= QSE_MT('0') && *f <= QSE_MT('9'));
|
||||
|
||||
if (*f != QSE_MT('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx].ptr;
|
||||
tmpend = tmp + str[idx].len;
|
||||
|
||||
while (tmp < tmpend) *b++ = *tmp++;
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_MT('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
*b = QSE_MT('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_mbsxfcpy (
|
||||
qse_mchar_t* buf, qse_size_t bsz,
|
||||
const qse_mchar_t* fmt, const qse_mchar_t* str[])
|
||||
{
|
||||
qse_mchar_t* b = buf;
|
||||
qse_mchar_t* end = buf + bsz - 1;
|
||||
const qse_mchar_t* f = fmt;
|
||||
|
||||
if (bsz <= 0) return 0;
|
||||
|
||||
while (*f != QSE_MT('\0'))
|
||||
{
|
||||
if (*f == QSE_MT('\\'))
|
||||
{
|
||||
// get the escaped character and treat it normally.
|
||||
// if the escaper is the last character, treat it
|
||||
// normally also.
|
||||
if (f[1] != QSE_MT('\0')) f++;
|
||||
}
|
||||
else if (*f == QSE_MT('$'))
|
||||
{
|
||||
if (f[1] == QSE_MT('{') &&
|
||||
(f[2] >= QSE_MT('0') && f[2] <= QSE_MT('9')))
|
||||
{
|
||||
const qse_mchar_t* tmp;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_MT('0'));
|
||||
while (*f >= QSE_MT('0') && *f <= QSE_MT('9'));
|
||||
|
||||
if (*f != QSE_MT('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx];
|
||||
while (*tmp != QSE_MT('\0'))
|
||||
{
|
||||
if (b >= end) goto fini;
|
||||
*b++ = *tmp++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_MT('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
if (b >= end) break;
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
fini:
|
||||
*b = QSE_MT('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_mbsxfncpy (
|
||||
qse_mchar_t* buf, qse_size_t bsz,
|
||||
const qse_mchar_t* fmt, const qse_mcstr_t str[])
|
||||
{
|
||||
qse_mchar_t* b = buf;
|
||||
qse_mchar_t* end = buf + bsz - 1;
|
||||
const qse_mchar_t* f = fmt;
|
||||
|
||||
if (bsz <= 0) return 0;
|
||||
|
||||
while (*f != QSE_MT('\0'))
|
||||
{
|
||||
if (*f == QSE_MT('\\'))
|
||||
{
|
||||
// get the escaped character and treat it normally.
|
||||
// if the escaper is the last character, treat it
|
||||
// normally also.
|
||||
if (f[1] != QSE_MT('\0')) f++;
|
||||
}
|
||||
else if (*f == QSE_MT('$'))
|
||||
{
|
||||
if (f[1] == QSE_MT('{') &&
|
||||
(f[2] >= QSE_MT('0') && f[2] <= QSE_MT('9')))
|
||||
{
|
||||
const qse_mchar_t* tmp, * tmpend;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_MT('0'));
|
||||
while (*f >= QSE_MT('0') && *f <= QSE_MT('9'));
|
||||
|
||||
if (*f != QSE_MT('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx].ptr;
|
||||
tmpend = tmp + str[idx].len;
|
||||
|
||||
while (tmp < tmpend)
|
||||
{
|
||||
if (b >= end) goto fini;
|
||||
*b++ = *tmp++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_MT('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
if (b >= end) break;
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
fini:
|
||||
*b = QSE_MT('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_wcsfcpy (
|
||||
qse_wchar_t* buf, const qse_wchar_t* fmt, const qse_wchar_t* str[])
|
||||
{
|
||||
qse_wchar_t* b = buf;
|
||||
const qse_wchar_t* f = fmt;
|
||||
|
||||
while (*f != QSE_WT('\0'))
|
||||
{
|
||||
if (*f == QSE_WT('$'))
|
||||
{
|
||||
if (f[1] == QSE_WT('{') &&
|
||||
(f[2] >= QSE_WT('0') && f[2] <= QSE_WT('9')))
|
||||
{
|
||||
const qse_wchar_t* tmp;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_WT('0'));
|
||||
while (*f >= QSE_WT('0') && *f <= QSE_WT('9'));
|
||||
|
||||
if (*f != QSE_WT('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx];
|
||||
while (*tmp != QSE_WT('\0')) *b++ = *tmp++;
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_WT('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
*b = QSE_WT('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_wcsfncpy (
|
||||
qse_wchar_t* buf, const qse_wchar_t* fmt, const qse_wcstr_t str[])
|
||||
{
|
||||
qse_wchar_t* b = buf;
|
||||
const qse_wchar_t* f = fmt;
|
||||
|
||||
while (*f != QSE_WT('\0'))
|
||||
{
|
||||
if (*f == QSE_WT('\\'))
|
||||
{
|
||||
// get the escaped character and treat it normally.
|
||||
// if the escaper is the last character, treat it
|
||||
// normally also.
|
||||
if (f[1] != QSE_WT('\0')) f++;
|
||||
}
|
||||
else if (*f == QSE_WT('$'))
|
||||
{
|
||||
if (f[1] == QSE_WT('{') &&
|
||||
(f[2] >= QSE_WT('0') && f[2] <= QSE_WT('9')))
|
||||
{
|
||||
const qse_wchar_t* tmp, * tmpend;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_WT('0'));
|
||||
while (*f >= QSE_WT('0') && *f <= QSE_WT('9'));
|
||||
|
||||
if (*f != QSE_WT('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx].ptr;
|
||||
tmpend = tmp + str[idx].len;
|
||||
|
||||
while (tmp < tmpend) *b++ = *tmp++;
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_WT('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
*b = QSE_WT('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_wcsxfcpy (
|
||||
qse_wchar_t* buf, qse_size_t bsz,
|
||||
const qse_wchar_t* fmt, const qse_wchar_t* str[])
|
||||
{
|
||||
qse_wchar_t* b = buf;
|
||||
qse_wchar_t* end = buf + bsz - 1;
|
||||
const qse_wchar_t* f = fmt;
|
||||
|
||||
if (bsz <= 0) return 0;
|
||||
|
||||
while (*f != QSE_WT('\0'))
|
||||
{
|
||||
if (*f == QSE_WT('\\'))
|
||||
{
|
||||
// get the escaped character and treat it normally.
|
||||
// if the escaper is the last character, treat it
|
||||
// normally also.
|
||||
if (f[1] != QSE_WT('\0')) f++;
|
||||
}
|
||||
else if (*f == QSE_WT('$'))
|
||||
{
|
||||
if (f[1] == QSE_WT('{') &&
|
||||
(f[2] >= QSE_WT('0') && f[2] <= QSE_WT('9')))
|
||||
{
|
||||
const qse_wchar_t* tmp;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_WT('0'));
|
||||
while (*f >= QSE_WT('0') && *f <= QSE_WT('9'));
|
||||
|
||||
if (*f != QSE_WT('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx];
|
||||
while (*tmp != QSE_WT('\0'))
|
||||
{
|
||||
if (b >= end) goto fini;
|
||||
*b++ = *tmp++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_WT('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
if (b >= end) break;
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
fini:
|
||||
*b = QSE_WT('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_wcsxfncpy (
|
||||
qse_wchar_t* buf, qse_size_t bsz,
|
||||
const qse_wchar_t* fmt, const qse_wcstr_t str[])
|
||||
{
|
||||
qse_wchar_t* b = buf;
|
||||
qse_wchar_t* end = buf + bsz - 1;
|
||||
const qse_wchar_t* f = fmt;
|
||||
|
||||
if (bsz <= 0) return 0;
|
||||
|
||||
while (*f != QSE_WT('\0'))
|
||||
{
|
||||
if (*f == QSE_WT('\\'))
|
||||
{
|
||||
// get the escaped character and treat it normally.
|
||||
// if the escaper is the last character, treat it
|
||||
// normally also.
|
||||
if (f[1] != QSE_WT('\0')) f++;
|
||||
}
|
||||
else if (*f == QSE_WT('$'))
|
||||
{
|
||||
if (f[1] == QSE_WT('{') &&
|
||||
(f[2] >= QSE_WT('0') && f[2] <= QSE_WT('9')))
|
||||
{
|
||||
const qse_wchar_t* tmp, * tmpend;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_WT('0'));
|
||||
while (*f >= QSE_WT('0') && *f <= QSE_WT('9'));
|
||||
|
||||
if (*f != QSE_WT('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx].ptr;
|
||||
tmpend = tmp + str[idx].len;
|
||||
|
||||
while (tmp < tmpend)
|
||||
{
|
||||
if (b >= end) goto fini;
|
||||
*b++ = *tmp++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_WT('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
if (b >= end) break;
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
fini:
|
||||
*b = QSE_WT('\0');
|
||||
return b - buf;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: str_cnv.c 402 2011-03-18 15:07:21Z hyunghwan.chung $
|
||||
* $Id$
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
|
101
qse/lib/cmn/str_put.c
Normal file
101
qse/lib/cmn/str_put.c
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
|
||||
QSE is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
QSE is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <qse/cmn/str.h>
|
||||
|
||||
qse_size_t qse_mbsput (qse_mchar_t* buf, const qse_mchar_t* str)
|
||||
{
|
||||
qse_mchar_t* org = buf;
|
||||
while (*str != QSE_MT('\0')) *buf++ = *str++;
|
||||
return buf - org;
|
||||
}
|
||||
|
||||
qse_size_t qse_wcsput (qse_wchar_t* buf, const qse_wchar_t* str)
|
||||
{
|
||||
qse_wchar_t* org = buf;
|
||||
while (*str != QSE_WT('\0')) *buf++ = *str++;
|
||||
return buf - org;
|
||||
}
|
||||
|
||||
qse_size_t qse_mbsxput (
|
||||
qse_mchar_t* buf, qse_size_t bsz, const qse_mchar_t* str)
|
||||
{
|
||||
qse_mchar_t* p, * p2;
|
||||
|
||||
p = buf; p2 = buf + bsz;
|
||||
|
||||
while (p < p2)
|
||||
{
|
||||
if (*str == QSE_MT('\0')) break;
|
||||
*p++ = *str++;
|
||||
}
|
||||
|
||||
return p - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_mbsxnput (
|
||||
qse_mchar_t* buf, qse_size_t bsz, const qse_mchar_t* str, qse_size_t len)
|
||||
{
|
||||
qse_mchar_t* p, * p2;
|
||||
const qse_mchar_t* end;
|
||||
|
||||
p = buf; p2 = buf + bsz; end = str + len;
|
||||
|
||||
while (p < p2)
|
||||
{
|
||||
if (str >= end) break;
|
||||
*p++ = *str++;
|
||||
}
|
||||
|
||||
return p - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_wcsxput (
|
||||
qse_wchar_t* buf, qse_size_t bsz, const qse_wchar_t* str)
|
||||
{
|
||||
qse_wchar_t* p, * p2;
|
||||
|
||||
p = buf; p2 = buf + bsz;
|
||||
|
||||
while (p < p2)
|
||||
{
|
||||
if (*str == QSE_WT('\0')) break;
|
||||
*p++ = *str++;
|
||||
}
|
||||
|
||||
return p - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_wcsxnput (
|
||||
qse_wchar_t* buf, qse_size_t bsz, const qse_wchar_t* str, qse_size_t len)
|
||||
{
|
||||
qse_wchar_t* p, * p2;
|
||||
const qse_wchar_t* end;
|
||||
|
||||
p = buf; p2 = buf + bsz; end = str + len;
|
||||
|
||||
while (p < p2)
|
||||
{
|
||||
if (str >= end) break;
|
||||
*p++ = *str++;
|
||||
}
|
||||
|
||||
return p - buf;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: str_cnv.c 402 2011-03-18 15:07:21Z hyunghwan.chung $
|
||||
* $Id$
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
|
Reference in New Issue
Block a user