FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
str_trimany.c
Go to the documentation of this file.
1
/* trim$ ANY function */
2
3
#include "
fb.h
"
4
5
FBCALL
FBSTRING
*
fb_TrimAny
(
FBSTRING
*src,
FBSTRING
*pattern )
6
{
7
const
char
*pachText =
NULL
;
8
FBSTRING
*dst;
9
ssize_t len;
10
11
if
( src ==
NULL
)
12
{
13
fb_hStrDelTemp
( pattern );
14
return
&
__fb_ctx
.
null_desc
;
15
}
16
17
FB_STRLOCK
();
18
19
len = 0;
20
if
( src->
data
!=
NULL
)
21
{
22
ssize_t len_pattern = ((pattern !=
NULL
) && (pattern->
data
!=
NULL
)?
FB_STRSIZE
( pattern ) : 0);
23
pachText = src->
data
;
24
len =
FB_STRSIZE
( src );
25
if
( len_pattern != 0 )
26
{
27
while
( len != 0 )
28
{
29
ssize_t i;
30
for
( i=0; i!=len_pattern; ++i )
31
{
32
if
(
FB_MEMCHR
( pattern->
data
, *pachText, len_pattern )!=
NULL
)
33
break
;
34
}
35
36
if
( i==len_pattern )
37
break
;
38
39
--len;
40
++pachText;
41
}
42
while
( len != 0 )
43
{
44
ssize_t i;
45
--len;
46
for
( i=0; i!=len_pattern; ++i )
47
{
48
if
(
FB_MEMCHR
( pattern->
data
, pachText[len], len_pattern )!=
NULL
)
49
break
;
50
}
51
52
if
( i==len_pattern )
53
{
54
++len;
55
break
;
56
}
57
}
58
}
59
}
60
61
if
( len > 0 )
62
{
63
/* alloc temp string */
64
dst =
fb_hStrAllocTemp_NoLock
(
NULL
, len );
65
if
( dst !=
NULL
)
66
{
67
/* simple copy */
68
fb_hStrCopy
( dst->
data
, pachText, len );
69
}
70
else
71
dst = &
__fb_ctx
.
null_desc
;
72
}
73
else
74
dst = &
__fb_ctx
.
null_desc
;
75
76
/* del if temp */
77
fb_hStrDelTemp_NoLock
( src );
78
fb_hStrDelTemp_NoLock
( pattern );
79
80
FB_STRUNLOCK
();
81
82
return
dst;
83
}
rtlib
str_trimany.c
Generated on Thu Jan 23 2014 19:40:13 for FreeBASIC by
1.8.4