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

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

View File

@ -287,6 +287,16 @@ pio1 (QSE_T("ls -laF"), QSE_PIO_READOUT|QSE_PIO_WRITEIN|/*QSE_PIO_SHELL|*/QSE_PI
}
}
{
qse_char_t abc[100];
qse_strcpy (abc, QSE_T("abcdefghilklmn"));
qse_strrev (abc);
qse_printf (QSE_T("<%s>\n"), abc);
qse_strrot (abc, -1, 5);
qse_printf (QSE_T("<%s>\n"), abc);
}
{
qse_scm_ent_t* x1, * x2;

View File

@ -1,5 +1,5 @@
/*
* $Id: str.h 430 2011-04-12 15:36:18Z hyunghwan.chung $
* $Id: str.h 432 2011-04-14 12:42:48Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -1422,6 +1422,68 @@ qse_size_t qse_wcsupr (
# define qse_strupr(str) qse_wcsupr(str);
#endif
qse_size_t qse_mbsrev (
qse_mchar_t* str
);
qse_size_t qse_wcsrev (
qse_wchar_t* str
);
qse_size_t qse_mbsxrev (
qse_mchar_t* str,
qse_size_t len
);
qse_size_t qse_wcsxrev (
qse_wchar_t* str,
qse_size_t len
);
#ifdef QSE_CHAR_IS_MCHAR
# define qse_strrev(str) qse_mbsrev(str)
# define qse_strxrev(str,len) qse_mbsxrev(str,len)
#else
# define qse_strrev(str) qse_wcsrev(str)
# define qse_strxrev(str,len) qse_wcsxrev(str,len)
#endif
qse_size_t qse_mbsrot (
qse_mchar_t* str,
int dir,
qse_size_t n
);
qse_size_t qse_wcsrot (
qse_wchar_t* str,
int dir,
qse_size_t n
);
qse_size_t qse_mbsxrot (
qse_mchar_t* str,
qse_size_t len,
int dir,
qse_size_t n
);
qse_size_t qse_wcsxrot (
qse_wchar_t* str,
qse_size_t len,
int dir,
qse_size_t n
);
#ifdef QSE_CHAR_IS_MCHAR
# define qse_strrot(str,dir,n) qse_mbsrot(str,dir,n)
# define qse_strxrot(str,len,dir,n) qse_mbsrot(str,len,dir,n)
#else
# define qse_strrot(str,dir,n) qse_wcsrot(str,dir,n)
# define qse_strxrot(str,len,dir,n) qse_wcsrot(str,len,dir,n)
#endif
/**
* The qse_mbsspl() function splits a string into fields.
*/

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;
}

View File

@ -42,7 +42,7 @@ WVList
0
10
WPickList
52
54
11
MItem
3
@ -728,7 +728,7 @@ WVList
163
MItem
32
..\..\..\..\..\lib\cmn\str_spl.c
..\..\..\..\..\lib\cmn\str_rev.c
164
WString
4
@ -746,7 +746,7 @@ WVList
167
MItem
32
..\..\..\..\..\lib\cmn\str_spn.c
..\..\..\..\..\lib\cmn\str_rot.c
168
WString
4
@ -764,7 +764,7 @@ WVList
171
MItem
32
..\..\..\..\..\lib\cmn\str_str.c
..\..\..\..\..\lib\cmn\str_spl.c
172
WString
4
@ -781,8 +781,8 @@ WVList
0
175
MItem
34
..\..\..\..\..\lib\cmn\str_subst.c
32
..\..\..\..\..\lib\cmn\str_spn.c
176
WString
4
@ -800,7 +800,7 @@ WVList
179
MItem
32
..\..\..\..\..\lib\cmn\str_tok.c
..\..\..\..\..\lib\cmn\str_str.c
180
WString
4
@ -817,8 +817,8 @@ WVList
0
183
MItem
32
..\..\..\..\..\lib\cmn\str_trm.c
34
..\..\..\..\..\lib\cmn\str_subst.c
184
WString
4
@ -835,8 +835,8 @@ WVList
0
187
MItem
33
..\..\..\..\..\lib\cmn\str_word.c
32
..\..\..\..\..\lib\cmn\str_tok.c
188
WString
4
@ -853,8 +853,8 @@ WVList
0
191
MItem
29
..\..\..\..\..\lib\cmn\time.c
32
..\..\..\..\..\lib\cmn\str_trm.c
192
WString
4
@ -871,8 +871,8 @@ WVList
0
195
MItem
28
..\..\..\..\..\lib\cmn\tio.c
33
..\..\..\..\..\lib\cmn\str_word.c
196
WString
4
@ -889,8 +889,8 @@ WVList
0
199
MItem
32
..\..\..\..\..\lib\cmn\tio_get.c
29
..\..\..\..\..\lib\cmn\time.c
200
WString
4
@ -907,8 +907,8 @@ WVList
0
203
MItem
32
..\..\..\..\..\lib\cmn\tio_put.c
28
..\..\..\..\..\lib\cmn\tio.c
204
WString
4
@ -925,8 +925,8 @@ WVList
0
207
MItem
28
..\..\..\..\..\lib\cmn\xma.c
32
..\..\..\..\..\lib\cmn\tio_get.c
208
WString
4
@ -943,44 +943,44 @@ WVList
0
211
MItem
3
*.h
32
..\..\..\..\..\lib\cmn\tio_put.c
212
WString
3
NIL
4
COBJ
213
WVList
0
214
WVList
0
-1
11
1
1
0
215
MItem
28
..\..\..\..\..\lib\cmn\mem.h
..\..\..\..\..\lib\cmn\xma.c
216
WString
3
NIL
4
COBJ
217
WVList
0
218
WVList
0
211
11
1
1
0
219
MItem
32
..\..\..\..\..\lib\cmn\syscall.h
3
*.h
220
WString
3
@ -991,7 +991,43 @@ WVList
222
WVList
0
211
-1
1
1
0
223
MItem
28
..\..\..\..\..\lib\cmn\mem.h
224
WString
3
NIL
225
WVList
0
226
WVList
0
219
1
1
0
227
MItem
32
..\..\..\..\..\lib\cmn\syscall.h
228
WString
3
NIL
229
WVList
0
230
WVList
0
219
1
1
0

