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