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

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

View File

@ -1,5 +1,5 @@
/* /*
* $Id: str.h 427 2011-04-07 06:46:25Z hyunghwan.chung $ * $Id: str.h 428 2011-04-08 13:56:28Z 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.
@ -135,14 +135,31 @@ typedef qse_wchar_t* (*qse_wcsxsubst_subst_t) (
} }
/** /**
* The qse_strtrmx_op_t defines a string trimming operation. * The qse_mbstrmx_op_t defines a string trimming operation.
*/ */
enum qse_strtrmx_op_t enum qse_mbstrmx_op_t
{ {
QSE_STRTRMX_LEFT = (1 << 0), /**< trim leading spaces */ QSE_MBSTRMX_LEFT = (1 << 0), /**< trim leading spaces */
QSE_STRTRMX_RIGHT = (1 << 1) /**< trim trailing spaces */ QSE_MBSTRMX_RIGHT = (1 << 1) /**< trim trailing spaces */
}; };
/**
* The qse_wcstrmx_op_t defines a string trimming operation.
*/
enum qse_wcstrmx_op_t
{
QSE_WCSTRMX_LEFT = (1 << 0), /**< trim leading spaces */
QSE_WCSTRMX_RIGHT = (1 << 1) /**< trim trailing spaces */
};
#ifdef QSE_CHAR_IS_MCHAR
# define QSE_STRTRMX_LEFT QSE_MBSTRMX_LEFT
# define QSE_STRTRMX_RIGHT QSE_MBSTRMX_RIGHT
#else
# define QSE_STRTRMX_LEFT QSE_WCSTRMX_LEFT
# define QSE_STRTRMX_RIGHT QSE_WCSTRMX_RIGHT
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -1441,73 +1458,160 @@ int qse_wcsspltrn (
#endif #endif
/** /**
* The qse_strtrmx() function strips leading spaces and/or trailing * The qse_mbstrmx() 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
* the op parameter by bitwise-OR'ing one or more of the following * the op parameter by bitwise-OR'ing one or more of the following
* values: * values:
* *
* - QSE_STRTRMX_LEFT - trim leading spaces * - QSE_MBSTRMX_LEFT - trim leading spaces
* - QSE_STRTRMX_RIGHT - trim trailing spaces * - QSE_MBSTRMX_RIGHT - trim trailing spaces
* *
* Should it remove leading spaces, it just returns the pointer to * Should it remove leading spaces, it just returns the pointer to
* the first non-space character in the string. Should it remove trailing * the first non-space character in the string. Should it remove trailing
* spaces, it inserts a QSE_T('\0') character after the last non-space * spaces, it inserts a QSE_MT('\0') character after the last non-space
* characters. Take note of this behavior. * characters. Take note of this behavior.
* *
* @code * @code
* qse_char_t a[] = QSE_T(" this is a test string "); * qse_mchar_t a[] = QSE_MT(" this is a test string ");
* qse_printf (QSE_T("[%s]\n"), qse_strtrmx(a,QSE_STRTRMX_LEFT|QSE_STRTRMX_RIGHT)); * qse_mbstrmx (a, QSE_MBSTRMX_LEFT|QSE_MBSTRMX_RIGHT);
* @endcode * @endcode
* *
* @return pointer to a trimmed string. * @return pointer to a trimmed string.
*/ */
qse_char_t* qse_strtrmx ( qse_mchar_t* qse_mbstrmx (
qse_char_t* str, /**< a string */ qse_mchar_t* str, /**< string */
int op /**< operation code XOR'ed of qse_strtrmx_op_t values */ int opt /**< option OR'ed of #qse_mbstrmx_op_t values */
); );
/** /**
* The qse_strtrm() function strips leading spaces and/or trailing * The qse_wcstrmx() function strips leading spaces and/or trailing
* spaces off a string. All characters between the first and the last non-space * spaces off a string depending on the opt parameter. You can form
* character inclusive are relocated to the beginning of memory pointed to * the op parameter by bitwise-OR'ing one or more of the following
* by @a str; QSE_T('\0') is inserted after the last non-space character. * values:
* @return length of the string without leading and trailing spaces. *
* - QSE_WCSTRMX_LEFT - trim leading spaces
* - QSE_WCSTRMX_RIGHT - trim trailing spaces
*
* Should it remove leading spaces, it just returns the pointer to
* the first non-space character in the string. Should it remove trailing
* spaces, it inserts a QSE_WT('\0') character after the last non-space
* characters. Take note of this behavior.
*
* @code
* qse_wchar_t a[] = QSE_WT(" this is a test string ");
* qse_wcstrmx (a, QSE_STRTRMX_LEFT|QSE_STRTRMX_RIGHT);
* @endcode
*
* @return pointer to a trimmed string.
*/ */
qse_size_t qse_strtrm ( qse_wchar_t* qse_wcstrmx (
qse_char_t* str /**< string */ qse_wchar_t* str, /**< a string */
int opt /**< option OR'ed of #qse_wcstrmx_op_t values */
); );
/** /**
* The qse_strxtrm() function strips leading spaces and/or trailing * The qse_mbstrm() function strips leading spaces and/or trailing
* spaces off a string. All characters between the first and the last non-space * spaces off a string. All characters between the first and the last non-space
* character inclusive are relocated to the beginning of memory pointed to * character inclusive are relocated to the beginning of memory pointed to
* by @a str; QSE_T('\0') is inserted after the last non-space character. * by @a str; QSE_MT('\0') is inserted after the last non-space character.
* @return length of the string without leading and trailing spaces. * @return length of the string without leading and trailing spaces.
*/ */
qse_size_t qse_strxtrm ( qse_size_t qse_mbstrm (
qse_char_t* str, /**< string */ qse_mchar_t* str /**< string */
);
/**
* The qse_wcstrm() function strips leading spaces and/or trailing
* spaces off a string. All characters between the first and the last non-space
* character inclusive are relocated to the beginning of memory pointed to
* by @a str; QSE_WT('\0') is inserted after the last non-space character.
* @return length of the string without leading and trailing spaces.
*/
qse_size_t qse_wcstrm (
qse_wchar_t* str /**< string */
);
/**
* The qse_mbsxtrm() function strips leading spaces and/or trailing
* spaces off a string. All characters between the first and the last non-space
* character inclusive are relocated to the beginning of memory pointed to
* by @a str; QSE_MT('\0') is inserted after the last non-space character.
* @return length of the string without leading and trailing spaces.
*/
qse_size_t qse_mbsxtrm (
qse_mchar_t* str, /**< string */
qse_size_t len /**< length */ qse_size_t len /**< length */
); );
/** /**
* The qse_strpac() function folds repeated whitespaces into one as well * The qse_wcsxtrm() function strips leading spaces and/or trailing
* spaces off a string. All characters between the first and the last non-space
* character inclusive are relocated to the beginning of memory pointed to
* by @a str; QSE_WT('\0') is inserted after the last non-space character.
* @return length of the string without leading and trailing spaces.
*/
qse_size_t qse_wcsxtrm (
qse_wchar_t* str, /**< string */
qse_size_t len /**< length */
);
#ifdef QSE_CHAR_IS_MCHAR
# define qse_strtrmx(str,opt) qse_mbstrmx(str,opt)
# define qse_strtrm(str) qse_mbstrm(str)
# define qse_strxtrm(str,len) qse_mbsxtrm(str,len)
#else
# define qse_strtrmx(str,opt) qse_wcstrmx(str,opt)
# define qse_strtrm(str) qse_wcstrm(str)
# define qse_strxtrm(str,len) qse_wcsxtrm(str,len)
#endif
/**
* The qse_mbspac() function folds repeated whitespaces into one as well
* as stripping leading whitespaces and trailing whitespaces. * as stripping leading whitespaces and trailing whitespaces.
* @return length of the string without leading and trailing spaces. * @return length of the string without leading and trailing spaces.
*/ */
qse_size_t qse_strpac ( qse_size_t qse_mbspac (
qse_char_t* str /**< string */ qse_mchar_t* str /**< string */
); );
/** /**
* The qse_strxpac() function folds repeated whitespaces into one as well * The qse_wcspac() function folds repeated whitespaces into one as well
* as stripping leading whitespaces and trailing whitespaces. * as stripping leading whitespaces and trailing whitespaces.
* @return length of the string without leading and trailing spaces. * @return length of the string without leading and trailing spaces.
*/ */
qse_size_t qse_strxpac ( qse_size_t qse_wcspac (
qse_char_t* str, /**< string */ qse_wchar_t* str /**< string */
);
/**
* The qse_mbsxpac() function folds repeated whitespaces into one as well
* as stripping leading whitespaces and trailing whitespaces.
* @return length of the string without leading and trailing spaces.
*/
qse_size_t qse_mbsxpac (
qse_mchar_t* str, /**< string */
qse_size_t len /**< length */ qse_size_t len /**< length */
); );
/**
* The qse_wcsxpac() function folds repeated whitespaces into one as well
* as stripping leading whitespaces and trailing whitespaces.
* @return length of the string without leading and trailing spaces.
*/
qse_size_t qse_wcsxpac (
qse_wchar_t* str, /**< string */
qse_size_t len /**< length */
);
#ifdef QSE_CHAR_IS_MCHAR
# define qse_strpac(str) qse_mbspac(str)
# define qse_strxpac(str,len) qse_mbsxpac(str,len)
#else
# define qse_strpac(str) qse_wcspac(str)
# define qse_strxpac(str,len) qse_wcsxpac(str,len)
#endif
/** /**
* The qse_mbstowcslen() function scans a null-terminated multibyte string * The qse_mbstowcslen() function scans a null-terminated multibyte string
* to calculate the number of wide characters it can be converted to. * to calculate the number of wide characters it can be converted to.

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_spl.c \ str_dyn.c str_fcpy.c str_len.c str_pac.c str_pbrk.c str_put.c \
str_spn.c str_str.c str_subst.c str_utl.c str_word.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 \ 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

@ -74,9 +74,9 @@ LTLIBRARIES = $(lib_LTLIBRARIES)
libqsecmn_la_DEPENDENCIES = 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_pac.lo \
str_pbrk.lo str_put.lo str_spl.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_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 \ 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 \
assert.lo main.lo stdio.lo assert.lo main.lo stdio.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_spl.c \ str_dyn.c str_fcpy.c str_len.c str_pac.c str_pbrk.c str_put.c \
str_spn.c str_str.c str_subst.c str_utl.c str_word.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 \ 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 \
@ -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_dyn.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_fcpy.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_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_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_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@
@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)/str_word.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time.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@ @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);
}

View File

@ -42,7 +42,7 @@ WVList
0 0
10 10
WPickList WPickList
49 50
11 11
MItem MItem
3 3
@ -655,8 +655,8 @@ WVList
0 0
147 147
MItem MItem
33 32
..\..\..\..\..\lib\cmn\str_pbrk.c ..\..\..\..\..\lib\cmn\str_pac.c
148 148
WString WString
4 4
@ -673,8 +673,8 @@ WVList
0 0
151 151
MItem MItem
32 33
..\..\..\..\..\lib\cmn\str_put.c ..\..\..\..\..\lib\cmn\str_pbrk.c
152 152
WString WString
4 4
@ -692,7 +692,7 @@ WVList
155 155
MItem MItem
32 32
..\..\..\..\..\lib\cmn\str_spl.c ..\..\..\..\..\lib\cmn\str_put.c
156 156
WString WString
4 4
@ -710,7 +710,7 @@ WVList
159 159
MItem MItem
32 32
..\..\..\..\..\lib\cmn\str_spn.c ..\..\..\..\..\lib\cmn\str_spl.c
160 160
WString WString
4 4
@ -728,7 +728,7 @@ WVList
163 163
MItem MItem
32 32
..\..\..\..\..\lib\cmn\str_str.c ..\..\..\..\..\lib\cmn\str_spn.c
164 164
WString WString
4 4
@ -745,8 +745,8 @@ WVList
0 0
167 167
MItem MItem
34 32
..\..\..\..\..\lib\cmn\str_subst.c ..\..\..\..\..\lib\cmn\str_str.c
168 168
WString WString
4 4
@ -763,8 +763,8 @@ WVList
0 0
171 171
MItem MItem
32 34
..\..\..\..\..\lib\cmn\str_utl.c ..\..\..\..\..\lib\cmn\str_subst.c
172 172
WString WString
4 4
@ -781,8 +781,8 @@ WVList
0 0
175 175
MItem MItem
33 32
..\..\..\..\..\lib\cmn\str_word.c ..\..\..\..\..\lib\cmn\str_trm.c
176 176
WString WString
4 4
@ -799,8 +799,8 @@ WVList
0 0
179 179
MItem MItem
29 33
..\..\..\..\..\lib\cmn\time.c ..\..\..\..\..\lib\cmn\str_word.c
180 180
WString WString
4 4
@ -817,8 +817,8 @@ WVList
0 0
183 183
MItem MItem
28 29
..\..\..\..\..\lib\cmn\tio.c ..\..\..\..\..\lib\cmn\time.c
184 184
WString WString
4 4
@ -835,8 +835,8 @@ WVList
0 0
187 187
MItem MItem
32 28
..\..\..\..\..\lib\cmn\tio_get.c ..\..\..\..\..\lib\cmn\tio.c
188 188
WString WString
4 4
@ -854,7 +854,7 @@ WVList
191 191
MItem MItem
32 32
..\..\..\..\..\lib\cmn\tio_put.c ..\..\..\..\..\lib\cmn\tio_get.c
192 192
WString WString
4 4
@ -871,8 +871,8 @@ WVList
0 0
195 195
MItem MItem
28 32
..\..\..\..\..\lib\cmn\xma.c ..\..\..\..\..\lib\cmn\tio_put.c
196 196
WString WString
4 4
@ -889,26 +889,26 @@ WVList
0 0
199 199
MItem MItem
3 28
*.h ..\..\..\..\..\lib\cmn\xma.c
200 200
WString WString
3 4
NIL COBJ
201 201
WVList WVList
0 0
202 202
WVList WVList
0 0
-1 11
1 1
1 1
0 0
203 203
MItem MItem
28 3
..\..\..\..\..\lib\cmn\mem.h *.h
204 204
WString WString
3 3
@ -919,14 +919,14 @@ WVList
206 206
WVList WVList
0 0
199 -1
1 1
1 1
0 0
207 207
MItem MItem
32 28
..\..\..\..\..\lib\cmn\syscall.h ..\..\..\..\..\lib\cmn\mem.h
208 208
WString WString
3 3
@ -937,7 +937,25 @@ WVList
210 210
WVList WVList
0 0
199 203
1
1
0
211
MItem
32
..\..\..\..\..\lib\cmn\syscall.h
212
WString
3
NIL
213
WVList
0
214
WVList
0
203
1 1
1 1
0 0

View File

@ -42,7 +42,7 @@ WVList
0 0
10 10
WPickList WPickList
49 50
11 11
MItem MItem
3 3
@ -655,8 +655,8 @@ WVList
0 0
147 147
MItem MItem
33 32
..\..\..\..\..\lib\cmn\str_pbrk.c ..\..\..\..\..\lib\cmn\str_pac.c
148 148
WString WString
4 4
@ -673,8 +673,8 @@ WVList
0 0
151 151
MItem MItem
32 33
..\..\..\..\..\lib\cmn\str_put.c ..\..\..\..\..\lib\cmn\str_pbrk.c
152 152
WString WString
4 4
@ -692,7 +692,7 @@ WVList
155 155
MItem MItem
32 32
..\..\..\..\..\lib\cmn\str_spl.c ..\..\..\..\..\lib\cmn\str_put.c
156 156
WString WString
4 4
@ -710,7 +710,7 @@ WVList
159 159
MItem MItem
32 32
..\..\..\..\..\lib\cmn\str_spn.c ..\..\..\..\..\lib\cmn\str_spl.c
160 160
WString WString
4 4
@ -728,7 +728,7 @@ WVList
163 163
MItem MItem
32 32
..\..\..\..\..\lib\cmn\str_str.c ..\..\..\..\..\lib\cmn\str_spn.c
164 164
WString WString
4 4
@ -745,8 +745,8 @@ WVList
0 0
167 167
MItem MItem
34 32
..\..\..\..\..\lib\cmn\str_subst.c ..\..\..\..\..\lib\cmn\str_str.c
168 168
WString WString
4 4
@ -763,8 +763,8 @@ WVList
0 0
171 171
MItem MItem
32 34
..\..\..\..\..\lib\cmn\str_utl.c ..\..\..\..\..\lib\cmn\str_subst.c
172 172
WString WString
4 4
@ -781,8 +781,8 @@ WVList
0 0
175 175
MItem MItem
33 32
..\..\..\..\..\lib\cmn\str_word.c ..\..\..\..\..\lib\cmn\str_trm.c
176 176
WString WString
4 4
@ -799,8 +799,8 @@ WVList
0 0
179 179
MItem MItem
29 33
..\..\..\..\..\lib\cmn\time.c ..\..\..\..\..\lib\cmn\str_word.c
180 180
WString WString
4 4
@ -817,8 +817,8 @@ WVList
0 0
183 183
MItem MItem
28 29
..\..\..\..\..\lib\cmn\tio.c ..\..\..\..\..\lib\cmn\time.c
184 184
WString WString
4 4
@ -835,8 +835,8 @@ WVList
0 0
187 187
MItem MItem
32 28
..\..\..\..\..\lib\cmn\tio_get.c ..\..\..\..\..\lib\cmn\tio.c
188 188
WString WString
4 4
@ -854,7 +854,7 @@ WVList
191 191
MItem MItem
32 32
..\..\..\..\..\lib\cmn\tio_put.c ..\..\..\..\..\lib\cmn\tio_get.c
192 192
WString WString
4 4
@ -871,8 +871,8 @@ WVList
0 0
195 195
MItem MItem
28 32
..\..\..\..\..\lib\cmn\xma.c ..\..\..\..\..\lib\cmn\tio_put.c
196 196
WString WString
4 4
@ -889,26 +889,26 @@ WVList
0 0
199 199
MItem MItem
3 28
*.h ..\..\..\..\..\lib\cmn\xma.c
200 200
WString WString
3 4
NIL COBJ
201 201
WVList WVList
0 0
202 202
WVList WVList
0 0
-1 11
1 1
1 1
0 0
203 203
MItem MItem
28 3
..\..\..\..\..\lib\cmn\mem.h *.h
204 204
WString WString
3 3
@ -919,14 +919,14 @@ WVList
206 206
WVList WVList
0 0
199 -1
1 1
1 1
0 0
207 207
MItem MItem
32 28
..\..\..\..\..\lib\cmn\syscall.h ..\..\..\..\..\lib\cmn\mem.h
208 208
WString WString
3 3
@ -937,7 +937,25 @@ WVList
210 210
WVList WVList
0 0
199 203
1
1
0
211
MItem
32
..\..\..\..\..\lib\cmn\syscall.h
212
WString
3
NIL
213
WVList
0
214
WVList
0
203
1 1
1 1
0 0

View File

@ -78,8 +78,8 @@ WRect
WFileName WFileName
30 30
release/os2/lib/cmn/qsecmn.tgt release/os2/lib/cmn/qsecmn.tgt
22 34
24 40
20 20
VComponent VComponent
21 21
@ -142,8 +142,8 @@ WRect
WFileName WFileName
28 28
debug/os2/lib/cmn/qsecmn.tgt debug/os2/lib/cmn/qsecmn.tgt
31 33
35 40
32 32
VComponent VComponent
33 33
@ -206,8 +206,8 @@ WRect
WFileName WFileName
30 30
debug/win32/lib/cmn/qsecmn.tgt debug/win32/lib/cmn/qsecmn.tgt
18 33
26 38
44 44
VComponent VComponent
45 45

View File

@ -42,7 +42,7 @@ WVList
0 0
10 10
WPickList WPickList
49 50
11 11
MItem MItem
3 3
@ -719,8 +719,8 @@ WVList
0 0
163 163
MItem MItem
33 32
..\..\..\..\..\lib\cmn\str_pbrk.c ..\..\..\..\..\lib\cmn\str_pac.c
164 164
WString WString
4 4
@ -737,8 +737,8 @@ WVList
0 0
167 167
MItem MItem
32 33
..\..\..\..\..\lib\cmn\str_put.c ..\..\..\..\..\lib\cmn\str_pbrk.c
168 168
WString WString
4 4
@ -756,7 +756,7 @@ WVList
171 171
MItem MItem
32 32
..\..\..\..\..\lib\cmn\str_spl.c ..\..\..\..\..\lib\cmn\str_put.c
172 172
WString WString
4 4
@ -774,7 +774,7 @@ WVList
175 175
MItem MItem
32 32
..\..\..\..\..\lib\cmn\str_spn.c ..\..\..\..\..\lib\cmn\str_spl.c
176 176
WString WString
4 4
@ -792,7 +792,7 @@ WVList
179 179
MItem MItem
32 32
..\..\..\..\..\lib\cmn\str_str.c ..\..\..\..\..\lib\cmn\str_spn.c
180 180
WString WString
4 4
@ -809,8 +809,8 @@ WVList
0 0
183 183
MItem MItem
34 32
..\..\..\..\..\lib\cmn\str_subst.c ..\..\..\..\..\lib\cmn\str_str.c
184 184
WString WString
4 4
@ -827,30 +827,32 @@ WVList
0 0
187 187
MItem MItem
32 34
..\..\..\..\..\lib\cmn\str_utl.c ..\..\..\..\..\lib\cmn\str_subst.c
188 188
WString WString
4 4
COBJ COBJ
189 189
WVList WVList
1 0
190 190
MVState WVList
0
11
1
1
0
191 191
WString MItem
3 32
WCC ..\..\..\..\..\lib\cmn\str_trm.c
192 192
WString WString
25 4
o?2??Include directories: COBJ
1
193 193
WString WVList
54
"$(%watcom)/h;$(%watcom)/h/os2;..\..\..\..\..\include"
0 0
194 194
WVList WVList