View File

@ -42,7 +42,7 @@ WVList
0
10
WPickList
52
54
11
MItem
3
@ -728,7 +728,7 @@ WVList
163
MItem
32
..\..\..\..\..\lib\cmn\str_spl.c
..\..\..\..\..\lib\cmn\str_rev.c
164
WString
4
@ -746,7 +746,7 @@ WVList
167
MItem
32
..\..\..\..\..\lib\cmn\str_spn.c
..\..\..\..\..\lib\cmn\str_rot.c
168
WString
4
@ -764,7 +764,7 @@ WVList
171
MItem
32
..\..\..\..\..\lib\cmn\str_str.c
..\..\..\..\..\lib\cmn\str_spl.c
172
WString
4
@ -781,8 +781,8 @@ WVList
0
175
MItem
34
..\..\..\..\..\lib\cmn\str_subst.c
32
..\..\..\..\..\lib\cmn\str_spn.c
176
WString
4
@ -800,7 +800,7 @@ WVList
179
MItem
32
..\..\..\..\..\lib\cmn\str_tok.c
..\..\..\..\..\lib\cmn\str_str.c
180
WString
4
@ -817,8 +817,8 @@ WVList
0
183
MItem
32
..\..\..\..\..\lib\cmn\str_trm.c
34
..\..\..\..\..\lib\cmn\str_subst.c
184
WString
4
@ -835,8 +835,8 @@ WVList
0
187
MItem
33
..\..\..\..\..\lib\cmn\str_word.c
32
..\..\..\..\..\lib\cmn\str_tok.c
188
WString
4
@ -853,8 +853,8 @@ WVList
0
191
MItem
29
..\..\..\..\..\lib\cmn\time.c
32
..\..\..\..\..\lib\cmn\str_trm.c
192
WString
4
@ -871,8 +871,8 @@ WVList
0
195
MItem
28
..\..\..\..\..\lib\cmn\tio.c
33
..\..\..\..\..\lib\cmn\str_word.c
196
WString
4
@ -889,8 +889,8 @@ WVList
0
199
MItem
32
..\..\..\..\..\lib\cmn\tio_get.c
29
..\..\..\..\..\lib\cmn\time.c
200
WString
4
@ -907,8 +907,8 @@ WVList
0
203
MItem
32
..\..\..\..\..\lib\cmn\tio_put.c
28
..\..\..\..\..\lib\cmn\tio.c
204
WString
4
@ -925,8 +925,8 @@ WVList
0
207
MItem
28
..\..\..\..\..\lib\cmn\xma.c
32
..\..\..\..\..\lib\cmn\tio_get.c
208
WString
4
@ -943,44 +943,44 @@ WVList
0
211
MItem
3
*.h
32
..\..\..\..\..\lib\cmn\tio_put.c
212
WString
3
NIL
4
COBJ
213
WVList
0
214
WVList
0
-1
11
1
1
0
215
MItem
28
..\..\..\..\..\lib\cmn\mem.h
..\..\..\..\..\lib\cmn\xma.c
216
WString
3
NIL
4
COBJ
217
WVList
0
218
WVList
0
211
11
1
1
0
219
MItem
32
..\..\..\..\..\lib\cmn\syscall.h
3
*.h
220
WString
3
@ -991,7 +991,43 @@ WVList
222
WVList
0
211
-1
1
1
0
223
MItem
28
..\..\..\..\..\lib\cmn\mem.h
224
WString
3
NIL
225
WVList
0
226
WVList
0
219
1
1
0
227
MItem
32
..\..\..\..\..\lib\cmn\syscall.h
228
WString
3
NIL
229
WVList
0
230
WVList
0
219
1
1
0

