added qse_mbsspltrn()/qse_wcsspltrn()/qse_mbsspl()/qse_wcsspl()

This commit is contained in:
hyung-hwan 2011-04-08 00:46:25 +00:00
parent f7ebae421f
commit c0afd55a3a
9 changed files with 839 additions and 425 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: str.h 425 2011-04-03 14:57:23Z hyunghwan.chung $ * $Id: str.h 427 2011-04-07 06:46:25Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE. This file is part of QSE.
@ -1347,44 +1347,99 @@ qse_size_t qse_wcsupr (
#endif #endif
/** /**
* The qse_strspl() function splits a string into fields. * The qse_mbsspl() function splits a string into fields.
*/ */
int qse_strspl ( int qse_mbsspl (
qse_char_t* str, qse_mchar_t* str,
const qse_char_t* delim, const qse_mchar_t* delim,
qse_char_t lquote, qse_mchar_t lquote,
qse_char_t rquote, qse_mchar_t rquote,
qse_char_t escape qse_mchar_t escape
); );
/** /**
* The qse_strspltrn() function splits a string translating special * The qse_wcsspl() function splits a string into fields.
*/
int qse_wcsspl (
qse_wchar_t* str,
const qse_wchar_t* delim,
qse_wchar_t lquote,
qse_wchar_t rquote,
qse_wchar_t escape
);
/**
* The qse_mbsspltrn() function splits a string translating special
* escape sequences. * escape sequences.
* The argument @a trset is a translation character set which is composed * The argument @a trset is a translation character set which is composed
* of multiple character pairs. An escape character followed by the * of multiple character pairs. An escape character followed by the
* first character in a pair is translated into the second character * first character in a pair is translated into the second character
* in the pair. If trset is QSE_NULL, no translation is performed. * in the pair. If trset is #QSE_NULL, no translation is performed.
* *
* Let's translate a sequence of '\n' and '\r' to a new line and a carriage * Let's translate a sequence of '\n' and '\r' to a new line and a carriage
* return respectively. * return respectively.
* @code * @code
* qse_strspltrn (str, QSE_T(':'), QSE_T('['), QSE_T(']'), QSE_T('\\'), QSE_T("n\nr\r"), &nfields); * nfields = qse_mbsspltrn (
* str, QSE_MT(':'), QSE_MT('['), QSE_MT(']'),
* QSE_MT('\\'), QSE_MT("n\nr\r")
* );
* @endcode * @endcode
* Given [xxx]:[\rabc\ndef]:[] as an input, the example breaks the second * Given [xxx]:[\rabc\ndef]:[] as an input, the example breaks the second
* fields to <CR>abc<NL>def where <CR> is a carriage return and <NL> is a * fields to <CR>abc<NL>def where <CR> is a carriage return and <NL> is a
* new line. * new line.
* *
* If you don't need any translation, you may call qse_strspl() alternatively. * If you don't need translation, you may call qse_mbsspl() instead.
* @return number of resulting fields on success, -1 on failure
*/ */
int qse_strspltrn ( int qse_mbsspltrn (
qse_char_t* str, qse_mchar_t* str,
const qse_char_t* delim, const qse_mchar_t* delim,
qse_char_t lquote, qse_mchar_t lquote,
qse_char_t rquote, qse_mchar_t rquote,
qse_char_t escape, qse_mchar_t escape,
const qse_char_t* trset const qse_mchar_t* trset
); );
/**
* The qse_wcsspltrn() function splits a string translating special
* escape sequences.
* The argument @a trset is a translation character set which is composed
* of multiple character pairs. An escape character followed by the
* first character in a pair is translated into the second character
* in the pair. If trset is #QSE_NULL, no translation is performed.
*
* Let's translate a sequence of '\n' and '\r' to a new line and a carriage
* return respectively.
* @code
* nfields = qse_wcsspltrn (
* str, QSE_WT(':'), QSE_WT('['), QSE_WT(']'),
* QSE_WT('\\'), QSE_WT("n\nr\r")
* );
* @endcode
* Given [xxx]:[\rabc\ndef]:[] as an input, the example breaks the second
* fields to <CR>abc<NL>def where <CR> is a carriage return and <NL> is a
* new line.
*
* If you don't need translation, you may call qse_wcsspl() instead.
* @return number of resulting fields on success, -1 on failure
*/
int qse_wcsspltrn (
qse_wchar_t* str,
const qse_wchar_t* delim,
qse_wchar_t lquote,
qse_wchar_t rquote,
qse_wchar_t escape,
const qse_wchar_t* trset
);
#ifdef QSE_CHAR_IS_MCHAR
# define qse_strspl(str,delim,lquote,rquote,escape) qse_mbsspl(str,delim,lquote,rquote,escape)
# define qse_strspltrn(str,delim,lquote,rquote,escape,trset) qse_mbsspltrn(str,delim,lquote,rquote,escape,trset)
#else
# define qse_strspl(str,delim,lquote,rquote,escape) qse_wcsspl(str,delim,lquote,rquote,escape)
# define qse_strspltrn(str,delim,lquote,rquote,escape,trset) qse_wcsspltrn(str,delim,lquote,rquote,escape,trset)
#endif
/** /**
* The qse_strtrmx() function strips leading spaces and/or trailing * The qse_strtrmx() function strips leading spaces and/or trailing
* spaces off a string depending on the opt parameter. You can form * spaces off a string depending on the opt parameter. You can form

View File

@ -10,8 +10,8 @@ libqsecmn_la_SOURCES = \
syscall.h mem.h \ syscall.h mem.h \
mem.c xma.c fma.c chr.c chr_cnv.c rex.c \ mem.c xma.c fma.c chr.c chr_cnv.c rex.c \
str_bas.c str_cat.c str_chr.c str_cnv.c str_cmp.c str_cpy.c str_dup.c \ str_bas.c str_cat.c str_chr.c str_cnv.c str_cmp.c str_cpy.c str_dup.c \
str_dyn.c str_fcpy.c str_len.c str_pbrk.c str_put.c str_spn.c str_str.c \ str_dyn.c str_fcpy.c str_len.c str_pbrk.c str_put.c str_spl.c \
str_subst.c str_utl.c str_word.c \ str_spn.c str_str.c str_subst.c str_utl.c str_word.c \
lda.c oht.c htb.c rbt.c sll.c gdl.c dll.c opt.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 \ tio.c tio_get.c tio_put.c \
fio.c pio.c sio.c \ fio.c pio.c sio.c \

View File

@ -75,7 +75,7 @@ libqsecmn_la_DEPENDENCIES =
am_libqsecmn_la_OBJECTS = mem.lo xma.lo fma.lo chr.lo chr_cnv.lo \ am_libqsecmn_la_OBJECTS = mem.lo xma.lo fma.lo chr.lo chr_cnv.lo \
rex.lo str_bas.lo str_cat.lo str_chr.lo str_cnv.lo str_cmp.lo \ rex.lo str_bas.lo str_cat.lo str_chr.lo str_cnv.lo str_cmp.lo \
str_cpy.lo str_dup.lo str_dyn.lo str_fcpy.lo str_len.lo \ str_cpy.lo str_dup.lo str_dyn.lo str_fcpy.lo str_len.lo \
str_pbrk.lo str_put.lo str_spn.lo str_str.lo str_subst.lo \ str_pbrk.lo str_put.lo str_spl.lo str_spn.lo str_str.lo str_subst.lo \
str_utl.lo str_word.lo lda.lo oht.lo htb.lo rbt.lo sll.lo \ str_utl.lo str_word.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 \ 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 \ pio.lo sio.lo alg_search.lo alg_sort.lo time.lo misc.lo \
@ -268,8 +268,8 @@ libqsecmn_la_SOURCES = \
syscall.h mem.h \ syscall.h mem.h \
mem.c xma.c fma.c chr.c chr_cnv.c rex.c \ mem.c xma.c fma.c chr.c chr_cnv.c rex.c \
str_bas.c str_cat.c str_chr.c str_cnv.c str_cmp.c str_cpy.c str_dup.c \ str_bas.c str_cat.c str_chr.c str_cnv.c str_cmp.c str_cpy.c str_dup.c \
str_dyn.c str_fcpy.c str_len.c str_pbrk.c str_put.c str_spn.c str_str.c \ str_dyn.c str_fcpy.c str_len.c str_pbrk.c str_put.c str_spl.c \
str_subst.c str_utl.c str_word.c \ str_spn.c str_str.c str_subst.c str_utl.c str_word.c \
lda.c oht.c htb.c rbt.c sll.c gdl.c dll.c opt.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 \ tio.c tio_get.c tio_put.c \
fio.c pio.c sio.c \ fio.c pio.c sio.c \
@ -399,6 +399,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_len.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_len.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_pbrk.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_put.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_spl.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_spn.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_spn.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_str.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_str.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_subst.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_subst.Plo@am__quote@

594
qse/lib/cmn/str_spl.c Normal file
View File

@ -0,0 +1,594 @@
/*
* $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>
#include <qse/cmn/chr.h>
int qse_mbsspltrn (
qse_mchar_t* s, const qse_mchar_t* delim,
qse_mchar_t lquote, qse_mchar_t rquote,
qse_mchar_t escape, const qse_mchar_t* trset)
{
qse_mchar_t* p = s, *d;
qse_mchar_t* sp = QSE_NULL, * ep = QSE_NULL;
int delim_mode;
int cnt = 0;
if (delim == QSE_NULL) delim_mode = 0;
else
{
delim_mode = 1;
for (d = (qse_mchar_t*)delim; *d != QSE_MT('\0'); d++)
if (!QSE_ISMSPACE(*d)) delim_mode = 2;
}
if (delim_mode == 0)
{
/* skip preceding space characters */
while (QSE_ISMSPACE(*p)) p++;
/* when 0 is given as "delim", it has an effect of cutting
preceding and trailing space characters off "s". */
if (lquote != QSE_MT('\0') && *p == lquote)
{
qse_mbscpy (p, p + 1);
for (;;)
{
if (*p == QSE_MT('\0')) return -1;
if (escape != QSE_MT('\0') && *p == escape)
{
if (trset != QSE_NULL && p[1] != QSE_MT('\0'))
{
const qse_mchar_t* ep = trset;
while (*ep != QSE_MT('\0'))
{
if (p[1] == *ep++)
{
p[1] = *ep;
break;
}
}
}
qse_mbscpy (p, p + 1);
}
else
{
if (*p == rquote)
{
p++;
break;
}
}
if (sp == 0) sp = p;
ep = p;
p++;
}
while (QSE_ISMSPACE(*p)) p++;
if (*p != QSE_MT('\0')) return -1;
if (sp == 0 && ep == 0) s[0] = QSE_MT('\0');
else
{
ep[1] = QSE_MT('\0');
if (s != (qse_mchar_t*)sp) qse_mbscpy (s, sp);
cnt++;
}
}
else
{
while (*p)
{
if (!QSE_ISMSPACE(*p))
{
if (sp == 0) sp = p;
ep = p;
}
p++;
}
if (sp == 0 && ep == 0) s[0] = QSE_MT('\0');
else
{
ep[1] = QSE_MT('\0');
if (s != (qse_mchar_t*)sp) qse_mbscpy (s, sp);
cnt++;
}
}
}
else if (delim_mode == 1)
{
qse_mchar_t* o;
while (*p)
{
o = p;
while (QSE_ISMSPACE(*p)) p++;
if (o != p) { qse_mbscpy (o, p); p = o; }
if (lquote != QSE_MT('\0') && *p == lquote)
{
qse_mbscpy (p, p + 1);
for (;;)
{
if (*p == QSE_MT('\0')) return -1;
if (escape != QSE_MT('\0') && *p == escape)
{
if (trset != QSE_NULL && p[1] != QSE_MT('\0'))
{
const qse_mchar_t* ep = trset;
while (*ep != QSE_MT('\0'))
{
if (p[1] == *ep++)
{
p[1] = *ep;
break;
}
}
}
qse_mbscpy (p, p + 1);
}
else
{
if (*p == rquote)
{
*p++ = QSE_MT('\0');
cnt++;
break;
}
}
p++;
}
}
else
{
o = p;
for (;;)
{
if (*p == QSE_MT('\0'))
{
if (o != p) cnt++;
break;
}
if (QSE_ISMSPACE (*p))
{
*p++ = QSE_MT('\0');
cnt++;
break;
}
p++;
}
}
}
}
else /* if (delim_mode == 2) */
{
qse_mchar_t* o;
int ok;
while (*p != QSE_MT('\0'))
{
o = p;
while (QSE_ISMSPACE(*p)) p++;
if (o != p) { qse_mbscpy (o, p); p = o; }
if (lquote != QSE_MT('\0') && *p == lquote)
{
qse_mbscpy (p, p + 1);
for (;;)
{
if (*p == QSE_MT('\0')) return -1;
if (escape != QSE_MT('\0') && *p == escape)
{
if (trset != QSE_NULL && p[1] != QSE_MT('\0'))
{
const qse_mchar_t* ep = trset;
while (*ep != QSE_MT('\0'))
{
if (p[1] == *ep++)
{
p[1] = *ep;
break;
}
}
}
qse_mbscpy (p, p + 1);
}
else
{
if (*p == rquote)
{
*p++ = QSE_MT('\0');
cnt++;
break;
}
}
p++;
}
ok = 0;
while (QSE_ISMSPACE(*p)) p++;
if (*p == QSE_MT('\0')) ok = 1;
for (d = (qse_mchar_t*)delim; *d != QSE_MT('\0'); d++)
{
if (*p == *d)
{
ok = 1;
qse_mbscpy (p, p + 1);
break;
}
}
if (ok == 0) return -1;
}
else
{
o = p; sp = ep = 0;
for (;;)
{
if (*p == QSE_MT('\0'))
{
if (ep)
{
ep[1] = QSE_MT('\0');
p = &ep[1];
}
cnt++;
break;
}
for (d = (qse_mchar_t*)delim; *d != QSE_MT('\0'); d++)
{
if (*p == *d)
{
if (sp == QSE_NULL)
{
qse_mbscpy (o, p); p = o;
*p++ = QSE_MT('\0');
}
else
{
qse_mbscpy (&ep[1], p);
qse_mbscpy (o, sp);
o[ep - sp + 1] = QSE_MT('\0');
p = &o[ep - sp + 2];
}
cnt++;
/* last empty field after delim */
if (*p == QSE_MT('\0')) cnt++;
goto exit_point;
}
}
if (!QSE_ISMSPACE (*p))
{
if (sp == QSE_NULL) sp = p;
ep = p;
}
p++;
}
exit_point:
;
}
}
}
return cnt;
}
int qse_mbsspl (
qse_mchar_t* s, const qse_mchar_t* delim,
qse_mchar_t lquote, qse_mchar_t rquote, qse_mchar_t escape)
{
return qse_mbsspltrn (s, delim, lquote, rquote, escape, QSE_NULL);
}
int qse_wcsspltrn (
qse_wchar_t* s, const qse_wchar_t* delim,
qse_wchar_t lquote, qse_wchar_t rquote,
qse_wchar_t escape, const qse_wchar_t* trset)
{
qse_wchar_t* p = s, *d;
qse_wchar_t* sp = QSE_NULL, * ep = QSE_NULL;
int delim_mode;
int cnt = 0;
if (delim == QSE_NULL) delim_mode = 0;
else
{
delim_mode = 1;
for (d = (qse_wchar_t*)delim; *d != QSE_WT('\0'); d++)
if (!QSE_ISWSPACE(*d)) delim_mode = 2;
}
if (delim_mode == 0)
{
/* skip preceding space characters */
while (QSE_ISWSPACE(*p)) p++;
/* when 0 is given as "delim", it has an effect of cutting
preceding and trailing space characters off "s". */
if (lquote != QSE_WT('\0') && *p == lquote)
{
qse_wcscpy (p, p + 1);
for (;;)
{
if (*p == QSE_WT('\0')) return -1;
if (escape != QSE_WT('\0') && *p == escape)
{
if (trset != QSE_NULL && p[1] != QSE_WT('\0'))
{
const qse_wchar_t* ep = trset;
while (*ep != QSE_WT('\0'))
{
if (p[1] == *ep++)
{
p[1] = *ep;
break;
}
}
}
qse_wcscpy (p, p + 1);
}
else
{
if (*p == rquote)
{
p++;
break;
}
}
if (sp == 0) sp = p;
ep = p;
p++;
}
while (QSE_ISWSPACE(*p)) p++;
if (*p != QSE_WT('\0')) return -1;
if (sp == 0 && ep == 0) s[0] = QSE_WT('\0');
else
{
ep[1] = QSE_WT('\0');
if (s != (qse_wchar_t*)sp) qse_wcscpy (s, sp);
cnt++;
}
}
else
{
while (*p)
{
if (!QSE_ISWSPACE(*p))
{
if (sp == 0) sp = p;
ep = p;
}
p++;
}
if (sp == 0 && ep == 0) s[0] = QSE_WT('\0');
else
{
ep[1] = QSE_WT('\0');
if (s != (qse_wchar_t*)sp) qse_wcscpy (s, sp);
cnt++;
}
}
}
else if (delim_mode == 1)
{
qse_wchar_t* o;
while (*p)
{
o = p;
while (QSE_ISWSPACE(*p)) p++;
if (o != p) { qse_wcscpy (o, p); p = o; }
if (lquote != QSE_WT('\0') && *p == lquote)
{
qse_wcscpy (p, p + 1);
for (;;)
{
if (*p == QSE_WT('\0')) return -1;
if (escape != QSE_WT('\0') && *p == escape)
{
if (trset != QSE_NULL && p[1] != QSE_WT('\0'))
{
const qse_wchar_t* ep = trset;
while (*ep != QSE_WT('\0'))
{
if (p[1] == *ep++)
{
p[1] = *ep;
break;
}
}
}
qse_wcscpy (p, p + 1);
}
else
{
if (*p == rquote)
{
*p++ = QSE_WT('\0');
cnt++;
break;
}
}
p++;
}
}
else
{
o = p;
for (;;)
{
if (*p == QSE_WT('\0'))
{
if (o != p) cnt++;
break;
}
if (QSE_ISWSPACE (*p))
{
*p++ = QSE_WT('\0');
cnt++;
break;
}
p++;
}
}
}
}
else /* if (delim_mode == 2) */
{
qse_wchar_t* o;
int ok;
while (*p != QSE_WT('\0'))
{
o = p;
while (QSE_ISWSPACE(*p)) p++;
if (o != p) { qse_wcscpy (o, p); p = o; }
if (lquote != QSE_WT('\0') && *p == lquote)
{
qse_wcscpy (p, p + 1);
for (;;)
{
if (*p == QSE_WT('\0')) return -1;
if (escape != QSE_WT('\0') && *p == escape)
{
if (trset != QSE_NULL && p[1] != QSE_WT('\0'))
{
const qse_wchar_t* ep = trset;
while (*ep != QSE_WT('\0'))
{
if (p[1] == *ep++)
{
p[1] = *ep;
break;
}
}
}
qse_wcscpy (p, p + 1);
}
else
{
if (*p == rquote)
{
*p++ = QSE_WT('\0');
cnt++;
break;
}
}
p++;
}
ok = 0;
while (QSE_ISWSPACE(*p)) p++;
if (*p == QSE_WT('\0')) ok = 1;
for (d = (qse_wchar_t*)delim; *d != QSE_WT('\0'); d++)
{
if (*p == *d)
{
ok = 1;
qse_wcscpy (p, p + 1);
break;
}
}
if (ok == 0) return -1;
}
else
{
o = p; sp = ep = 0;
for (;;)
{
if (*p == QSE_WT('\0'))
{
if (ep)
{
ep[1] = QSE_WT('\0');
p = &ep[1];
}
cnt++;
break;
}
for (d = (qse_wchar_t*)delim; *d != QSE_WT('\0'); d++)
{
if (*p == *d)
{
if (sp == QSE_NULL)
{
qse_wcscpy (o, p); p = o;
*p++ = QSE_WT('\0');
}
else
{
qse_wcscpy (&ep[1], p);
qse_wcscpy (o, sp);
o[ep - sp + 1] = QSE_WT('\0');
p = &o[ep - sp + 2];
}
cnt++;
/* last empty field after delim */
if (*p == QSE_WT('\0')) cnt++;
goto exit_point;
}
}
if (!QSE_ISWSPACE (*p))
{
if (sp == QSE_NULL) sp = p;
ep = p;
}
p++;
}
exit_point:
;
}
}
}
return cnt;
}
int qse_wcsspl (
qse_wchar_t* s, const qse_wchar_t* delim,
qse_wchar_t lquote, qse_wchar_t rquote, qse_wchar_t escape)
{
return qse_wcsspltrn (s, delim, lquote, rquote, escape, QSE_NULL);
}

