File Coverage

tstr_regexp.c
Criterion Covered Total %
statement 46 63 73.0
branch 35 54 64.8
condition n/a
subroutine n/a
pod n/a
total 81 117 69.2


line stmt bran cond sub pod time code
1             #define PERL_NO_GET_CONTEXT
2             #include "EXTERN.h"
3             #include "perl.h"
4             #include "XSUB.h"
5              
6             #include "tstr_sv.h"
7             #include "tstr_parsed.h"
8             #include "tstr_token_parse.h"
9             #include "tstr_parse_result.h"
10              
11 2849           static bool fetch_cap_pv(pTHX_ REGEXP *rx, SV *namesv,
12             const char **sp, STRLEN *lenp) {
13 2849           SV *val = reg_named_buff_fetch(rx, namesv, 0);
14 2849 100         if (val && SvOK(val)) {
    50          
15 1648           sv_2mortal(val);
16 1648           *sp = SvPV_const(val, *lenp);
17 1648           return true;
18             }
19 1201 50         if (val)
20 0           SvREFCNT_dec(val);
21 1201           return false;
22             }
23              
24 221           tstr_parse_result_t tstr_regexp_extract(pTHX_ REGEXP *rx, tstr_parsed_t *p,
25             tstr_sv_keys_t *keys) {
26             const char *s;
27             STRLEN len;
28             int v;
29              
30             #define CAP_PV(field) fetch_cap_pv(aTHX_ rx, keys->k_##field, &s, &len)
31              
32 221           (void)tstr_parsed_init(p);
33              
34 221 50         if (!CAP_PV(year))
35 0           croak("panic: regexp matched but no 'year' capture");
36 221 50         if (!tstr_token_parse_year(s, len, &v))
37 0           return TSTR_PARSE_ERR_YEAR;
38 221 100         if (len == 2)
39 41           tstr_parsed_set_year2(p, v);
40             else
41 180           tstr_parsed_set_year4(p, v);
42              
43 221 50         if (CAP_PV(month)) {
44 221 50         if (!tstr_token_parse_month(s, len, &v))
45 0           return TSTR_PARSE_ERR_MONTH;
46 221           tstr_parsed_set_month(p, v);
47             } else {
48 0           p->month = 1;
49             }
50              
51 221 50         if (CAP_PV(day)) {
52 221 50         if (!tstr_token_parse_day(s, len, &v))
53 0           return TSTR_PARSE_ERR_DAY;
54 221           tstr_parsed_set_day(p, v);
55             } else {
56 0           p->day = 1;
57             }
58              
59 221 100         if (CAP_PV(day_name)) {
60 106 50         if (!tstr_token_parse_day_name(s, len, &v))
61 0           return TSTR_PARSE_ERR_DAY_NAME;
62 106           tstr_parsed_set_day_name(p, v);
63             }
64              
65 221 100         if (CAP_PV(hour)) {
66 218 50         if (!tstr_token_parse_hour(s, len, &v))
67 0           return TSTR_PARSE_ERR_HOUR;
68 218           tstr_parsed_set_hour(p, v);
69              
70 218 50         if (CAP_PV(meridiem)) {
71 0 0         if (!tstr_token_parse_meridiem(s, len, &v))
72 0           return TSTR_PARSE_ERR_MERIDIEM;
73 0           tstr_parsed_set_meridiem(p, v);
74             }
75              
76 218 50         if (CAP_PV(minute)) {
77 218 50         if (!tstr_token_parse_minute(s, len, &v))
78 0           return TSTR_PARSE_ERR_MINUTE;
79 218           tstr_parsed_set_minute(p, v);
80             }
81              
82 218 100         if (CAP_PV(second)) {
83 213 50         if (!tstr_token_parse_second(s, len, &v))
84 0           return TSTR_PARSE_ERR_SECOND;
85 213           tstr_parsed_set_second(p, v);
86             }
87              
88 218 100         if (CAP_PV(fraction)) {
89 22 50         if (!tstr_token_parse_fraction(s, len, &v))
90 0           return TSTR_PARSE_ERR_FRACTION;
91 22           tstr_parsed_set_fraction(p, v);
92             }
93              
94 218 100         if (CAP_PV(tz_offset)) {
95 139 50         if (!tstr_token_parse_tz_offset(s, len, &v))
96 0           return TSTR_PARSE_ERR_OFFSET;
97 139           tstr_parsed_set_offset(p, v);
98             }
99              
100 218 100         if (CAP_PV(tz_utc))
101 66           tstr_parsed_set_tz_utc(p, s, len);
102              
103 218 100         if (CAP_PV(tz_abbrev))
104 3           tstr_parsed_set_tz_abbrev(p, s, len);
105              
106 218 50         if (CAP_PV(tz_annotation))
107 0           tstr_parsed_set_tz_annotation(p, s, len);
108             }
109              
110             #undef CAP_PV
111              
112 221           return TSTR_PARSE_OK;
113             }