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