added qse_mbstrm()/qse_wcstrm()/qse_mbspac()/qse_wcspac() and related functions

This commit is contained in:
2011-04-09 07:56:28 +00:00
parent c0afd55a3a
commit 10901ba0df
10 changed files with 596 additions and 294 deletions

View File

@ -10,8 +10,8 @@ libqsecmn_la_SOURCES = \
syscall.h mem.h \
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_dyn.c str_fcpy.c str_len.c str_pbrk.c str_put.c str_spl.c \
str_spn.c str_str.c str_subst.c str_utl.c str_word.c \
str_dyn.c str_fcpy.c str_len.c str_pac.c str_pbrk.c str_put.c \
str_spl.c str_spn.c str_str.c str_subst.c str_trm.c str_word.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 \

View File

@ -74,9 +74,9 @@ 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_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_pac.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_trm.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 \
pio.lo sio.lo alg_search.lo alg_sort.lo time.lo misc.lo \
assert.lo main.lo stdio.lo
@ -268,8 +268,8 @@ libqsecmn_la_SOURCES = \
syscall.h mem.h \
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_dyn.c str_fcpy.c str_len.c str_pbrk.c str_put.c str_spl.c \
str_spn.c str_str.c str_subst.c str_utl.c str_word.c \
str_dyn.c str_fcpy.c str_len.c str_pac.c str_pbrk.c str_put.c \
str_spl.c str_spn.c str_str.c str_subst.c str_trm.c str_word.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 \
@ -397,13 +397,14 @@ distclean-compile:
@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_len.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_pac.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_spl.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_subst.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_utl.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_trm.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_word.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@

142
qse/lib/cmn/str_pac.c Normal file
View File

@ -0,0 +1,142 @@
/*
* $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>
qse_size_t qse_mbspac (qse_mchar_t* str)
{
qse_mchar_t* p = str, * q = str;
while (QSE_ISMSPACE(*p)) p++;
while (*p != QSE_MT('\0'))
{
if (QSE_ISMSPACE(*p))
{
*q++ = *p++;
while (QSE_ISMSPACE(*p)) p++;
}
else *q++ = *p++;
}
if (q > str && QSE_ISMSPACE(q[-1])) q--;
*q = QSE_MT('\0');
return q - str;
}
qse_size_t qse_mbsxpac (qse_mchar_t* str, qse_size_t len)
{
qse_mchar_t* p = str, * q = str, * end = str + len;
int followed_by_space = 0;
int state = 0;
while (p < end)
{
if (state == 0)
{
if (!QSE_ISMSPACE(*p))
{
*q++ = *p;
state = 1;
}
}
else if (state == 1)
{
if (QSE_ISMSPACE(*p))
{
if (!followed_by_space)
{
followed_by_space = 1;
*q++ = *p;
}
}
else
{
followed_by_space = 0;
*q++ = *p;
}
}
p++;
}
return (followed_by_space) ? (q - str -1): (q - str);
}
qse_size_t qse_wcspac (qse_wchar_t* str)
{
qse_wchar_t* p = str, * q = str;
while (QSE_ISWSPACE(*p)) p++;
while (*p != QSE_WT('\0'))
{
if (QSE_ISWSPACE(*p))
{
*q++ = *p++;
while (QSE_ISWSPACE(*p)) p++;
}
else *q++ = *p++;
}
if (q > str && QSE_ISWSPACE(q[-1])) q--;
*q = QSE_WT('\0');
return q - str;
}
qse_size_t qse_wcsxpac (qse_wchar_t* str, qse_size_t len)
{
qse_wchar_t* p = str, * q = str, * end = str + len;
int followed_by_space = 0;
int state = 0;
while (p < end)
{
if (state == 0)
{
if (!QSE_ISWSPACE(*p))
{
*q++ = *p;
state = 1;
}
}
else if (state == 1)
{
if (QSE_ISWSPACE(*p))
{
if (!followed_by_space)
{
followed_by_space = 1;
*q++ = *p;
}
}
else
{
followed_by_space = 0;
*q++ = *p;
}
}
p++;
}
return (followed_by_space) ? (q - str -1): (q - str);
}

177
qse/lib/cmn/str_trm.c Normal file
View File

@ -0,0 +1,177 @@
/*
* $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>
#include "mem.h"
qse_mchar_t* qse_mbstrmx (qse_mchar_t* str, int opt)
{
qse_mchar_t* p = str;
qse_mchar_t* s = QSE_NULL, * e = QSE_NULL;
while (*p != QSE_MT('\0'))
{
if (!QSE_ISMSPACE(*p))
{
if (s == QSE_NULL) s = p;
e = p;
}
p++;
}
if (opt & QSE_MBSTRMX_RIGHT) e[1] = QSE_MT('\0');
if (opt & QSE_MBSTRMX_LEFT) str = s;
return str;
}
qse_size_t qse_mbstrm (qse_mchar_t* str)
{
qse_mchar_t* p = str;
qse_mchar_t* s = QSE_NULL, * e = QSE_NULL;
while (*p != QSE_MT('\0'))
{
if (!QSE_ISMSPACE(*p))
{
if (s == QSE_NULL) s = p;
e = p;
}
p++;
}
if (e != QSE_NULL)
{
e[1] = QSE_MT('\0');
if (str != s)
QSE_MEMCPY (str, s, (e - s + 2) * QSE_SIZEOF(*str));
return e - s + 1;
}
str[0] = QSE_MT('\0');
return 0;
}
qse_size_t qse_mbsxtrm (qse_mchar_t* str, qse_size_t len)
{
qse_mchar_t* p = str, * end = str + len;
qse_mchar_t* s = QSE_NULL, * e = QSE_NULL;
while (p < end)
{
if (!QSE_ISMSPACE(*p))
{
if (s == QSE_NULL) s = p;
e = p;
}
p++;
}
if (e != QSE_NULL)
{
/* do not insert a terminating null */
/*e[1] = QSE_MT('\0');*/
if (str != s)
QSE_MEMCPY (str, s, (e - s + 2) * QSE_SIZEOF(*str));
return e - s + 1;
}
/* do not insert a terminating null */
/*str[0] = QSE_MT('\0');*/
return 0;
}
qse_wchar_t* qse_wcstrmx (qse_wchar_t* str, int opt)
{
qse_wchar_t* p = str;
qse_wchar_t* s = QSE_NULL, * e = QSE_NULL;
while (*p != QSE_MT('\0'))
{
if (!QSE_ISWSPACE(*p))
{
if (s == QSE_NULL) s = p;
e = p;
}
p++;
}
if (opt & QSE_WCSTRMX_RIGHT) e[1] = QSE_MT('\0');
if (opt & QSE_WCSTRMX_LEFT) str = s;
return str;
}
qse_size_t qse_wcstrm (qse_wchar_t* str)
{
qse_wchar_t* p = str;
qse_wchar_t* s = QSE_NULL, * e = QSE_NULL;
while (*p != QSE_MT('\0'))
{
if (!QSE_ISWSPACE(*p))
{
if (s == QSE_NULL) s = p;
e = p;
}
p++;
}
if (e != QSE_NULL)
{
e[1] = QSE_MT('\0');
if (str != s)
QSE_MEMCPY (str, s, (e - s + 2) * QSE_SIZEOF(*str));
return e - s + 1;
}
str[0] = QSE_MT('\0');
return 0;
}
qse_size_t qse_wcsxtrm (qse_wchar_t* str, qse_size_t len)
{
qse_wchar_t* p = str, * end = str + len;
qse_wchar_t* s = QSE_NULL, * e = QSE_NULL;
while (p < end)
{
if (!QSE_ISWSPACE(*p))
{
if (s == QSE_NULL) s = p;
e = p;
}
p++;
}
if (e != QSE_NULL)
{
/* do not insert a terminating null */
/*e[1] = QSE_MT('\0');*/
if (str != s)
QSE_MEMCPY (str, s, (e - s + 2) * QSE_SIZEOF(*str));
return e - s + 1;
}
/* do not insert a terminating null */
/*str[0] = QSE_MT('\0');*/
return 0;
}

