added qse_strpbrk()

This commit is contained in:
hyung-hwan 2011-03-23 20:45:39 +00:00
parent f83c2c133a
commit b701c43361
7 changed files with 300 additions and 76 deletions

View File

@ -234,7 +234,8 @@ pio1 (QSE_T("pstat.exe /c"), QSE_PIO_READOUT|QSE_PIO_WRITEIN|/*QSE_PIO_SHELL|*/Q
{ {
qse_printf (QSE_T("%d\n"), (int)qse_strspn (QSE_T("abcdefg"), QSE_T("cdab"))); qse_printf (QSE_T("%d\n"), (int)qse_strspn (QSE_T("abcdefg"), QSE_T("cdab")));
qse_printf (QSE_T("%d\n"), (int)qse_strcspn (QSE_T("abcdefg"), QSE_T("fg"))); qse_printf (QSE_T("%d\n"), (int)qse_strcspn (QSE_T("abcdefg"), QSE_T("fg")));
qse_printf (QSE_T("%s\n"), qse_strpbrk (QSE_T("abcdefg"), QSE_T("fb")));
} }
{ {

View File

@ -1,5 +1,5 @@
/* /*
* $Id: str.h 407 2011-03-23 02:21:14Z hyunghwan.chung $ * $Id: str.h 408 2011-03-23 02:45:39Z 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.
@ -653,6 +653,34 @@ qse_size_t qse_wcscspn (
# define qse_strcspn(str1,str2) qse_wcscspn(str1,str2) # define qse_strcspn(str1,str2) qse_wcscspn(str1,str2)
#endif #endif
/*
* The qse_mbspbrk() function searches @a str1 for the first occurrence of
* a character in @a str2.
* @return pointer to the first occurrence in @a str1 if one is found.
* QSE_NULL if none is found.
*/
qse_mchar_t* qse_mbspbrk (
const qse_mchar_t* str1,
const qse_mchar_t* str2
);
/*
* The qse_wcspbrk() function searches @a str1 for the first occurrence of
* a character in @a str2.
* @return pointer to the first occurrence in @a str1 if one is found.
* QSE_NULL if none is found.
*/
qse_wchar_t* qse_wcspbrk (
const qse_wchar_t* str1,
const qse_wchar_t* str2
);
#ifdef QSE_CHAR_IS_MCHAR
# define qse_strpbrk(str1,str2) qse_mbspbrk(str1,str2)
#else
# define qse_strpbrk(str1,str2) qse_wcspbrk(str1,str2)
#endif
/* /*
* string conversion * string conversion
*/ */

53
qse/lib/cmn/str_pbrk.c Normal file
View File

@ -0,0 +1,53 @@
/*
* $Id: str_cnv.c 402 2011-03-18 15:07:21Z 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>
qse_mchar_t* qse_mbspbrk (const qse_mchar_t* str1, const qse_mchar_t* str2)
{
const qse_mchar_t* p1, * p2;
for (p1 = str1; *p1 != QSE_MT('\0'); p1++)
{
for (p2 = str2; *p2 != QSE_MT('\0'); p2++)
{
if (*p2 == *p1) return (qse_mchar_t*)p1;
}
}
return QSE_NULL;
}
qse_wchar_t* qse_wcspbrk (const qse_wchar_t* str1, const qse_wchar_t* str2)
{
const qse_wchar_t* p1, * p2;
for (p1 = str1; *p1 != QSE_WT('\0'); p1++)
{
for (p2 = str2; *p2 != QSE_WT('\0'); p2++)
{
if (*p2 == *p1) return (qse_wchar_t*)p1;
}
}
return QSE_NULL;
}

106
qse/lib/cmn/str_spn.c Normal file
View File

@ -0,0 +1,106 @@
/*
* $Id: str_cnv.c 402 2011-03-18 15:07:21Z 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>
qse_size_t qse_mbsspn (const qse_mchar_t* str1, const qse_mchar_t* str2)
{
const qse_mchar_t* p1, * p2;
qse_size_t n = 0;
for (p1 = str1; *p1 != QSE_MT('\0'); p1++)
{
for (p2 = str2; *p2 != QSE_MT('\0'); p2++)
{
if (*p2 == *p1) goto matched;
}
/* didn't match anything */
break;
matched:
n++;
}
return n;
}
qse_size_t qse_wcsspn (const qse_wchar_t* str1, const qse_wchar_t* str2)
{
const qse_wchar_t* p1, * p2;
qse_size_t n = 0;
for (p1 = str1; *p1 != QSE_WT('\0'); p1++)
{
for (p2 = str2; *p2 != QSE_WT('\0'); p2++)
{
if (*p2 == *p1) goto matched;
}
/* didn't match anything */
break;
matched:
n++;
}
return n;
}
qse_size_t qse_mbscspn (const qse_mchar_t* str1, const qse_mchar_t* str2)
{
const qse_mchar_t* p1, * p2;
qse_size_t n = 0;
for (p1 = str1; *p1 != QSE_WT('\0'); p1++)
{
for (p2 = str2; *p2 != QSE_WT('\0'); p2++)
{
if (*p2 == *p1) goto done;
}
/* didn't match anything. increment the length */
n++;
}
done:
return n;
}
qse_size_t qse_wcscspn (const qse_wchar_t* str1, const qse_wchar_t* str2)
{
const qse_wchar_t* p1, * p2;
qse_size_t n = 0;
for (p1 = str1; *p1 != QSE_WT('\0'); p1++)
{
for (p2 = str2; *p2 != QSE_WT('\0'); p2++)
{
if (*p2 == *p1) goto done;
}
/* didn't match anything. increment the length */
n++;
}
done:
return n;
}

View File

@ -42,7 +42,7 @@ WVList
0 0
10 10
WPickList WPickList
36 37
11 11
MItem MItem
3 3
@ -529,8 +529,8 @@ WVList
0 0
119 119
MItem MItem
32 33
..\..\..\..\..\lib\cmn\str_spn.c ..\..\..\..\..\lib\cmn\str_pbrk.c
120 120
WString WString
4 4
@ -548,7 +548,7 @@ WVList
123 123
MItem MItem
32 32
..\..\..\..\..\lib\cmn\str_utl.c ..\..\..\..\..\lib\cmn\str_spn.c
124 124
WString WString
4 4
@ -565,8 +565,8 @@ WVList
0 0
127 127
MItem MItem
29 32
..\..\..\..\..\lib\cmn\time.c ..\..\..\..\..\lib\cmn\str_utl.c
128 128
WString WString
4 4
@ -583,8 +583,8 @@ WVList
0 0
131 131
MItem MItem
28 29
..\..\..\..\..\lib\cmn\tio.c ..\..\..\..\..\lib\cmn\time.c
132 132
WString WString
4 4
@ -601,8 +601,8 @@ WVList
0 0
135 135
MItem MItem
32 28
..\..\..\..\..\lib\cmn\tio_get.c ..\..\..\..\..\lib\cmn\tio.c
136 136
WString WString
4 4
@ -620,7 +620,7 @@ WVList
139 139
MItem MItem
32 32
..\..\..\..\..\lib\cmn\tio_put.c ..\..\..\..\..\lib\cmn\tio_get.c
140 140
WString WString
4 4
@ -637,8 +637,8 @@ WVList
0 0
143 143
MItem MItem
28 32
..\..\..\..\..\lib\cmn\xma.c ..\..\..\..\..\lib\cmn\tio_put.c
144 144
WString WString
4 4
@ -655,26 +655,26 @@ WVList
0 0
147 147
MItem MItem
3 28
*.h ..\..\..\..\..\lib\cmn\xma.c
148 148
WString WString
3 4
NIL COBJ
149 149
WVList WVList
0 0
150 150
WVList WVList
0 0
-1 11
1 1
1 1
0 0
151 151
MItem MItem
28 3
..\..\..\..\..\lib\cmn\mem.h *.h
152 152
WString WString
3 3
@ -685,14 +685,14 @@ WVList
154 154
WVList WVList
0 0
147 -1
1 1
1 1
0 0
155 155
MItem MItem
32 28
..\..\..\..\..\lib\cmn\syscall.h ..\..\..\..\..\lib\cmn\mem.h
156 156
WString WString
3 3
@ -703,7 +703,25 @@ WVList
158 158
WVList WVList
0 0
147 151
1
1
0
159
MItem
32
..\..\..\..\..\lib\cmn\syscall.h
160
WString
3
NIL
161
WVList
0
162
WVList
0
151
1 1
1 1
0 0

View File

@ -66,8 +66,8 @@ WRect
WFileName WFileName
30 30
release/os2/lib/cmn/qsecmn.tgt release/os2/lib/cmn/qsecmn.tgt
0 25
14 25
17 17
VComponent VComponent
18 18
@ -124,14 +124,14 @@ WRect
320 320
5700 5700
4240 4240
0 1
0 0
28 28
WFileName WFileName
28 28
debug/os2/lib/cmn/qsecmn.tgt debug/os2/lib/cmn/qsecmn.tgt
19 19
27 26
29 29
VComponent VComponent
30 30
@ -163,7 +163,7 @@ WFileName
28 28
debug/os2/lib/scm/qsescm.tgt debug/os2/lib/scm/qsescm.tgt
0 0
3 4
35 35
VComponent VComponent
36 36
@ -180,4 +180,4 @@ WFileName
debug/os2/cmd/scm/qsescm.tgt debug/os2/cmd/scm/qsescm.tgt
0 0
1 1
26 32

View File

@ -42,7 +42,7 @@ WVList
0 0
10 10
WPickList WPickList
36 37
11 11
MItem MItem
3 3
@ -593,8 +593,8 @@ WVList
0 0
135 135
MItem MItem
32 33
..\..\..\..\..\lib\cmn\str_spn.c ..\..\..\..\..\lib\cmn\str_pbrk.c
136 136
WString WString
4 4
@ -612,47 +612,47 @@ WVList
139 139
MItem MItem
32 32
..\..\..\..\..\lib\cmn\str_utl.c ..\..\..\..\..\lib\cmn\str_spn.c
140 140
WString WString
4 4
COBJ COBJ
141 141
WVList WVList
1
142
MVState
143
WString
3
WCC
144
WString
25
o?2??Include directories:
1
145
WString
54
"$(%watcom)/h;$(%watcom)/h/os2;..\..\..\..\..\include"
0 0
146 142
WVList WVList
0 0
11 11
1 1
1 1
0 0
147 143
MItem MItem
29 32
..\..\..\..\..\lib\cmn\time.c ..\..\..\..\..\lib\cmn\str_utl.c
148 144
WString WString
4 4
COBJ COBJ
149 145
WVList WVList
1
146
MVState
147
WString
3
WCC
148
WString
25
o?2??Include directories:
1
149
WString
54
"$(%watcom)/h;$(%watcom)/h/os2;..\..\..\..\..\include"
0 0
150 150
WVList WVList
@ -663,8 +663,8 @@ WVList
0 0
151 151
MItem MItem
28 29
..\..\..\..\..\lib\cmn\tio.c ..\..\..\..\..\lib\cmn\time.c
152 152
WString WString
4 4
@ -681,8 +681,8 @@ WVList
0 0
155 155
MItem MItem
32 28
..\..\..\..\..\lib\cmn\tio_get.c ..\..\..\..\..\lib\cmn\tio.c
156 156
WString WString
4 4
@ -700,7 +700,7 @@ WVList
159 159
MItem MItem
32 32
..\..\..\..\..\lib\cmn\tio_put.c ..\..\..\..\..\lib\cmn\tio_get.c
160 160
WString WString
4 4
@ -717,8 +717,8 @@ WVList
0 0
163 163
MItem MItem
28 32
..\..\..\..\..\lib\cmn\xma.c ..\..\..\..\..\lib\cmn\tio_put.c
164 164
WString WString
4 4
@ -735,26 +735,26 @@ WVList
0 0
167 167
MItem MItem
3 28
*.h ..\..\..\..\..\lib\cmn\xma.c
168 168
WString WString
3 4
NIL COBJ
169 169
WVList WVList
0 0
170 170
WVList WVList
0 0
-1 11
1 1
1 1
0 0
171 171
MItem MItem
28 3
..\..\..\..\..\lib\cmn\mem.h *.h
172 172
WString WString
3 3
@ -765,14 +765,14 @@ WVList
174 174
WVList WVList
0 0
167 -1
1 1
1 1
0 0
175 175
MItem MItem
32 28
..\..\..\..\..\lib\cmn\syscall.h ..\..\..\..\..\lib\cmn\mem.h
176 176
WString WString
3 3
@ -783,7 +783,25 @@ WVList
178 178
WVList WVList
0 0
167 171
1
1
0
179
MItem
32
..\..\..\..\..\lib\cmn\syscall.h
180
WString
3
NIL
181
WVList
0
182
WVList
0
171
1 1
1 1
0 0