View File

@ -1,5 +1,5 @@
/* /*
* $Id: str_utl.c 297 2009-10-08 13:09:19Z hyunghwan.chung $ * $Id: str_utl.c 427 2011-04-07 06:46:25Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE. This file is part of QSE.
@ -22,296 +22,6 @@
#include <qse/cmn/chr.h> #include <qse/cmn/chr.h>
#include "mem.h" #include "mem.h"
#define ISSPACE(c) \
((c) == QSE_T(' ') || (c) == QSE_T('\t') || (c) == QSE_T('\n') || \
(c) == QSE_T('\r') || (c) == QSE_T('\v') && (c) == QSE_T('\f'))
int qse_strspltrn (
qse_char_t* s, const qse_char_t* delim,
qse_char_t lquote, qse_char_t rquote,
qse_char_t escape, const qse_char_t* trset)
{
qse_char_t* p = s, *d;
qse_char_t* sp = QSE_NULL, * ep = QSE_NULL;
int delim_mode;
int cnt = 0;
if (delim == QSE_NULL) delim_mode = 0;
else
{
delim_mode = 1;
for (d = (qse_char_t*)delim; *d != QSE_T('\0'); d++)
if (!QSE_ISSPACE(*d)) delim_mode = 2;
}
if (delim_mode == 0)
{
/* skip preceding space characters */
while (QSE_ISSPACE(*p)) p++;
/* when 0 is given as "delim", it has an effect of cutting
preceding and trailing space characters off "s". */
if (lquote != QSE_T('\0') && *p == lquote)
{
qse_strcpy (p, p + 1);
for (;;)
{
if (*p == QSE_T('\0')) return -1;
if (escape != QSE_T('\0') && *p == escape)
{
if (trset != QSE_NULL && p[1] != QSE_T('\0'))
{
const qse_char_t* ep = trset;
while (*ep != QSE_T('\0'))
{
if (p[1] == *ep++)
{
p[1] = *ep;
break;
}
}
}
qse_strcpy (p, p + 1);
}
else
{
if (*p == rquote)
{
p++;
break;
}
}
if (sp == 0) sp = p;
ep = p;
p++;
}
while (QSE_ISSPACE(*p)) p++;
if (*p != QSE_T('\0')) return -1;
if (sp == 0 && ep == 0) s[0] = QSE_T('\0');
else
{
ep[1] = QSE_T('\0');
if (s != (qse_char_t*)sp) qse_strcpy (s, sp);
cnt++;
}
}
else
{
while (*p)
{
if (!QSE_ISSPACE(*p))
{
if (sp == 0) sp = p;
ep = p;
}
p++;
}
if (sp == 0 && ep == 0) s[0] = QSE_T('\0');
else
{
ep[1] = QSE_T('\0');
if (s != (qse_char_t*)sp) qse_strcpy (s, sp);
cnt++;
}
}
}
else if (delim_mode == 1)
{
qse_char_t* o;
while (*p)
{
o = p;
while (QSE_ISSPACE(*p)) p++;
if (o != p) { qse_strcpy (o, p); p = o; }
if (lquote != QSE_T('\0') && *p == lquote)
{
qse_strcpy (p, p + 1);
for (;;)
{
if (*p == QSE_T('\0')) return -1;
if (escape != QSE_T('\0') && *p == escape)
{
if (trset != QSE_NULL && p[1] != QSE_T('\0'))
{
const qse_char_t* ep = trset;
while (*ep != QSE_T('\0'))
{
if (p[1] == *ep++)
{
p[1] = *ep;
break;
}
}
}
qse_strcpy (p, p + 1);
}
else
{
if (*p == rquote)
{
*p++ = QSE_T('\0');
cnt++;
break;
}
}
p++;
}
}
else
{
o = p;
for (;;)
{
if (*p == QSE_T('\0'))
{
if (o != p) cnt++;
break;
}
if (QSE_ISSPACE (*p))
{
*p++ = QSE_T('\0');
cnt++;
break;
}
p++;
}
}
}
}
else /* if (delim_mode == 2) */
{
qse_char_t* o;
int ok;
while (*p != QSE_T('\0'))
{
o = p;
while (QSE_ISSPACE(*p)) p++;
if (o != p) { qse_strcpy (o, p); p = o; }
if (lquote != QSE_T('\0') && *p == lquote)
{
qse_strcpy (p, p + 1);
for (;;)
{
if (*p == QSE_T('\0')) return -1;
if (escape != QSE_T('\0') && *p == escape)
{
if (trset != QSE_NULL && p[1] != QSE_T('\0'))
{
const qse_char_t* ep = trset;
while (*ep != QSE_T('\0'))
{
if (p[1] == *ep++)
{
p[1] = *ep;
break;
}
}
}
qse_strcpy (p, p + 1);
}
else
{
if (*p == rquote)
{
*p++ = QSE_T('\0');
cnt++;
break;
}
}
p++;
}
ok = 0;
while (QSE_ISSPACE(*p)) p++;
if (*p == QSE_T('\0')) ok = 1;
for (d = (qse_char_t*)delim; *d != QSE_T('\0'); d++)
{
if (*p == *d)
{
ok = 1;
qse_strcpy (p, p + 1);
break;
}
}
if (ok == 0) return -1;
}
else
{
o = p; sp = ep = 0;
for (;;)
{
if (*p == QSE_T('\0'))
{
if (ep)
{
ep[1] = QSE_T('\0');
p = &ep[1];
}
cnt++;
break;
}
for (d = (qse_char_t*)delim; *d != QSE_T('\0'); d++)
{
if (*p == *d)
{
if (sp == QSE_NULL)
{
qse_strcpy (o, p); p = o;
*p++ = QSE_T('\0');
}
else
{
qse_strcpy (&ep[1], p);
qse_strcpy (o, sp);
o[ep - sp + 1] = QSE_T('\0');
p = &o[ep - sp + 2];
}
cnt++;
/* last empty field after delim */
if (*p == QSE_T('\0')) cnt++;
goto exit_point;
}
}
if (!QSE_ISSPACE (*p))
{
if (sp == QSE_NULL) sp = p;
ep = p;
}
p++;
}
exit_point:
;
}
}
}
return cnt;
}
int qse_strspl (
qse_char_t* s, const qse_char_t* delim,
qse_char_t lquote, qse_char_t rquote, qse_char_t escape)
{
return qse_strspltrn (s, delim, lquote, rquote, escape, QSE_NULL);
}
qse_char_t* qse_strtrmx (qse_char_t* str, int opt) qse_char_t* qse_strtrmx (qse_char_t* str, int opt)
{ {
qse_char_t* p = str; qse_char_t* p = str;

View File

@ -42,7 +42,7 @@ WVList
0 0
10 10
WPickList WPickList
48 49
11 11
MItem MItem
3 3
@ -692,7 +692,7 @@ WVList
155 155
MItem MItem
32 32
..\..\..\..\..\lib\cmn\str_spn.c ..\..\..\..\..\lib\cmn\str_spl.c
156 156
WString WString
4 4
@ -710,7 +710,7 @@ WVList
159 159
MItem MItem
32 32
..\..\..\..\..\lib\cmn\str_str.c ..\..\..\..\..\lib\cmn\str_spn.c
160 160
WString WString
4 4
@ -727,8 +727,8 @@ WVList
0 0
163 163
MItem MItem
34 32
..\..\..\..\..\lib\cmn\str_subst.c ..\..\..\..\..\lib\cmn\str_str.c
164 164
WString WString
4 4
@ -745,8 +745,8 @@ WVList
0 0
167 167
MItem MItem
32 34
..\..\..\..\..\lib\cmn\str_utl.c ..\..\..\..\..\lib\cmn\str_subst.c
168 168
WString WString
4 4
@ -763,8 +763,8 @@ WVList
0 0
171 171
MItem MItem
33 32
..\..\..\..\..\lib\cmn\str_word.c ..\..\..\..\..\lib\cmn\str_utl.c
172 172
WString WString
4 4
@ -781,8 +781,8 @@ WVList
0 0
175 175
MItem MItem
29 33
..\..\..\..\..\lib\cmn\time.c ..\..\..\..\..\lib\cmn\str_word.c
176 176
WString WString
4 4
@ -799,8 +799,8 @@ WVList
0 0
179 179
MItem MItem
28 29
..\..\..\..\..\lib\cmn\tio.c ..\..\..\..\..\lib\cmn\time.c
180 180
WString WString
4 4
@ -817,8 +817,8 @@ WVList
0 0
183 183
MItem MItem
32 28
..\..\..\..\..\lib\cmn\tio_get.c ..\..\..\..\..\lib\cmn\tio.c
184 184
WString WString
4 4
@ -836,7 +836,7 @@ WVList
187 187
MItem MItem
32 32
..\..\..\..\..\lib\cmn\tio_put.c ..\..\..\..\..\lib\cmn\tio_get.c
188 188
WString WString
4 4
@ -853,8 +853,8 @@ WVList
0 0
191 191
MItem MItem
28 32
..\..\..\..\..\lib\cmn\xma.c ..\..\..\..\..\lib\cmn\tio_put.c
192 192
WString WString
4 4
@ -871,26 +871,26 @@ WVList
0 0
195 195
MItem MItem
3 28
*.h ..\..\..\..\..\lib\cmn\xma.c
196 196
WString WString
3 4
NIL COBJ
197 197
WVList WVList
0 0
198 198
WVList WVList
0 0
-1 11
1 1
1 1
0 0
199 199
MItem MItem
28 3
..\..\..\..\..\lib\cmn\mem.h *.h
200 200
WString WString
3 3
@ -901,14 +901,14 @@ WVList
202 202
WVList WVList
0 0
195 -1
1 1
1 1
0 0
203 203
MItem MItem
32 28
..\..\..\..\..\lib\cmn\syscall.h ..\..\..\..\..\lib\cmn\mem.h
204 204
WString WString
3 3
@ -919,7 +919,25 @@ WVList
206 206
WVList WVList
0 0
195 199
1
1
0
207
MItem
32
..\..\..\..\..\lib\cmn\syscall.h
208
WString
3
NIL
209
WVList
0
210
WVList
0
199
1 1
1 1
0 0

View File

@ -42,7 +42,7 @@ WVList
0 0
10 10
WPickList WPickList
48 49
11 11
MItem MItem
3 3
@ -692,7 +692,7 @@ WVList
155 155
MItem MItem
32 32
..\..\..\..\..\lib\cmn\str_spn.c ..\..\..\..\..\lib\cmn\str_spl.c
156 156
WString WString
4 4
@ -710,7 +710,7 @@ WVList
159 159
MItem MItem
32 32
..\..\..\..\..\lib\cmn\str_str.c ..\..\..\..\..\lib\cmn\str_spn.c
160 160
WString WString
4 4
@ -727,8 +727,8 @@ WVList
0 0
163 163
MItem MItem
34 32
..\..\..\..\..\lib\cmn\str_subst.c ..\..\..\..\..\lib\cmn\str_str.c
164 164
WString WString
4 4
@ -745,8 +745,8 @@ WVList
0 0
167 167
MItem MItem
32 34
..\..\..\..\..\lib\cmn\str_utl.c ..\..\..\..\..\lib\cmn\str_subst.c
168 168
WString WString
4 4
@ -763,8 +763,8 @@ WVList
0 0
171 171
MItem MItem
33 32
..\..\..\..\..\lib\cmn\str_word.c ..\..\..\..\..\lib\cmn\str_utl.c
172 172
WString WString
4 4
@ -781,8 +781,8 @@ WVList
0 0
175 175
MItem MItem
29 33
..\..\..\..\..\lib\cmn\time.c ..\..\..\..\..\lib\cmn\str_word.c
176 176
WString WString
4 4
@ -799,8 +799,8 @@ WVList
0 0
179 179
MItem MItem
28 29
..\..\..\..\..\lib\cmn\tio.c ..\..\..\..\..\lib\cmn\time.c
180 180
WString WString
4 4
@ -817,8 +817,8 @@ WVList
0 0
183 183
MItem MItem
32 28
..\..\..\..\..\lib\cmn\tio_get.c ..\..\..\..\..\lib\cmn\tio.c
184 184
WString WString
4 4
@ -836,7 +836,7 @@ WVList
187 187
MItem MItem
32 32
..\..\..\..\..\lib\cmn\tio_put.c ..\..\..\..\..\lib\cmn\tio_get.c
188 188
WString WString
4 4
@ -853,8 +853,8 @@ WVList
0 0
191 191
MItem MItem
28 32
..\..\..\..\..\lib\cmn\xma.c ..\..\..\..\..\lib\cmn\tio_put.c
192 192
WString WString
4 4
@ -871,26 +871,26 @@ WVList
0 0
195 195
MItem MItem
3 28
*.h ..\..\..\..\..\lib\cmn\xma.c
196 196
WString WString
3 4
NIL COBJ
197 197
WVList WVList
0 0
198 198
WVList WVList
0 0
-1 11
1 1
1 1
0 0
199 199
MItem MItem
28 3
..\..\..\..\..\lib\cmn\mem.h *.h
200 200
WString WString
3 3
@ -901,14 +901,14 @@ WVList
202 202
WVList WVList
0 0
195 -1
1 1
1 1
0 0
203 203
MItem MItem
32 28
..\..\..\..\..\lib\cmn\syscall.h ..\..\..\..\..\lib\cmn\mem.h
204 204
WString WString
3 3
@ -919,7 +919,25 @@ WVList
206 206
WVList WVList
0 0
195 199
1
1
0
207
MItem
32
..\..\..\..\..\lib\cmn\syscall.h
208
WString
3
NIL
209
WVList
0
210
WVList
0
199
1 1
1 1
0 0

View File

@ -72,7 +72,7 @@ WRect
3160 3160
5700 5700
4240 4240
1 0
0 0
19 19
WFileName WFileName
@ -143,7 +143,7 @@ WFileName
28 28
debug/os2/lib/cmn/qsecmn.tgt debug/os2/lib/cmn/qsecmn.tgt
31 31
32 35
32 32
VComponent VComponent
33 33
@ -207,7 +207,7 @@ WFileName
30 30
debug/win32/lib/cmn/qsecmn.tgt debug/win32/lib/cmn/qsecmn.tgt
18 18
22 26
44 44
VComponent VComponent
45 45

View File

@ -42,7 +42,7 @@ WVList
0 0
10 10
WPickList WPickList
48 49
11 11
MItem MItem
3 3
@ -756,7 +756,7 @@ WVList
171 171
MItem MItem
32 32
..\..\..\..\..\lib\cmn\str_spn.c ..\..\..\..\..\lib\cmn\str_spl.c
172 172
WString WString
4 4
@ -774,7 +774,7 @@ WVList
175 175
MItem MItem
32 32
..\..\..\..\..\lib\cmn\str_str.c ..\..\..\..\..\lib\cmn\str_spn.c
176 176
WString WString
4 4
@ -791,8 +791,8 @@ WVList
0 0
179 179
MItem MItem
34 32
..\..\..\..\..\lib\cmn\str_subst.c ..\..\..\..\..\lib\cmn\str_str.c
180 180
WString WString
4 4
@ -809,48 +809,48 @@ WVList
0 0
183 183
MItem MItem
32 34
..\..\..\..\..\lib\cmn\str_utl.c ..\..\..\..\..\lib\cmn\str_subst.c
184 184
WString WString
4 4
COBJ COBJ
185 185
WVList WVList
1
186
MVState
187
WString
3
WCC
188
WString
25
o?2??Include directories:
1
189
WString
54
"$(%watcom)/h;$(%watcom)/h/os2;..\..\..\..\..\include"
0 0
190 186
WVList WVList
0 0
11 11
1 1
1 1
0 0
191 187
MItem MItem
33 32
..\..\..\..\..\lib\cmn\str_word.c ..\..\..\..\..\lib\cmn\str_utl.c
192 188
WString WString
4 4
COBJ COBJ
193 189
WVList WVList
1
190
MVState
191
WString
3
WCC
192
WString
25
o?2??Include directories:
1
193
WString
54
"$(%watcom)/h;$(%watcom)/h/os2;..\..\..\..\..\include"
0 0
194 194
WVList WVList
@ -861,8 +861,8 @@ WVList
0 0
195 195
MItem MItem
29 33
..\..\..\..\..\lib\cmn\time.c ..\..\..\..\..\lib\cmn\str_word.c
196 196
WString WString
4 4
@ -879,8 +879,8 @@ WVList
0 0
199 199
MItem MItem
28 29
..\..\..\..\..\lib\cmn\tio.c ..\..\..\..\..\lib\cmn\time.c
200 200
WString WString
4 4
@ -897,8 +897,8 @@ WVList
0 0
203 203
MItem MItem
32 28
..\..\..\..\..\lib\cmn\tio_get.c ..\..\..\..\..\lib\cmn\tio.c
204 204
WString WString
4 4
@ -916,7 +916,7 @@ WVList
207 207
MItem MItem
32 32
..\..\..\..\..\lib\cmn\tio_put.c ..\..\..\..\..\lib\cmn\tio_get.c
208 208
WString WString
4 4
@ -933,8 +933,8 @@ WVList
0 0
211 211
MItem MItem
28 32
..\..\..\..\..\lib\cmn\xma.c ..\..\..\..\..\lib\cmn\tio_put.c
212 212
WString WString
4 4
@ -951,26 +951,26 @@ WVList
0 0
215 215
MItem MItem
3 28
*.h ..\..\..\..\..\lib\cmn\xma.c
216 216
WString WString
3 4
NIL COBJ
217 217
WVList WVList
0 0
218 218
WVList WVList
0 0
-1 11
1 1
1 1
0 0
219 219
MItem MItem
28 3
..\..\..\..\..\lib\cmn\mem.h *.h
220 220
WString WString
3 3
@ -981,14 +981,14 @@ WVList
222 222
WVList WVList
0 0
215 -1
1 1
1 1
0 0
223 223
MItem MItem
32 28
..\..\..\..\..\lib\cmn\syscall.h ..\..\..\..\..\lib\cmn\mem.h
224 224
WString WString
3 3
@ -999,7 +999,25 @@ WVList
226 226
WVList WVList
0 0
215 219
1
1
0
227
MItem
32
..\..\..\..\..\lib\cmn\syscall.h
228
WString
3
NIL
229
WVList
0
230
WVList
0
219
1 1
1 1
0 0