View File

@ -1,160 +0,0 @@
/*
* $Id: str_utl.c 427 2011-04-07 06:46:25Z hyunghwan.chung $
*
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>
#include "mem.h"
qse_char_t* qse_strtrmx (qse_char_t* str, int opt)
{
qse_char_t* p = str;
qse_char_t* s = QSE_NULL, * e = QSE_NULL;
while (*p != QSE_T('\0'))
{
if (!QSE_ISSPACE(*p))
{
if (s == QSE_NULL) s = p;
e = p;
}
p++;
}
if (opt & QSE_STRTRMX_RIGHT) e[1] = QSE_T('\0');
if (opt & QSE_STRTRMX_LEFT) str = s;
return str;
}
qse_size_t qse_strtrm (qse_char_t* str)
{
qse_char_t* p = str;
qse_char_t* s = QSE_NULL, * e = QSE_NULL;
while (*p != QSE_T('\0'))
{
if (!QSE_ISSPACE(*p))
{
if (s == QSE_NULL) s = p;
e = p;
}
p++;
}
if (e != QSE_NULL)
{
e[1] = QSE_T('\0');
if (str != s)
QSE_MEMCPY (str, s, (e - s + 2) * QSE_SIZEOF(qse_char_t));
return e - s + 1;
}
str[0] = QSE_T('\0');
return 0;
}
qse_size_t qse_strxtrm (qse_char_t* str, qse_size_t len)
{
qse_char_t* p = str, * end = str + len;
qse_char_t* s = QSE_NULL, * e = QSE_NULL;
while (p < end)
{
if (!QSE_ISSPACE(*p))
{
if (s == QSE_NULL) s = p;
e = p;
}
p++;
}
if (e != QSE_NULL)
{
/* do not insert a terminating null */
/*e[1] = QSE_T('\0');*/
if (str != s)
QSE_MEMCPY (str, s, (e - s + 2) * QSE_SIZEOF(qse_char_t));
return e - s + 1;
}
/* do not insert a terminating null */
/*str[0] = QSE_T('\0');*/
return 0;
}
qse_size_t qse_strpac (qse_char_t* str)
{
qse_char_t* p = str, * q = str;
while (QSE_ISSPACE(*p)) p++;
while (*p != QSE_T('\0'))
{
if (QSE_ISSPACE(*p))
{
*q++ = *p++;
while (QSE_ISSPACE(*p)) p++;
}
else *q++ = *p++;
}
if (q > str && QSE_ISSPACE(q[-1])) q--;
*q = QSE_T('\0');
return q - str;
}
qse_size_t qse_strxpac (qse_char_t* str, qse_size_t len)
{
qse_char_t* p = str, * q = str, * end = str + len;
int followed_by_space = 0;
int state = 0;
while (p < end)
{
if (state == 0)
{
if (!QSE_ISSPACE(*p))
{
*q++ = *p;
state = 1;
}
}
else if (state == 1)
{
if (QSE_ISSPACE(*p))
{
if (!followed_by_space)
{
followed_by_space = 1;
*q++ = *p;
}
}
else
{
followed_by_space = 0;
*q++ = *p;
}
}
p++;
}
return (followed_by_space) ? (q - str -1): (q - str);
}