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