added qse_mbsxsubst()/qse_wcsxsubst()
This commit is contained in:
@ -10,7 +10,7 @@ libqsecmn_la_SOURCES = \
|
||||
syscall.h mem.h \
|
||||
mem.c xma.c fma.c chr.c chr_cnv.c rex.c \
|
||||
str_bas.c str_chr.c str_cnv.c str_cmp.c str_cpy.c str_dyn.c str_fcpy.c \
|
||||
str_pbrk.c str_put.c str_spn.c str_utl.c \
|
||||
str_pbrk.c str_put.c str_spn.c str_subst.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 \
|
||||
|
@ -75,10 +75,10 @@ libqsecmn_la_DEPENDENCIES =
|
||||
am_libqsecmn_la_OBJECTS = mem.lo xma.lo fma.lo chr.lo chr_cnv.lo \
|
||||
rex.lo str_bas.lo str_chr.lo str_cnv.lo str_cmp.lo str_cpy.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
|
||||
str_subst.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) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
@ -267,7 +267,7 @@ libqsecmn_la_SOURCES = \
|
||||
syscall.h mem.h \
|
||||
mem.c xma.c fma.c chr.c chr_cnv.c rex.c \
|
||||
str_bas.c str_chr.c str_cnv.c str_cmp.c str_cpy.c str_dyn.c str_fcpy.c \
|
||||
str_pbrk.c str_put.c str_spn.c str_utl.c \
|
||||
str_pbrk.c str_put.c str_spn.c str_subst.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 \
|
||||
@ -395,6 +395,7 @@ distclean-compile:
|
||||
@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_subst.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@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tio.Plo@am__quote@
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: str_bas.c 416 2011-03-27 05:04:24Z hyunghwan.chung $
|
||||
* $Id: str_bas.c 417 2011-03-27 14:32:37Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -43,68 +43,6 @@ qse_size_t qse_strbytes (const qse_char_t* str)
|
||||
return (p - str) * QSE_SIZEOF(qse_char_t);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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('{'))
|
||||
{
|
||||
const qse_char_t* tmp;
|
||||
qse_cstr_t ident;
|
||||
|
||||
f += 2; /* skip ${ */
|
||||
tmp = f; /* mark the beginning */
|
||||
|
||||
/* scan an enclosed segment */
|
||||
while (*f != QSE_T('\0') && *f != QSE_T('}')) f++;
|
||||
|
||||
if (*f != QSE_T('}'))
|
||||
{
|
||||
/* restore to the position of $ */
|
||||
f = tmp - 2;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++; /* skip } */
|
||||
|
||||
ident.ptr = tmp;
|
||||
ident.len = f - tmp - 1;
|
||||
|
||||
b = subst (b, end - b, &ident, ctx);
|
||||
if (b >= end) goto fini;
|
||||
|
||||
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_strxcat (qse_char_t* buf, qse_size_t bsz, const qse_char_t* str)
|
||||
{
|
||||
qse_char_t* p, * p2;
|
||||
|
145
qse/lib/cmn/str_subst.c
Normal file
145
qse/lib/cmn/str_subst.c
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* $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_mbsxsubst (
|
||||
qse_mchar_t* buf, qse_size_t bsz, const qse_mchar_t* fmt,
|
||||
qse_mbsxsubst_subst_t subst, void* ctx)
|
||||
{
|
||||
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('{'))
|
||||
{
|
||||
const qse_mchar_t* tmp;
|
||||
qse_mcstr_t ident;
|
||||
|
||||
f += 2; /* skip ${ */
|
||||
tmp = f; /* mark the beginning */
|
||||
|
||||
/* scan an enclosed segment */
|
||||
while (*f != QSE_MT('\0') && *f != QSE_MT('}')) f++;
|
||||
|
||||
if (*f != QSE_MT('}'))
|
||||
{
|
||||
/* restore to the position of $ */
|
||||
f = tmp - 2;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++; /* skip } */
|
||||
|
||||
ident.ptr = tmp;
|
||||
ident.len = f - tmp - 1;
|
||||
|
||||
b = subst (b, end - b, &ident, ctx);
|
||||
if (b >= end) goto fini;
|
||||
|
||||
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_wcsxsubst (
|
||||
qse_wchar_t* buf, qse_size_t bsz, const qse_wchar_t* fmt,
|
||||
qse_wcsxsubst_subst_t subst, void* ctx)
|
||||
{
|
||||
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('{'))
|
||||
{
|
||||
const qse_wchar_t* tmp;
|
||||
qse_wcstr_t ident;
|
||||
|
||||
f += 2; /* skip ${ */
|
||||
tmp = f; /* mark the beginning */
|
||||
|
||||
/* scan an enclosed segment */
|
||||
while (*f != QSE_WT('\0') && *f != QSE_WT('}')) f++;
|
||||
|
||||
if (*f != QSE_WT('}'))
|
||||
{
|
||||
/* restore to the position of $ */
|
||||
f = tmp - 2;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++; /* skip } */
|
||||
|
||||
ident.ptr = tmp;
|
||||
ident.len = f - tmp - 1;
|
||||
|
||||
b = subst (b, end - b, &ident, ctx);
|
||||
if (b >= end) goto fini;
|
||||
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_WT('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
if (b >= end) break;
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
fini:
|
||||
*b = QSE_WT('\0');
|
||||
return b - buf;
|
||||
}
|
Reference in New Issue
Block a user