File Coverage

tstr_regexp.c
Criterion Covered Total %
statement 50 63 79.3
branch 40 54 74.0
condition n/a
subroutine n/a
pod n/a
total 90 117 76.9


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 8169           static bool fetch_cap_pv(pTHX_ REGEXP *rx, SV *namesv,
12             const char **sp, STRLEN *lenp) {
13 8169           SV *val = reg_named_buff_fetch(rx, namesv, 0);
14 8169 100         if (val && SvOK(val)) {
    50          
15 4657           sv_2mortal(val);
16 4657           *sp = SvPV_const(val, *lenp);
17 4657           return true;
18             }
19 3512 50         if (val)
20 0           SvREFCNT_dec(val);
21 3512           return false;
22             }
23              
24 699           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 699           (void)tstr_parsed_init(p);
33              
34 699 50         if (!CAP_PV(year))
35 0           croak("panic: regexp matched but no 'year' capture");
36 699 50         if (!tstr_token_parse_year(s, len, &v))
37 0           return TSTR_PARSE_ERR_YEAR;
38 699 100         if (len == 2)
39 41           tstr_parsed_set_year2(p, v);
40             else
41 658           tstr_parsed_set_year4(p, v);
42              
43 699 50         if (CAP_PV(month)) {
44 699 100         if (!tstr_token_parse_month(s, len, &v))
45 2           return TSTR_PARSE_ERR_MONTH;
46 697           tstr_parsed_set_month(p, v);
47             } else {
48 0           p->month = 1;
49             }
50              
51 697 50         if (CAP_PV(day)) {
52 697 50         if (!tstr_token_parse_day(s, len, &v))
53 0           return TSTR_PARSE_ERR_DAY;
54 697           tstr_parsed_set_day(p, v);
55             } else {
56 0           p->day = 1;
57             }
58              
59 697 100         if (CAP_PV(day_name)) {
60 125 50         if (!tstr_token_parse_day_name(s, len, &v))
61 0           return TSTR_PARSE_ERR_DAY_NAME;
62 125           tstr_parsed_set_day_name(p, v);
63             }
64              
65 697 100         if (CAP_PV(hour)) {
66 585 50         if (!tstr_token_parse_hour(s, len, &v))
67 0           return TSTR_PARSE_ERR_HOUR;
68 585           tstr_parsed_set_hour(p, v);
69              
70 585 100         if (CAP_PV(meridiem)) {
71 22 50         if (!tstr_token_parse_meridiem(s, len, &v))
72 0           return TSTR_PARSE_ERR_MERIDIEM;
73 22           tstr_parsed_set_meridiem(p, v);
74             }
75              
76 585 100         if (CAP_PV(minute)) {
77 561 50         if (!tstr_token_parse_minute(s, len, &v))
78 0           return TSTR_PARSE_ERR_MINUTE;
79 561           tstr_parsed_set_minute(p, v);
80             }
81              
82 585 100         if (CAP_PV(second)) {
83 521 50         if (!tstr_token_parse_second(s, len, &v))
84 0           return TSTR_PARSE_ERR_SECOND;
85 521           tstr_parsed_set_second(p, v);
86             }
87              
88 585 100         if (CAP_PV(fraction)) {
89 177 50         if (!tstr_token_parse_fraction(s, len, &v))
90 0           return TSTR_PARSE_ERR_FRACTION;
91 177           tstr_parsed_set_fraction(p, v);
92             }
93              
94 585 100         if (CAP_PV(tz_offset)) {
95 282 50         if (!tstr_token_parse_tz_offset(s, len, &v))
96 0           return TSTR_PARSE_ERR_OFFSET;
97 282           tstr_parsed_set_offset(p, v);
98             }
99              
100 585 100         if (CAP_PV(tz_utc))
101 255           tstr_parsed_set_tz_utc(p, s, len);
102              
103 585 100         if (CAP_PV(tz_abbrev))
104 5           tstr_parsed_set_tz_abbrev(p, s, len);
105              
106 585 100         if (CAP_PV(tz_annotation))
107 29           tstr_parsed_set_tz_annotation(p, s, len);
108             }
109              
110             #undef CAP_PV
111              
112 697           return TSTR_PARSE_OK;
113             }