scalar_kind.c

filter: Statementstmt 100% 40 / 40 Branchbran 69.7% 53 / 76 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 80.1% 93 / 116 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« datetime.c ↑ Summary types.c »
1 #define PERL_NO_GET_CONTEXT
2 #include "EXTERN.h"
3 #include "perl.h"
4 #include "XSUB.h"
5  
6 #include "scalar_kind.h"
7  
8 1332 SV **fetch_named_value(pTHX_ HV *hv, const char *name, STRLEN len) {
9 1332 SV **value = hv_fetch(hv, name, (I32)len, 0);
10 1332 ▶ if (!value && len && is_utf8_string((const U8 *)name, len))
Branch: 3 branches
BranchTrueFalseTotal
if (!value && len && is_utf8_string((const U8 *)name, len)) 584 748 1332
if (!value && len && is_utf8_string((const U8 *)name, len)) 584 0 584
if (!value && len && is_utf8_string((const U8 *)name, len)) 584 0 584
11 584 value = hv_fetch(hv, name, -(I32)len, 0);
12 1332 return value;
13 }
14  
15 6023 const char *hash_key_bytes(pTHX_ HE *he, STRLEN *len) {
16 6023 ▶ if (HeKLEN(he) == HEf_SVKEY) return SvPV(HeKEY_sv(he), *len);
Branch: 1 branch
BranchTrueFalseTotal
if (HeKLEN(he) == HEf_SVKEY) return SvPV(HeKEY_sv(he), *len); 0 6023 6023
17 6024 ▶ if (HeKWASUTF8(he)) return SvPVutf8(hv_iterkeysv(he), *len);
Branch: 1 branch
BranchTrueFalseTotal
if (HeKWASUTF8(he)) return SvPVutf8(hv_iterkeysv(he), *len); 1 6022 6023
18 6022 *len = (STRLEN)HeKLEN(he);
19 6022 return HeKEY(he);
20 }
21  
22 3868 int looks_stringy(SV *val) {
23 3868 ▶ return SvOK(val) && SvPOK(val) && !SvIOK(val) && !SvNOK(val);
Branch: 4 branches
BranchTrueFalseTotal
return SvOK(val) && SvPOK(val) && !SvIOK(val) && !SvNOK(val); 3868 0 3868
return SvOK(val) && SvPOK(val) && !SvIOK(val) && !SvNOK(val); 3838 30 3868
return SvOK(val) && SvPOK(val) && !SvIOK(val) && !SvNOK(val); 3838 0 3838
return SvOK(val) && SvPOK(val) && !SvIOK(val) && !SvNOK(val); 3838 0 3838
24 }
25  
26 /* "[+-]?digits" (no exponent, no decimal point). */
27 2712 int looks_like_int_str(const char *s, STRLEN len) {
28 2712 STRLEN i = 0;
29 2712 ▶ if (len == 0) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (len == 0) return 0; 1 2711 2712
30 2711 ▶ if (s[0] == '+' || s[0] == '-') i = 1;
Branch: 2 branches
BranchTrueFalseTotal
if (s[0] == '+' || s[0] == '-') i = 1; 2707 4 2711
if (s[0] == '+' || s[0] == '-') i = 1; 66 2641 2707
31 2711 ▶ if (i >= len) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (i >= len) return 0; 0 2711 2711
32 3913 ▶ for (; i < len; i++) if (s[i] < '0' || s[i] > '9') return 0;
Branch: 3 branches
BranchTrueFalseTotal
for (; i < len; i++) if (s[i] < '0' || s[i] > '9') return 0; 3454 156 3610
for (; i < len; i++) if (s[i] < '0' || s[i] > '9') return 0; 2252 1202 3454
for (; i < len; i++) if (s[i] < '0' || s[i] > '9') return 0; 3610 303 3913
33 303 return 1;
34 }
35  
36 /* "[+-]?digits[.digits]?" - no exponent, integer-with-dot allowed. */
37 32 int looks_like_number_str(const char *s, STRLEN len) {
38 32 STRLEN i = 0;
39 32 int seen_digit = 0, seen_dot = 0;
40 32 ▶ if (len == 0) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (len == 0) return 0; 0 32 32
41 32 ▶ if (s[0] == '+' || s[0] == '-') i = 1;
Branch: 2 branches
BranchTrueFalseTotal
if (s[0] == '+' || s[0] == '-') i = 1; 32 0 32
if (s[0] == '+' || s[0] == '-') i = 1; 0 32 32
42 193 ▶ for (; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (; i < len; i++) { 190 3 193
43 190 ▶ if (s[i] == '.') {
Branch: 1 branch
BranchTrueFalseTotal
if (s[i] == '.') { 3 187 190
44 3 ▶ if (seen_dot) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (seen_dot) return 0; 0 3 3
45 3 seen_dot = 1;
46 187 ▶ } else if (s[i] >= '0' && s[i] <= '9') {
Branch: 2 branches
BranchTrueFalseTotal
} else if (s[i] >= '0' && s[i] <= '9') { 158 29 187
} else if (s[i] >= '0' && s[i] <= '9') { 158 0 158
47 158 seen_digit = 1;
48 29 } else return 0;
49 }
50 3 return seen_digit;
51 }
52  
53 /* YYYY-MM-DD prefix - validates digit shape only; range checks happen
54 * in parse_date_string so out-of-range components produce informative
55 * messages with the offending value. */
56 131 int looks_like_date(const char *s, STRLEN len) {
57 int i;
58 131 ▶ if (len < 10) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (len < 10) return 0; 1 130 131
59 650 ▶ for (i = 0; i < 4; i++) if (s[i] < '0' || s[i] > '9') return 0;
Branch: 3 branches
BranchTrueFalseTotal
for (i = 0; i < 4; i++) if (s[i] < '0' || s[i] > '9') return 0; 520 0 520
for (i = 0; i < 4; i++) if (s[i] < '0' || s[i] > '9') return 0; 0 520 520
for (i = 0; i < 4; i++) if (s[i] < '0' || s[i] > '9') return 0; 520 130 650
60 130 ▶ if (s[4] != '-') return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (s[4] != '-') return 0; 1 129 130
61 129 ▶ if (s[5] < '0' || s[5] > '9' || s[6] < '0' || s[6] > '9') return 0;
Branch: 4 branches
BranchTrueFalseTotal
if (s[5] < '0' || s[5] > '9' || s[6] < '0' || s[6] > '9') return 0; 129 0 129
if (s[5] < '0' || s[5] > '9' || s[6] < '0' || s[6] > '9') return 0; 129 0 129
if (s[5] < '0' || s[5] > '9' || s[6] < '0' || s[6] > '9') return 0; 129 0 129
if (s[5] < '0' || s[5] > '9' || s[6] < '0' || s[6] > '9') return 0; 0 129 129
62 129 ▶ if (s[7] != '-') return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (s[7] != '-') return 0; 0 129 129
63 129 ▶ if (s[8] < '0' || s[8] > '9' || s[9] < '0' || s[9] > '9') return 0;
Branch: 4 branches
BranchTrueFalseTotal
if (s[8] < '0' || s[8] > '9' || s[9] < '0' || s[9] > '9') return 0; 129 0 129
if (s[8] < '0' || s[8] > '9' || s[9] < '0' || s[9] > '9') return 0; 129 0 129
if (s[8] < '0' || s[8] > '9' || s[9] < '0' || s[9] > '9') return 0; 129 0 129
if (s[8] < '0' || s[8] > '9' || s[9] < '0' || s[9] > '9') return 0; 0 129 129
64 129 return 1;
65 }
« datetime.c ↑ Summary types.c »