FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
strw_convfrom.c
Go to the documentation of this file.
1
/* valw function */
2
3
#include "
fb.h
"
4
5
FBCALL
double
fb_WstrToDouble
(
const
FB_WCHAR
*src, ssize_t len )
6
{
7
const
FB_WCHAR
*
p
, *r;
8
int
radix;
9
ssize_t i;
10
FB_WCHAR
*q, c;
11
double
ret;
12
13
/* skip white spc */
14
p =
fb_wstr_SkipChar
( src, len, 32 );
15
16
len -=
fb_wstr_CalcDiff
( src, p );
17
if
( len < 1 )
18
return
0.0;
19
20
r =
p
;
21
if
( (len >= 2) && (*r++ == L
'&'
) )
22
{
23
radix = 0;
24
switch
( *r++ )
25
{
26
case
L
'h'
:
27
case
L
'H'
:
28
radix = 16;
29
break
;
30
case
L
'o'
:
31
case
L
'O'
:
32
radix = 8;
33
break
;
34
case
L
'b'
:
35
case
L
'B'
:
36
radix = 2;
37
break
;
38
39
default
:
/* assume octal */
40
radix = 8;
41
r--;
42
break
;
43
}
44
45
if
( radix != 0 )
46
return
(
double
)
fb_WstrRadix2Longint
( r, len -
fb_wstr_CalcDiff
( p, r ), radix );
47
}
48
49
/* Workaround: wcstod() does not allow 'd' as an exponent specifier on
50
* non-win32 platforms, so create a temporary buffer and replace any
51
* 'd's with 'e'
52
*/
53
q = malloc( (len + 1) *
sizeof
(
FB_WCHAR
) );
54
for
( i = 0; i < len; i++ )
55
{
56
c = p[i];
57
if
( c == L
'd'
|| c == L
'D'
)
58
++c;
59
q[i]= c;
60
}
61
q[len] = L
'\0'
;
62
ret =
wcstod
( q,
NULL
);
63
free( q );
64
65
return
ret;
66
}
67
68
FBCALL
double
fb_WstrVal
(
const
FB_WCHAR
*str )
69
{
70
double
val;
71
ssize_t len;
72
73
if
( str ==
NULL
)
74
return
0.0;
75
76
len =
fb_wstr_Len
( str );
77
if
( len == 0 )
78
val = 0.0;
79
else
80
val =
fb_WstrToDouble
( str, len );
81
82
return
val;
83
}
rtlib
strw_convfrom.c
Generated on Thu Jan 23 2014 19:40:13 for FreeBASIC by
1.8.4