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