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