| 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 |
827 |
| SV **fetch_named_value(pTHX_ HV *hv, const char *name, STRLEN len) { |
| 9 |
827 |
| SV **value = hv_fetch(hv, name, (I32)len, 0); |
| 10 |
827 |
▶ | if (!value && len && is_utf8_string((const U8 *)name, len)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!value && len && is_utf8_string((const U8 *)name, len)) |
524 |
303 |
827 |
| if (!value && len && is_utf8_string((const U8 *)name, len)) |
524 |
0 |
524 |
| if (!value && len && is_utf8_string((const U8 *)name, len)) |
524 |
0 |
524 |
|
| 11 |
524 |
| value = hv_fetch(hv, name, -(I32)len, 0); |
| 12 |
827 |
| return value; |
| 13 |
|
| } |
| 14 |
|
| |
| 15 |
6016 |
| const char *hash_key_bytes(pTHX_ HE *he, STRLEN *len) { |
| 16 |
6016 |
▶ | if (HeKLEN(he) == HEf_SVKEY) return SvPV(HeKEY_sv(he), *len); |
Branch: 1 branch
| Branch | True | False | Total |
| if (HeKLEN(he) == HEf_SVKEY) return SvPV(HeKEY_sv(he), *len); |
0 |
6016 |
6016 |
|
| 17 |
6017 |
▶ | if (HeKWASUTF8(he)) return SvPVutf8(hv_iterkeysv(he), *len); |
Branch: 1 branch
| Branch | True | False | Total |
| if (HeKWASUTF8(he)) return SvPVutf8(hv_iterkeysv(he), *len); |
1 |
6015 |
6016 |
|
| 18 |
6015 |
| *len = (STRLEN)HeKLEN(he); |
| 19 |
6015 |
| return HeKEY(he); |
| 20 |
|
| } |
| 21 |
|
| |
| 22 |
3854 |
| int looks_stringy(SV *val) { |
| 23 |
3854 |
▶ | return SvOK(val) && SvPOK(val) && !SvIOK(val) && !SvNOK(val); |
Branch: 4 branches
| Branch | True | False | Total |
| return SvOK(val) && SvPOK(val) && !SvIOK(val) && !SvNOK(val); |
3854 |
0 |
3854 |
| return SvOK(val) && SvPOK(val) && !SvIOK(val) && !SvNOK(val); |
3828 |
26 |
3854 |
| return SvOK(val) && SvPOK(val) && !SvIOK(val) && !SvNOK(val); |
3828 |
0 |
3828 |
| return SvOK(val) && SvPOK(val) && !SvIOK(val) && !SvNOK(val); |
3828 |
0 |
3828 |
|
| 24 |
|
| } |
| 25 |
|
| |
| 26 |
|
| /* "[+-]?digits" (no exponent, no decimal point). */ |
| 27 |
2685 |
| int looks_like_int_str(const char *s, STRLEN len) { |
| 28 |
2685 |
| STRLEN i = 0; |
| 29 |
2685 |
▶ | if (len == 0) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == 0) return 0; |
0 |
2685 |
2685 |
|
| 30 |
2685 |
▶ | if (s[0] == '+' || s[0] == '-') i = 1; |
Branch: 2 branches
| Branch | True | False | Total |
| if (s[0] == '+' || s[0] == '-') i = 1; |
2681 |
4 |
2685 |
| if (s[0] == '+' || s[0] == '-') i = 1; |
66 |
2615 |
2681 |
|
| 31 |
2685 |
▶ | if (i >= len) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (i >= len) return 0; |
0 |
2685 |
2685 |
|
| 32 |
3856 |
▶ | for (; i < len; i++) if (s[i] < '0' || s[i] > '9') return 0; |
Branch: 3 branches
| Branch | True | False | Total |
| for (; i < len; i++) if (s[i] < '0' || s[i] > '9') return 0; |
3414 |
150 |
3564 |
| for (; i < len; i++) if (s[i] < '0' || s[i] > '9') return 0; |
2243 |
1171 |
3414 |
| for (; i < len; i++) if (s[i] < '0' || s[i] > '9') return 0; |
3564 |
292 |
3856 |
|
| 33 |
292 |
| 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
| Branch | True | False | Total |
| if (len == 0) return 0; |
0 |
32 |
32 |
|
| 41 |
32 |
▶ | if (s[0] == '+' || s[0] == '-') i = 1; |
Branch: 2 branches
| Branch | True | False | Total |
| 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
| Branch | True | False | Total |
| for (; i < len; i++) { |
190 |
3 |
193 |
|
| 43 |
190 |
▶ | if (s[i] == '.') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s[i] == '.') { |
3 |
187 |
190 |
|
| 44 |
3 |
▶ | if (seen_dot) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| 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
| Branch | True | False | Total |
| } 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 |
127 |
| int looks_like_date(const char *s, STRLEN len) { |
| 57 |
|
| int i; |
| 58 |
127 |
▶ | if (len < 10) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (len < 10) return 0; |
1 |
126 |
127 |
|
| 59 |
630 |
▶ | for (i = 0; i < 4; i++) if (s[i] < '0' || s[i] > '9') return 0; |
Branch: 3 branches
| Branch | True | False | Total |
| for (i = 0; i < 4; i++) if (s[i] < '0' || s[i] > '9') return 0; |
504 |
0 |
504 |
| for (i = 0; i < 4; i++) if (s[i] < '0' || s[i] > '9') return 0; |
0 |
504 |
504 |
| for (i = 0; i < 4; i++) if (s[i] < '0' || s[i] > '9') return 0; |
504 |
126 |
630 |
|
| 60 |
126 |
▶ | if (s[4] != '-') return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (s[4] != '-') return 0; |
1 |
125 |
126 |
|
| 61 |
125 |
▶ | if (s[5] < '0' || s[5] > '9' || s[6] < '0' || s[6] > '9') return 0; |
Branch: 4 branches
| Branch | True | False | Total |
| if (s[5] < '0' || s[5] > '9' || s[6] < '0' || s[6] > '9') return 0; |
125 |
0 |
125 |
| if (s[5] < '0' || s[5] > '9' || s[6] < '0' || s[6] > '9') return 0; |
125 |
0 |
125 |
| if (s[5] < '0' || s[5] > '9' || s[6] < '0' || s[6] > '9') return 0; |
125 |
0 |
125 |
| if (s[5] < '0' || s[5] > '9' || s[6] < '0' || s[6] > '9') return 0; |
0 |
125 |
125 |
|
| 62 |
125 |
▶ | if (s[7] != '-') return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (s[7] != '-') return 0; |
0 |
125 |
125 |
|
| 63 |
125 |
▶ | if (s[8] < '0' || s[8] > '9' || s[9] < '0' || s[9] > '9') return 0; |
Branch: 4 branches
| Branch | True | False | Total |
| if (s[8] < '0' || s[8] > '9' || s[9] < '0' || s[9] > '9') return 0; |
125 |
0 |
125 |
| if (s[8] < '0' || s[8] > '9' || s[9] < '0' || s[9] > '9') return 0; |
125 |
0 |
125 |
| if (s[8] < '0' || s[8] > '9' || s[9] < '0' || s[9] > '9') return 0; |
125 |
0 |
125 |
| if (s[8] < '0' || s[8] > '9' || s[9] < '0' || s[9] > '9') return 0; |
0 |
125 |
125 |
|
| 64 |
125 |
| return 1; |
| 65 |
|
| } |