View File

@ -69,7 +69,7 @@ VComponent
18
WRect
410
1906
1893
5700
4240
0
@ -78,8 +78,8 @@ WRect
WFileName
30
release/os2/lib/cmn/qsecmn.tgt
18
24
36
42
20
VComponent
21
@ -143,7 +143,7 @@ WFileName
28
debug/os2/lib/cmn/qsecmn.tgt
37
41
38
32
VComponent
33
@ -180,8 +180,8 @@ debug/os2/lib/scm/qsescm.tgt
VComponent
39
WRect
2020
1680
2460
2426
5700
4240
0
@ -206,8 +206,8 @@ WRect
WFileName
30
debug/win32/lib/cmn/qsecmn.tgt
17
24
31
37
44
VComponent
45

View File

@ -42,7 +42,7 @@ WVList
0
10
WPickList
52
54
11
MItem
3
@ -792,7 +792,7 @@ WVList
179
MItem
32
..\..\..\..\..\lib\cmn\str_spl.c
..\..\..\..\..\lib\cmn\str_rev.c
180
WString
4
@ -810,7 +810,7 @@ WVList
183
MItem
32
..\..\..\..\..\lib\cmn\str_spn.c
..\..\..\..\..\lib\cmn\str_rot.c
184
WString
4
@ -828,7 +828,7 @@ WVList
187
MItem
32
..\..\..\..\..\lib\cmn\str_str.c
..\..\..\..\..\lib\cmn\str_spl.c
188
WString
4
@ -845,8 +845,8 @@ WVList
0
191
MItem
34
..\..\..\..\..\lib\cmn\str_subst.c
32
..\..\..\..\..\lib\cmn\str_spn.c
192
WString
4
@ -864,7 +864,7 @@ WVList
195
MItem
32
..\..\..\..\..\lib\cmn\str_tok.c
..\..\..\..\..\lib\cmn\str_str.c
196
WString
4
@ -881,8 +881,8 @@ WVList
0
199
MItem
32
..\..\..\..\..\lib\cmn\str_trm.c
34
..\..\..\..\..\lib\cmn\str_subst.c
200
WString
4
@ -899,8 +899,8 @@ WVList
0
203
MItem
33
..\..\..\..\..\lib\cmn\str_word.c
32
..\..\..\..\..\lib\cmn\str_tok.c
204
WString
4
@ -917,8 +917,8 @@ WVList
0
207
MItem
29
..\..\..\..\..\lib\cmn\time.c
32
..\..\..\..\..\lib\cmn\str_trm.c
208
WString
4
@ -935,8 +935,8 @@ WVList
0
211
MItem
28
..\..\..\..\..\lib\cmn\tio.c
33
..\..\..\..\..\lib\cmn\str_word.c
212
WString
4
@ -953,8 +953,8 @@ WVList
0
215
MItem
32
..\..\..\..\..\lib\cmn\tio_get.c
29
..\..\..\..\..\lib\cmn\time.c
216
WString
4
@ -971,8 +971,8 @@ WVList
0
219
MItem
32
..\..\..\..\..\lib\cmn\tio_put.c
28
..\..\..\..\..\lib\cmn\tio.c
220
WString
4
@ -989,8 +989,8 @@ WVList
0
223
MItem
28
..\..\..\..\..\lib\cmn\xma.c
32
..\..\..\..\..\lib\cmn\tio_get.c
224
WString
4
@ -1007,44 +1007,44 @@ WVList
0
227
MItem
3
*.h
32
..\..\..\..\..\lib\cmn\tio_put.c
228
WString
3
NIL
4
COBJ
229
WVList
0
230
WVList
0
-1
11
1
1
0
231
MItem
28
..\..\..\..\..\lib\cmn\mem.h
..\..\..\..\..\lib\cmn\xma.c
232
WString
3
NIL
4
COBJ
233
WVList
0
234
WVList
0
227
11
1
1
0
235
MItem
32
..\..\..\..\..\lib\cmn\syscall.h
3
*.h
236
WString
3
@ -1055,7 +1055,43 @@ WVList
238
WVList
0
227
-1
1
1
0
239
MItem
28
..\..\..\..\..\lib\cmn\mem.h
240
WString
3
NIL
241
WVList
0
242
WVList
0
235
1
1
0
243
MItem
32
..\..\..\..\..\lib\cmn\syscall.h
244
WString
3
NIL
245
WVList
0
246
WVList
0
235
1
1
0