FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
str_convfrom_int.c
Go to the documentation of this file.
1
/* valint function */
2
3
#include "
fb.h
"
4
5
FBCALL
int
fb_hStr2Int
(
char
*src, ssize_t len )
6
{
7
char
*
p
;
8
int
radix, skip;
9
10
/* skip white spc */
11
p =
fb_hStrSkipChar
( src, len, 32 );
12
13
len -= (ssize_t)(p - src);
14
if
( len < 1 )
15
return
0;
16
17
else
if
( (len >= 2) && (p[0] ==
'&'
) )
18
{
19
radix = 0;
20
skip = 2;
21
switch
( p[1] )
22
{
23
case
'h'
:
24
case
'H'
:
25
radix = 16;
26
break
;
27
case
'o'
:
28
case
'O'
:
29
radix = 8;
30
break
;
31
case
'b'
:
32
case
'B'
:
33
radix = 2;
34
break
;
35
36
default
:
/* assume octal */
37
radix = 8;
38
skip = 1;
39
break
;
40
}
41
42
if
( radix != 0 )
43
return
fb_hStrRadix2Int
( &p[skip], len - skip, radix );
44
}
45
46
/* atoi() saturates values outside [-2^31, 2^31)
47
so use strtoul() instead */
48
return
strtoul( p,
NULL
, 10 );
49
}
50
51
FBCALL
int
fb_VALINT
(
FBSTRING
*str )
52
{
53
int
val;
54
55
if
( str ==
NULL
)
56
return
0;
57
58
if
( (str->
data
==
NULL
) || (
FB_STRSIZE
( str ) == 0) )
59
val = 0;
60
else
61
val =
fb_hStr2Int
( str->
data
,
FB_STRSIZE
( str ) );
62
63
/* del if temp */
64
fb_hStrDelTemp
( str );
65
66
return
val;
67
}
rtlib
str_convfrom_int.c
Generated on Thu Jan 23 2014 19:40:12 for FreeBASIC by
1.8.4