added qse_mbsrot()/qse_wcsrot()/qse_mbsrev()/qse_wcsrev() and related functions

This commit is contained in:
2011-04-15 06:42:48 +00:00
parent 6af502fa30
commit e1d7784e4e
10 changed files with 465 additions and 117 deletions

View File

@ -11,8 +11,8 @@ libqsecmn_la_SOURCES = \
mem.c xma.c fma.c chr.c chr_cnv.c rex.c \
str_beg.c str_cat.c str_chr.c str_cnv.c str_cmp.c str_cpy.c \
str_dup.c str_dyn.c str_end.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_tok.c str_trm.c str_word.c \
str_pbrk.c str_put.c str_rev.c str_rot.c str_spl.c str_spn.c str_str.c \
str_subst.c str_tok.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

@ -75,11 +75,11 @@ libqsecmn_la_DEPENDENCIES =
am_libqsecmn_la_OBJECTS = mem.lo xma.lo fma.lo chr.lo chr_cnv.lo \
rex.lo str_beg.lo str_cat.lo str_chr.lo str_cnv.lo str_cmp.lo \
str_cpy.lo str_dup.lo str_dyn.lo str_end.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_tok.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
str_pac.lo str_pbrk.lo str_put.lo str_rev.lo str_rot.lo str_spl.lo \
str_spn.lo str_str.lo str_subst.lo str_tok.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
libqsecmn_la_OBJECTS = $(am_libqsecmn_la_OBJECTS)
libqsecmn_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
@ -269,8 +269,8 @@ libqsecmn_la_SOURCES = \
mem.c xma.c fma.c chr.c chr_cnv.c rex.c \
str_beg.c str_cat.c str_chr.c str_cnv.c str_cmp.c str_cpy.c \
str_dup.c str_dyn.c str_end.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_tok.c str_trm.c str_word.c \
str_pbrk.c str_put.c str_rev.c str_rot.c str_spl.c str_spn.c str_str.c \
str_subst.c str_tok.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 \
@ -402,6 +402,8 @@ distclean-compile:
@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_rev.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_rot.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@

64
qse/lib/cmn/str_rev.c Normal file
View File

@ -0,0 +1,64 @@
/*
* $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_mbsrev (qse_mchar_t* str)
{
return qse_mbsxrev (str, qse_mbslen(str));
}
qse_size_t qse_mbsxrev (qse_mchar_t* str, qse_size_t len)
{
qse_mchar_t ch;
qse_mchar_t* start = str;
qse_mchar_t* end = str + len - 1;
while (start < end)
{
ch = *start;
*start++ = *end;
*end-- = ch;
}
return len;
}
qse_size_t qse_wcsrev (qse_wchar_t* str)
{
return qse_wcsxrev (str, qse_wcslen(str));
}
qse_size_t qse_wcsxrev (qse_wchar_t* str, qse_size_t len)
{
qse_wchar_t ch;
qse_wchar_t* start = str;
qse_wchar_t* end = str + len - 1;
while (start < end)
{
ch = *start;
*start++ = *end;
*end-- = ch;
}
return len;
}

102
qse/lib/cmn/str_rot.c Normal file
View File

@ -0,0 +1,102 @@
/*
* $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_mbsrot (qse_mchar_t* str, int dir, qse_size_t n)
{
return qse_mbsxrot (str, qse_mbslen(str), dir, n);
}
qse_size_t qse_mbsxrot (qse_mchar_t* str, qse_size_t len, int dir, qse_size_t n)
{
qse_size_t first, last, count, index, nk;
qse_mchar_t c;
if (dir == 0 || len == 0) return len;
if ((n %= len) == 0) return len;
if (dir > 0) n = len - n;
first = 0; nk = len - n; count = 0;
while (count < n)
{
last = first + nk;
index = first;
c = str[first];
do
{
count++;
while (index < nk)
{
str[index] = str[index + n];
index += n;
}
if (index == last) break;
str[index] = str[index - nk];
index -= nk;
}
while (1);
str[last] = c; first++;
}
return len;
}
qse_size_t qse_wcsrot (qse_wchar_t* str, int dir, qse_size_t n)
{
return qse_wcsxrot (str, qse_wcslen(str), dir, n);
}
qse_size_t qse_wcsxrot (qse_wchar_t* str, qse_size_t len, int dir, qse_size_t n)
{
qse_size_t first, last, count, index, nk;
qse_wchar_t c;
if (dir == 0 || len == 0) return len;
if ((n %= len) == 0) return len;
if (dir > 0) n = len - n;
first = 0; nk = len - n; count = 0;
while (count < n)
{
last = first + nk;
index = first;
c = str[first];
do
{
count++;
while (index < nk)
{
str[index] = str[index + n];
index += n;
}
if (index == last) break;
str[index] = str[index - nk];
index -= nk;
}
while (1);
str[last] = c; first++;
}
return len;
}