1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
MODULE = XS::APItest PACKAGE = XS::APItest::numeric
void
grok_number(number)
SV *number
PREINIT:
STRLEN len;
const char *pv = SvPV(number, len);
UV value;
int result;
PPCODE:
EXTEND(SP,2);
result = grok_number(pv, len, &value);
PUSHs(sv_2mortal(newSViv(result)));
if (result & IS_NUMBER_IN_UV)
PUSHs(sv_2mortal(newSVuv(value)));
void
grok_number_flags(number, flags)
SV *number
U32 flags
PREINIT:
STRLEN len;
const char *pv = SvPV(number, len);
UV value;
int result;
PPCODE:
EXTEND(SP,2);
result = grok_number_flags(pv, len, &value, flags);
PUSHs(sv_2mortal(newSViv(result)));
if (result & IS_NUMBER_IN_UV)
PUSHs(sv_2mortal(newSVuv(value)));
void
grok_atoUV(number, endsv)
SV *number
SV *endsv
PREINIT:
STRLEN len;
const char *pv = SvPV(number, len);
UV value = 0xdeadbeef;
bool result;
const char* endptr;
PPCODE:
EXTEND(SP,2);
if (endsv == &PL_sv_undef) {
result = grok_atoUV(pv, &value, NULL);
} else {
result = grok_atoUV(pv, &value, &endptr);
}
PUSHs(result ? &PL_sv_yes : &PL_sv_no);
PUSHs(sv_2mortal(newSVuv(value)));
if (endsv == &PL_sv_undef) {
PUSHs(sv_2mortal(newSVpvn(NULL, 0)));
} else {
if (endptr) {
PUSHs(sv_2mortal(newSViv(endptr - pv)));
} else {
PUSHs(sv_2mortal(newSViv(0)));
}
}
|