FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
str_trim.c
Go to the documentation of this file.
1
/* trim$ function */
2
3
#include "
fb.h
"
4
5
FBCALL
FBSTRING
*
fb_TRIM
(
FBSTRING
*src )
6
{
7
FBSTRING
*dst;
8
ssize_t len;
9
char
*src_ptr;
10
11
if
( src ==
NULL
)
12
return
&
__fb_ctx
.
null_desc
;
13
14
FB_STRLOCK
();
15
16
len = 0;
17
if
( src->
data
!=
NULL
)
18
{
19
len =
FB_STRSIZE
( src );
20
if
( len > 0 )
21
{
22
src_ptr =
fb_hStrSkipCharRev
( src->
data
, len, 32 );
23
len = (ssize_t)(src_ptr - src->
data
) + 1;
24
}
25
}
26
27
if
( len > 0 )
28
{
29
src_ptr =
fb_hStrSkipChar
( src->
data
,
FB_STRSIZE
( src ), 32 );
30
len -= (ssize_t)(src_ptr - src->
data
);
31
if
( len > 0 )
32
{
33
/* alloc temp string */
34
dst =
fb_hStrAllocTemp_NoLock
(
NULL
, len );
35
if
( dst !=
NULL
)
36
{
37
/* simple copy */
38
fb_hStrCopy
( dst->
data
, src_ptr, len );
39
}
40
else
41
dst = &
__fb_ctx
.
null_desc
;
42
}
43
else
44
dst = &
__fb_ctx
.
null_desc
;
45
}
46
else
47
dst = &
__fb_ctx
.
null_desc
;
48
49
/* del if temp */
50
fb_hStrDelTemp_NoLock
( src );
51
52
FB_STRUNLOCK
();
53
54
return
dst;
55
}
rtlib
str_trim.c
Generated on Thu Jan 23 2014 19:40:13 for FreeBASIC by
1.8.4