| 1 |
|
| /* |
| 2 |
|
| * Copyright 1999-2016, Gisle Aas |
| 3 |
|
| * Copyright 1999-2000, Michael A. Chase |
| 4 |
|
| * |
| 5 |
|
| * This library is free software; you can redistribute it and/or |
| 6 |
|
| * modify it under the same terms as Perl itself. |
| 7 |
|
| */ |
| 8 |
|
| |
| 9 |
|
| #ifndef EXTERN |
| 10 |
|
| #define EXTERN extern |
| 11 |
|
| #endif |
| 12 |
|
| |
| 13 |
|
| #include "hctype.h" /* isH...() macros */ |
| 14 |
|
| #include "tokenpos.h" /* dTOKEN; PUSH_TOKEN() */ |
| 15 |
|
| |
| 16 |
|
| |
| 17 |
|
| const static |
| 18 |
|
| struct literal_tag { |
| 19 |
|
| int len; |
| 20 |
|
| char* str; |
| 21 |
|
| int is_cdata; |
| 22 |
|
| } |
| 23 |
|
| literal_mode_elem[] = |
| 24 |
|
| { |
| 25 |
|
| {6, "script", 1}, |
| 26 |
|
| {5, "style", 1}, |
| 27 |
|
| {3, "xmp", 1}, |
| 28 |
|
| {6, "iframe", 1}, |
| 29 |
|
| {9, "plaintext", 1}, |
| 30 |
|
| {5, "title", 0}, |
| 31 |
|
| {8, "textarea", 0}, |
| 32 |
|
| {0, 0, 0} |
| 33 |
|
| }; |
| 34 |
|
| |
| 35 |
|
| enum argcode { |
| 36 |
|
| ARG_SELF = 1, /* need to avoid '\0' in argspec string */ |
| 37 |
|
| ARG_TOKENS, |
| 38 |
|
| ARG_TOKENPOS, |
| 39 |
|
| ARG_TOKEN0, |
| 40 |
|
| ARG_TAGNAME, |
| 41 |
|
| ARG_TAG, |
| 42 |
|
| ARG_ATTR, |
| 43 |
|
| ARG_ATTRARR, |
| 44 |
|
| ARG_ATTRSEQ, |
| 45 |
|
| ARG_TEXT, |
| 46 |
|
| ARG_DTEXT, |
| 47 |
|
| ARG_IS_CDATA, |
| 48 |
|
| ARG_SKIPPED_TEXT, |
| 49 |
|
| ARG_OFFSET, |
| 50 |
|
| ARG_OFFSET_END, |
| 51 |
|
| ARG_LENGTH, |
| 52 |
|
| ARG_LINE, |
| 53 |
|
| ARG_COLUMN, |
| 54 |
|
| ARG_EVENT, |
| 55 |
|
| ARG_UNDEF, |
| 56 |
|
| ARG_LITERAL, /* Always keep last */ |
| 57 |
|
| |
| 58 |
|
| /* extra flags always encoded first */ |
| 59 |
|
| ARG_FLAG_FLAT_ARRAY |
| 60 |
|
| }; |
| 61 |
|
| |
| 62 |
|
| static const char * const argname[] = { |
| 63 |
|
| /* Must be in the same order as enum argcode */ |
| 64 |
|
| "self", /* ARG_SELF */ |
| 65 |
|
| "tokens", /* ARG_TOKENS */ |
| 66 |
|
| "tokenpos", /* ARG_TOKENPOS */ |
| 67 |
|
| "token0", /* ARG_TOKEN0 */ |
| 68 |
|
| "tagname", /* ARG_TAGNAME */ |
| 69 |
|
| "tag", /* ARG_TAG */ |
| 70 |
|
| "attr", /* ARG_ATTR */ |
| 71 |
|
| "@attr", /* ARG_ATTRARR */ |
| 72 |
|
| "attrseq", /* ARG_ATTRSEQ */ |
| 73 |
|
| "text", /* ARG_TEXT */ |
| 74 |
|
| "dtext", /* ARG_DTEXT */ |
| 75 |
|
| "is_cdata", /* ARG_IS_CDATA */ |
| 76 |
|
| "skipped_text", /* ARG_SKIPPED_TEXT */ |
| 77 |
|
| "offset", /* ARG_OFFSET */ |
| 78 |
|
| "offset_end", /* ARG_OFFSET_END */ |
| 79 |
|
| "length", /* ARG_LENGTH */ |
| 80 |
|
| "line", /* ARG_LINE */ |
| 81 |
|
| "column", /* ARG_COLUMN */ |
| 82 |
|
| "event", /* ARG_EVENT */ |
| 83 |
|
| "undef", /* ARG_UNDEF */ |
| 84 |
|
| /* ARG_LITERAL (not compared) */ |
| 85 |
|
| /* ARG_FLAG_FLAT_ARRAY */ |
| 86 |
|
| }; |
| 87 |
|
| |
| 88 |
|
| #define CASE_SENSITIVE(p_state) \ |
| 89 |
|
| ((p_state)->xml_mode || (p_state)->case_sensitive) |
| 90 |
|
| #define STRICT_NAMES(p_state) \ |
| 91 |
|
| ((p_state)->xml_mode || (p_state)->strict_names) |
| 92 |
|
| #define ALLOW_EMPTY_TAG(p_state) \ |
| 93 |
|
| ((p_state)->xml_mode || (p_state)->empty_element_tags) |
| 94 |
|
| |
| 95 |
|
| static void flush_pending_text(PSTATE* p_state, SV* self); |
| 96 |
|
| |
| 97 |
|
| /* |
| 98 |
|
| * Parser functions. |
| 99 |
|
| * |
| 100 |
|
| * parse() - top level entry point. |
| 101 |
|
| * deals with text and calls one of its |
| 102 |
|
| * subordinate parse_*() routines after |
| 103 |
|
| * looking at the first char after "<" |
| 104 |
|
| * parse_decl() - deals with declarations <!...> |
| 105 |
|
| * parse_comment() - deals with <!-- ... --> |
| 106 |
|
| * parse_marked_section - deals with <![ ... [ ... ]]> |
| 107 |
|
| * parse_end() - deals with end tags </...> |
| 108 |
|
| * parse_start() - deals with start tags <A...> |
| 109 |
|
| * parse_process() - deals with process instructions <?...> |
| 110 |
|
| * parse_null() - deals with anything else <....> |
| 111 |
|
| * |
| 112 |
|
| * report_event() - called whenever any of the parse*() routines |
| 113 |
|
| * has recongnized something. |
| 114 |
|
| */ |
| 115 |
|
| |
| 116 |
|
| static void |
| 117 |
32213 |
| report_event(PSTATE* p_state, |
| 118 |
|
| event_id_t event, |
| 119 |
|
| char *beg, char *end, U32 utf8, |
| 120 |
|
| token_pos_t *tokens, int num_tokens, |
| 121 |
|
| SV* self |
| 122 |
|
| ) |
| 123 |
|
| { |
| 124 |
|
| struct p_handler *h; |
| 125 |
|
| dTHX; |
| 126 |
32213 |
| dSP; |
| 127 |
|
| AV *array; |
| 128 |
|
| STRLEN my_na; |
| 129 |
|
| char *argspec; |
| 130 |
|
| char *s; |
| 131 |
|
| STRLEN offset; |
| 132 |
|
| STRLEN line; |
| 133 |
|
| STRLEN column; |
| 134 |
|
| |
| 135 |
|
| #define CHR_DIST(a,b) (utf8 ? utf8_distance((U8*)(a),(U8*)(b)) : (a) - (b)) |
| 136 |
|
| |
| 137 |
|
| /* some events might still fire after a handler has signaled eof |
| 138 |
|
| * so suppress them here. |
| 139 |
|
| */ |
| 140 |
32213 |
▶ | if (p_state->eof) |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->eof) |
4 |
32209 |
32213 |
|
| 141 |
4 |
| return; |
| 142 |
|
| |
| 143 |
|
| /* capture offsets */ |
| 144 |
32209 |
| offset = p_state->offset; |
| 145 |
32209 |
| line = p_state->line; |
| 146 |
32209 |
| column = p_state->column; |
| 147 |
|
| |
| 148 |
|
| #if 0 |
| 149 |
|
| { /* used for debugging at some point */ |
| 150 |
|
| char *s = beg; |
| 151 |
|
| int i; |
| 152 |
|
| |
| 153 |
|
| /* print debug output */ |
| 154 |
|
| switch(event) { |
| 155 |
|
| case E_DECLARATION: printf("DECLARATION"); break; |
| 156 |
|
| case E_COMMENT: printf("COMMENT"); break; |
| 157 |
|
| case E_START: printf("START"); break; |
| 158 |
|
| case E_END: printf("END"); break; |
| 159 |
|
| case E_TEXT: printf("TEXT"); break; |
| 160 |
|
| case E_PROCESS: printf("PROCESS"); break; |
| 161 |
|
| case E_NONE: printf("NONE"); break; |
| 162 |
|
| default: printf("EVENT #%d", event); break; |
| 163 |
|
| } |
| 164 |
|
| |
| 165 |
|
| printf(" ["); |
| 166 |
|
| while (s < end) { |
| 167 |
|
| if (*s == '\n') { |
| 168 |
|
| putchar('\\'); putchar('n'); |
| 169 |
|
| } |
| 170 |
|
| else |
| 171 |
|
| putchar(*s); |
| 172 |
|
| s++; |
| 173 |
|
| } |
| 174 |
|
| printf("] %d\n", end - beg); |
| 175 |
|
| for (i = 0; i < num_tokens; i++) { |
| 176 |
|
| printf(" token %d: %d %d\n", |
| 177 |
|
| i, |
| 178 |
|
| tokens[i].beg - beg, |
| 179 |
|
| tokens[i].end - tokens[i].beg); |
| 180 |
|
| } |
| 181 |
|
| } |
| 182 |
|
| #endif |
| 183 |
|
| |
| 184 |
32209 |
▶ | if (p_state->pending_end_tag && event != E_TEXT && event != E_COMMENT) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (p_state->pending_end_tag && event != E_TEXT && event != E_COMMENT) { |
0 |
32209 |
32209 |
| if (p_state->pending_end_tag && event != E_TEXT && event != E_COMMENT) { |
0 |
0 |
0 |
| if (p_state->pending_end_tag && event != E_TEXT && event != E_COMMENT) { |
0 |
0 |
0 |
|
| 185 |
|
| token_pos_t t; |
| 186 |
|
| char dummy; |
| 187 |
0 |
| t.beg = p_state->pending_end_tag; |
| 188 |
0 |
| t.end = p_state->pending_end_tag + strlen(p_state->pending_end_tag); |
| 189 |
0 |
| p_state->pending_end_tag = 0; |
| 190 |
0 |
| report_event(p_state, E_END, &dummy, &dummy, 0, &t, 1, self); |
| 191 |
0 |
| SPAGAIN; |
| 192 |
|
| } |
| 193 |
|
| |
| 194 |
|
| /* update offsets */ |
| 195 |
32209 |
▶ | p_state->offset += CHR_DIST(end, beg); |
Branch: 1 branch
| Branch | True | False | Total |
| p_state->offset += CHR_DIST(end, beg); |
154 |
32055 |
32209 |
|
| 196 |
32209 |
▶ | if (line) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (line) { |
122 |
32087 |
32209 |
|
| 197 |
122 |
| char *s = beg; |
| 198 |
122 |
| char *nl = NULL; |
| 199 |
840 |
▶ | while (s < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (s < end) { |
718 |
122 |
840 |
|
| 200 |
718 |
▶ | if (*s == '\n') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '\n') { |
31 |
687 |
718 |
|
| 201 |
31 |
| p_state->line++; |
| 202 |
31 |
| nl = s; |
| 203 |
|
| } |
| 204 |
718 |
| s++; |
| 205 |
|
| } |
| 206 |
122 |
▶ | if (nl) |
Branch: 1 branch
| Branch | True | False | Total |
| if (nl) |
27 |
95 |
122 |
|
| 207 |
27 |
▶ | p_state->column = CHR_DIST(end, nl) - 1; |
Branch: 1 branch
| Branch | True | False | Total |
| p_state->column = CHR_DIST(end, nl) - 1; |
10 |
17 |
27 |
|
| 208 |
|
| else |
| 209 |
95 |
▶ | p_state->column += CHR_DIST(end, beg); |
Branch: 1 branch
| Branch | True | False | Total |
| p_state->column += CHR_DIST(end, beg); |
22 |
73 |
95 |
|
| 210 |
|
| } |
| 211 |
|
| |
| 212 |
32209 |
▶ | if (event == E_NONE) |
Branch: 1 branch
| Branch | True | False | Total |
| if (event == E_NONE) |
32 |
32177 |
32209 |
|
| 213 |
32 |
| goto IGNORE_EVENT; |
| 214 |
|
| |
| 215 |
|
| #ifdef MARKED_SECTION |
| 216 |
32177 |
▶ | if (p_state->ms == MS_IGNORE) |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->ms == MS_IGNORE) |
4 |
32173 |
32177 |
|
| 217 |
4 |
| goto IGNORE_EVENT; |
| 218 |
|
| #endif |
| 219 |
|
| |
| 220 |
|
| /* tag filters */ |
| 221 |
32173 |
▶ | if (p_state->ignore_tags || p_state->report_tags || p_state->ignore_elements) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (p_state->ignore_tags || p_state->report_tags || p_state->ignore_elements) { |
32043 |
130 |
32173 |
| if (p_state->ignore_tags || p_state->report_tags || p_state->ignore_elements) { |
31957 |
86 |
32043 |
| if (p_state->ignore_tags || p_state->report_tags || p_state->ignore_elements) { |
197 |
31760 |
31957 |
|
| 222 |
|
| |
| 223 |
533 |
▶ | if (event == E_START || event == E_END) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (event == E_START || event == E_END) { |
308 |
105 |
413 |
| if (event == E_START || event == E_END) { |
62 |
246 |
308 |
|
| 224 |
167 |
| SV* tagname = p_state->tmp; |
| 225 |
|
| |
| 226 |
|
| assert(num_tokens >= 1); |
| 227 |
167 |
| sv_setpvn(tagname, tokens[0].beg, tokens[0].end - tokens[0].beg); |
| 228 |
167 |
▶ | if (utf8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (utf8) |
38 |
129 |
167 |
|
| 229 |
38 |
| SvUTF8_on(tagname); |
| 230 |
|
| else |
| 231 |
129 |
| SvUTF8_off(tagname); |
| 232 |
167 |
▶ | if (!CASE_SENSITIVE(p_state)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!CASE_SENSITIVE(p_state)) |
159 |
8 |
167 |
| if (!CASE_SENSITIVE(p_state)) |
155 |
4 |
159 |
|
| 233 |
155 |
| sv_lower(aTHX_ tagname); |
| 234 |
|
| |
| 235 |
167 |
▶ | if (p_state->ignoring_element) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->ignoring_element) { |
7 |
160 |
167 |
|
| 236 |
7 |
▶ | if (sv_eq(p_state->ignoring_element, tagname)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_eq(p_state->ignoring_element, tagname)) { |
7 |
0 |
7 |
|
| 237 |
7 |
▶ | if (event == E_START) |
Branch: 1 branch
| Branch | True | False | Total |
| if (event == E_START) |
0 |
7 |
7 |
|
| 238 |
0 |
| p_state->ignore_depth++; |
| 239 |
7 |
▶ | else if (--p_state->ignore_depth == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (--p_state->ignore_depth == 0) { |
7 |
0 |
7 |
|
| 240 |
7 |
| SvREFCNT_dec(p_state->ignoring_element); |
| 241 |
7 |
| p_state->ignoring_element = 0; |
| 242 |
|
| } |
| 243 |
|
| } |
| 244 |
7 |
| goto IGNORE_EVENT; |
| 245 |
|
| } |
| 246 |
|
| |
| 247 |
244 |
| if (p_state->ignore_elements && |
| 248 |
84 |
| hv_fetch_ent(p_state->ignore_elements, tagname, 0, 0)) |
| 249 |
|
| { |
| 250 |
8 |
▶ | if (event == E_START) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (event == E_START) { |
7 |
1 |
8 |
|
| 251 |
7 |
| p_state->ignoring_element = newSVsv(tagname); |
| 252 |
7 |
| p_state->ignore_depth = 1; |
| 253 |
|
| } |
| 254 |
8 |
| goto IGNORE_EVENT; |
| 255 |
|
| } |
| 256 |
|
| |
| 257 |
205 |
| if (p_state->ignore_tags && |
| 258 |
53 |
| hv_fetch_ent(p_state->ignore_tags, tagname, 0, 0)) |
| 259 |
|
| { |
| 260 |
20 |
| goto IGNORE_EVENT; |
| 261 |
|
| } |
| 262 |
174 |
| if (p_state->report_tags && |
| 263 |
42 |
| !hv_fetch_ent(p_state->report_tags, tagname, 0, 0)) |
| 264 |
|
| { |
| 265 |
12 |
| goto IGNORE_EVENT; |
| 266 |
|
| } |
| 267 |
|
| } |
| 268 |
246 |
▶ | else if (p_state->ignoring_element) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (p_state->ignoring_element) { |
7 |
239 |
246 |
|
| 269 |
7 |
| goto IGNORE_EVENT; |
| 270 |
|
| } |
| 271 |
|
| } |
| 272 |
|
| |
| 273 |
32119 |
| h = &p_state->handlers[event]; |
| 274 |
32119 |
▶ | if (!h->cb) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->cb) { |
3286 |
28833 |
32119 |
|
| 275 |
|
| /* event = E_DEFAULT; */ |
| 276 |
3286 |
| h = &p_state->handlers[E_DEFAULT]; |
| 277 |
3286 |
▶ | if (!h->cb) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->cb) |
2178 |
1108 |
3286 |
|
| 278 |
2178 |
| goto IGNORE_EVENT; |
| 279 |
|
| } |
| 280 |
|
| |
| 281 |
29941 |
▶ | if (SvTYPE(h->cb) != SVt_PVAV && !SvTRUE(h->cb)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTYPE(h->cb) != SVt_PVAV && !SvTRUE(h->cb)) { |
16498 |
13443 |
29941 |
| if (SvTYPE(h->cb) != SVt_PVAV && !SvTRUE(h->cb)) { |
7 |
16491 |
16498 |
|
| 282 |
|
| /* FALSE scalar ('' or 0) means IGNORE this event */ |
| 283 |
7 |
| return; |
| 284 |
|
| } |
| 285 |
|
| |
| 286 |
29934 |
▶ | if (p_state->unbroken_text && event == E_TEXT) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (p_state->unbroken_text && event == E_TEXT) { |
8981 |
20953 |
29934 |
| if (p_state->unbroken_text && event == E_TEXT) { |
4510 |
4471 |
8981 |
|
| 287 |
|
| /* should buffer text */ |
| 288 |
4510 |
▶ | if (!p_state->pend_text) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!p_state->pend_text) |
16 |
4494 |
4510 |
|
| 289 |
16 |
| p_state->pend_text = newSV(256); |
| 290 |
4510 |
▶ | if (SvOK(p_state->pend_text)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(p_state->pend_text)) { |
4356 |
154 |
4510 |
|
| 291 |
154 |
▶ | if (p_state->is_cdata != p_state->pend_text_is_cdata) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->is_cdata != p_state->pend_text_is_cdata) { |
2 |
152 |
154 |
|
| 292 |
2 |
| flush_pending_text(p_state, self); |
| 293 |
2 |
| SPAGAIN; |
| 294 |
2 |
| goto INIT_PEND_TEXT; |
| 295 |
|
| } |
| 296 |
|
| } |
| 297 |
|
| else { |
| 298 |
4356 |
| INIT_PEND_TEXT: |
| 299 |
4358 |
| p_state->pend_text_offset = offset; |
| 300 |
4358 |
| p_state->pend_text_line = line; |
| 301 |
4358 |
| p_state->pend_text_column = column; |
| 302 |
4358 |
| p_state->pend_text_is_cdata = p_state->is_cdata; |
| 303 |
4358 |
| sv_setpvs(p_state->pend_text, ""); |
| 304 |
4358 |
▶ | if (!utf8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!utf8) |
4358 |
0 |
4358 |
|
| 305 |
4358 |
| SvUTF8_off(p_state->pend_text); |
| 306 |
|
| } |
| 307 |
4510 |
▶ | if (utf8 && !SvUTF8(p_state->pend_text)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (utf8 && !SvUTF8(p_state->pend_text)) |
0 |
4510 |
4510 |
| if (utf8 && !SvUTF8(p_state->pend_text)) |
0 |
0 |
0 |
|
| 308 |
0 |
| sv_utf8_upgrade(p_state->pend_text); |
| 309 |
4510 |
▶ | if (utf8 || !SvUTF8(p_state->pend_text)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (utf8 || !SvUTF8(p_state->pend_text)) { |
4510 |
0 |
4510 |
| if (utf8 || !SvUTF8(p_state->pend_text)) { |
4510 |
0 |
4510 |
|
| 310 |
4510 |
| sv_catpvn(p_state->pend_text, beg, end - beg); |
| 311 |
|
| } |
| 312 |
|
| else { |
| 313 |
0 |
| SV *tmp = newSVpvn(beg, end - beg); |
| 314 |
0 |
| sv_utf8_upgrade(tmp); |
| 315 |
0 |
| sv_catsv(p_state->pend_text, tmp); |
| 316 |
0 |
| SvREFCNT_dec(tmp); |
| 317 |
|
| } |
| 318 |
4510 |
| return; |
| 319 |
|
| } |
| 320 |
25424 |
▶ | else if (p_state->pend_text && SvOK(p_state->pend_text)) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (p_state->pend_text && SvOK(p_state->pend_text)) { |
4458 |
20966 |
25424 |
| else if (p_state->pend_text && SvOK(p_state->pend_text)) { |
4294 |
164 |
4458 |
|
| 321 |
4294 |
| flush_pending_text(p_state, self); |
| 322 |
4294 |
| SPAGAIN; |
| 323 |
|
| } |
| 324 |
|
| |
| 325 |
|
| /* At this point we have decided to generate an event callback */ |
| 326 |
|
| |
| 327 |
50847 |
▶ | argspec = h->argspec ? SvPV(h->argspec, my_na) : ""; |
Branch: 1 branch
| Branch | True | False | Total |
| argspec = h->argspec ? SvPV(h->argspec, my_na) : ""; |
25423 |
1 |
25424 |
|
| 328 |
|
| |
| 329 |
25424 |
▶ | if (SvTYPE(h->cb) == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(h->cb) == SVt_PVAV) { |
8945 |
16479 |
25424 |
|
| 330 |
|
| |
| 331 |
8945 |
▶ | if (*argspec == ARG_FLAG_FLAT_ARRAY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*argspec == ARG_FLAG_FLAT_ARRAY) { |
502 |
8443 |
8945 |
|
| 332 |
502 |
| argspec++; |
| 333 |
502 |
| array = (AV*)h->cb; |
| 334 |
|
| } |
| 335 |
|
| else { |
| 336 |
|
| /* start sub-array for accumulator array */ |
| 337 |
8443 |
| array = newAV(); |
| 338 |
|
| } |
| 339 |
|
| } |
| 340 |
|
| else { |
| 341 |
16479 |
| array = 0; |
| 342 |
16479 |
▶ | if (*argspec == ARG_FLAG_FLAT_ARRAY) |
Branch: 1 branch
| Branch | True | False | Total |
| if (*argspec == ARG_FLAG_FLAT_ARRAY) |
0 |
16479 |
16479 |
|
| 343 |
0 |
| argspec++; |
| 344 |
|
| |
| 345 |
|
| /* start argument stack for callback */ |
| 346 |
16479 |
| ENTER; |
| 347 |
16479 |
| SAVETMPS; |
| 348 |
16479 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
16479 |
16479 |
|
| 349 |
|
| } |
| 350 |
|
| |
| 351 |
109833 |
▶ | for (s = argspec; *s; s++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (s = argspec; *s; s++) { |
84409 |
25424 |
109833 |
|
| 352 |
84409 |
| SV* arg = 0; |
| 353 |
84409 |
| int push_arg = 1; |
| 354 |
84409 |
| enum argcode argcode = (enum argcode)*s; |
| 355 |
|
| |
| 356 |
84409 |
| switch( argcode ) { |
| 357 |
|
| |
| 358 |
16112 |
| case ARG_SELF: |
| 359 |
16112 |
| arg = sv_mortalcopy(self); |
| 360 |
16112 |
| break; |
| 361 |
|
| |
| 362 |
85 |
| case ARG_TOKENS: |
| 363 |
85 |
▶ | if (num_tokens >= 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (num_tokens >= 1) { |
68 |
17 |
85 |
|
| 364 |
68 |
| AV* av = newAV(); |
| 365 |
68 |
| SV* prev_token = &PL_sv_undef; |
| 366 |
|
| int i; |
| 367 |
68 |
| av_extend(av, num_tokens); |
| 368 |
473 |
▶ | for (i = 0; i < num_tokens; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < num_tokens; i++) { |
405 |
68 |
473 |
|
| 369 |
405 |
▶ | if (tokens[i].beg) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tokens[i].beg) { |
405 |
0 |
405 |
|
| 370 |
405 |
| prev_token = newSVpvn(tokens[i].beg, tokens[i].end-tokens[i].beg); |
| 371 |
405 |
▶ | if (utf8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (utf8) |
0 |
405 |
405 |
|
| 372 |
0 |
| SvUTF8_on(prev_token); |
| 373 |
405 |
| av_push(av, prev_token); |
| 374 |
|
| } |
| 375 |
|
| else { /* boolean */ |
| 376 |
0 |
▶ | av_push(av, p_state->bool_attr_val |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(av, p_state->bool_attr_val |
0 |
0 |
0 |
|
| 377 |
|
| ? newSVsv(p_state->bool_attr_val) |
| 378 |
|
| : newSVsv(prev_token)); |
| 379 |
|
| } |
| 380 |
|
| } |
| 381 |
68 |
| arg = sv_2mortal(newRV_noinc((SV*)av)); |
| 382 |
|
| } |
| 383 |
85 |
| break; |
| 384 |
|
| |
| 385 |
84 |
| case ARG_TOKENPOS: |
| 386 |
84 |
▶ | if (num_tokens >= 1 && tokens[0].beg >= beg) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (num_tokens >= 1 && tokens[0].beg >= beg) { |
33 |
51 |
84 |
| if (num_tokens >= 1 && tokens[0].beg >= beg) { |
32 |
1 |
33 |
|
| 387 |
32 |
| AV* av = newAV(); |
| 388 |
|
| int i; |
| 389 |
32 |
| av_extend(av, num_tokens*2); |
| 390 |
401 |
▶ | for (i = 0; i < num_tokens; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < num_tokens; i++) { |
369 |
32 |
401 |
|
| 391 |
369 |
▶ | if (tokens[i].beg) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tokens[i].beg) { |
367 |
2 |
369 |
|
| 392 |
367 |
▶ | av_push(av, newSViv(CHR_DIST(tokens[i].beg, beg))); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(av, newSViv(CHR_DIST(tokens[i].beg, beg))); |
13 |
354 |
367 |
|
| 393 |
367 |
▶ | av_push(av, newSViv(CHR_DIST(tokens[i].end, tokens[i].beg))); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(av, newSViv(CHR_DIST(tokens[i].end, tokens[i].beg))); |
13 |
354 |
367 |
|
| 394 |
|
| } |
| 395 |
|
| else { /* boolean tag value */ |
| 396 |
2 |
| av_push(av, newSViv(0)); |
| 397 |
2 |
| av_push(av, newSViv(0)); |
| 398 |
|
| } |
| 399 |
|
| } |
| 400 |
32 |
| arg = sv_2mortal(newRV_noinc((SV*)av)); |
| 401 |
|
| } |
| 402 |
84 |
| break; |
| 403 |
|
| |
| 404 |
6779 |
| case ARG_TOKEN0: |
| 405 |
|
| case ARG_TAGNAME: |
| 406 |
|
| /* fall through */ |
| 407 |
|
| |
| 408 |
|
| case ARG_TAG: |
| 409 |
6779 |
▶ | if (num_tokens >= 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (num_tokens >= 1) { |
6711 |
68 |
6779 |
|
| 410 |
6711 |
| arg = sv_2mortal(newSVpvn(tokens[0].beg, |
| 411 |
|
| tokens[0].end - tokens[0].beg)); |
| 412 |
6711 |
▶ | if (utf8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (utf8) |
29 |
6682 |
6711 |
|
| 413 |
29 |
| SvUTF8_on(arg); |
| 414 |
6711 |
▶ | if (!CASE_SENSITIVE(p_state) && argcode != ARG_TOKEN0) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!CASE_SENSITIVE(p_state) && argcode != ARG_TOKEN0) |
6650 |
61 |
6711 |
| if (!CASE_SENSITIVE(p_state) && argcode != ARG_TOKEN0) |
6645 |
5 |
6650 |
| if (!CASE_SENSITIVE(p_state) && argcode != ARG_TOKEN0) |
6577 |
68 |
6645 |
|
| 415 |
6577 |
| sv_lower(aTHX_ arg); |
| 416 |
6711 |
▶ | if (argcode == ARG_TAG && event != E_START) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (argcode == ARG_TAG && event != E_START) { |
21 |
6690 |
6711 |
| if (argcode == ARG_TAG && event != E_START) { |
10 |
11 |
21 |
|
| 417 |
10 |
| char *e_type = "!##/#?#"; |
| 418 |
10 |
| sv_insert(arg, 0, 0, &e_type[event], 1); |
| 419 |
|
| } |
| 420 |
|
| } |
| 421 |
6779 |
| break; |
| 422 |
|
| |
| 423 |
4492 |
| case ARG_ATTR: |
| 424 |
|
| case ARG_ATTRARR: |
| 425 |
4492 |
▶ | if (event == E_START) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (event == E_START) { |
4400 |
92 |
4492 |
|
| 426 |
|
| HV* hv; |
| 427 |
|
| int i; |
| 428 |
4400 |
▶ | if (argcode == ARG_ATTR) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (argcode == ARG_ATTR) { |
4391 |
9 |
4400 |
|
| 429 |
4391 |
| hv = newHV(); |
| 430 |
4391 |
| arg = sv_2mortal(newRV_noinc((SV*)hv)); |
| 431 |
|
| } |
| 432 |
|
| else { |
| 433 |
|
| #ifdef __GNUC__ |
| 434 |
|
| /* gcc -Wall reports this variable as possibly used uninitialized */ |
| 435 |
9 |
| hv = 0; |
| 436 |
|
| #endif |
| 437 |
9 |
| push_arg = 0; /* deal with argument pushing here */ |
| 438 |
|
| } |
| 439 |
|
| |
| 440 |
16730 |
▶ | for (i = 1; i < num_tokens; i += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i < num_tokens; i += 2) { |
12330 |
4400 |
16730 |
|
| 441 |
12330 |
| SV* attrname = newSVpvn(tokens[i].beg, |
| 442 |
|
| tokens[i].end-tokens[i].beg); |
| 443 |
|
| SV* attrval; |
| 444 |
|
| |
| 445 |
12330 |
▶ | if (utf8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (utf8) |
37 |
12293 |
12330 |
|
| 446 |
37 |
| SvUTF8_on(attrname); |
| 447 |
12330 |
▶ | if (tokens[i+1].beg) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tokens[i+1].beg) { |
3553 |
8777 |
12330 |
|
| 448 |
3553 |
| char *beg = tokens[i+1].beg; |
| 449 |
3553 |
| STRLEN len = tokens[i+1].end - beg; |
| 450 |
3553 |
▶ | if (*beg == '"' || *beg == '\'' || (*beg == '`' && p_state->backquote)) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (*beg == '"' || *beg == '\'' || (*beg == '`' && p_state->backquote)) { |
3390 |
163 |
3553 |
| if (*beg == '"' || *beg == '\'' || (*beg == '`' && p_state->backquote)) { |
1342 |
2048 |
3390 |
| if (*beg == '"' || *beg == '\'' || (*beg == '`' && p_state->backquote)) { |
9 |
1333 |
1342 |
| if (*beg == '"' || *beg == '\'' || (*beg == '`' && p_state->backquote)) { |
1 |
8 |
9 |
|
| 451 |
|
| assert(len >= 2 && *beg == beg[len-1]); |
| 452 |
2212 |
| beg++; len -= 2; |
| 453 |
|
| } |
| 454 |
3553 |
| attrval = newSVpvn(beg, len); |
| 455 |
3553 |
▶ | if (utf8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (utf8) |
34 |
3519 |
3553 |
|
| 456 |
34 |
| SvUTF8_on(attrval); |
| 457 |
3553 |
▶ | if (!p_state->attr_encoded) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!p_state->attr_encoded) { |
3551 |
2 |
3553 |
|
| 458 |
3551 |
▶ | if (p_state->utf8_mode) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->utf8_mode) { |
20 |
3531 |
3551 |
|
| 459 |
20 |
| sv_utf8_decode(attrval); |
| 460 |
20 |
| sv_utf8_upgrade(attrval); |
| 461 |
|
| } |
| 462 |
3551 |
| decode_entities(aTHX_ attrval, p_state->entity2char, 0); |
| 463 |
3551 |
▶ | if (p_state->utf8_mode) |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->utf8_mode) |
20 |
3531 |
3551 |
|
| 464 |
20 |
| SvUTF8_off(attrval); |
| 465 |
|
| } |
| 466 |
|
| } |
| 467 |
|
| else { /* boolean */ |
| 468 |
8777 |
▶ | if (p_state->bool_attr_val) |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->bool_attr_val) |
0 |
8777 |
8777 |
|
| 469 |
0 |
| attrval = newSVsv(p_state->bool_attr_val); |
| 470 |
|
| else |
| 471 |
8777 |
| attrval = newSVsv(attrname); |
| 472 |
|
| } |
| 473 |
|
| |
| 474 |
12330 |
▶ | if (!CASE_SENSITIVE(p_state)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!CASE_SENSITIVE(p_state)) |
12317 |
13 |
12330 |
| if (!CASE_SENSITIVE(p_state)) |
12313 |
4 |
12317 |
|
| 475 |
12313 |
| sv_lower(aTHX_ attrname); |
| 476 |
|
| |
| 477 |
12330 |
▶ | if (argcode == ARG_ATTR) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (argcode == ARG_ATTR) { |
12322 |
8 |
12330 |
|
| 478 |
24642 |
| if (hv_exists_ent(hv, attrname, 0) || |
| 479 |
12320 |
| !hv_store_ent(hv, attrname, attrval, 0)) { |
| 480 |
2 |
| SvREFCNT_dec(attrval); |
| 481 |
|
| } |
| 482 |
12322 |
| SvREFCNT_dec(attrname); |
| 483 |
|
| } |
| 484 |
|
| else { /* ARG_ATTRARR */ |
| 485 |
8 |
▶ | if (array) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (array) { |
4 |
4 |
8 |
|
| 486 |
4 |
| av_push(array, attrname); |
| 487 |
4 |
| av_push(array, attrval); |
| 488 |
|
| } |
| 489 |
|
| else { |
| 490 |
4 |
▶ | mXPUSHs(attrname); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(attrname); |
0 |
4 |
4 |
|
| 491 |
4 |
▶ | mXPUSHs(attrval); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(attrval); |
0 |
4 |
4 |
|
| 492 |
|
| } |
| 493 |
|
| } |
| 494 |
|
| } |
| 495 |
|
| } |
| 496 |
92 |
▶ | else if (argcode == ARG_ATTRARR) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (argcode == ARG_ATTRARR) { |
18 |
74 |
92 |
|
| 497 |
18 |
| push_arg = 0; |
| 498 |
|
| } |
| 499 |
4492 |
| break; |
| 500 |
|
| |
| 501 |
4315 |
| case ARG_ATTRSEQ: /* (v2 compatibility stuff) */ |
| 502 |
4315 |
▶ | if (event == E_START) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (event == E_START) { |
4290 |
25 |
4315 |
|
| 503 |
4290 |
| AV* av = newAV(); |
| 504 |
|
| int i; |
| 505 |
16507 |
▶ | for (i = 1; i < num_tokens; i += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i < num_tokens; i += 2) { |
12217 |
4290 |
16507 |
|
| 506 |
12217 |
| SV* attrname = newSVpvn(tokens[i].beg, |
| 507 |
|
| tokens[i].end-tokens[i].beg); |
| 508 |
12217 |
▶ | if (utf8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (utf8) |
0 |
12217 |
12217 |
|
| 509 |
0 |
| SvUTF8_on(attrname); |
| 510 |
12217 |
▶ | if (!CASE_SENSITIVE(p_state)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!CASE_SENSITIVE(p_state)) |
12207 |
10 |
12217 |
| if (!CASE_SENSITIVE(p_state)) |
12203 |
4 |
12207 |
|
| 511 |
12203 |
| sv_lower(aTHX_ attrname); |
| 512 |
12217 |
| av_push(av, attrname); |
| 513 |
|
| } |
| 514 |
4290 |
| arg = sv_2mortal(newRV_noinc((SV*)av)); |
| 515 |
|
| } |
| 516 |
4315 |
| break; |
| 517 |
|
| |
| 518 |
25131 |
| case ARG_TEXT: |
| 519 |
25131 |
| arg = sv_2mortal(newSVpvn(beg, end - beg)); |
| 520 |
25131 |
▶ | if (utf8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (utf8) |
115 |
25016 |
25131 |
|
| 521 |
115 |
| SvUTF8_on(arg); |
| 522 |
25131 |
| break; |
| 523 |
|
| |
| 524 |
156 |
| case ARG_DTEXT: |
| 525 |
156 |
▶ | if (event == E_TEXT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (event == E_TEXT) { |
79 |
77 |
156 |
|
| 526 |
79 |
| arg = sv_2mortal(newSVpvn(beg, end - beg)); |
| 527 |
79 |
▶ | if (utf8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (utf8) |
23 |
56 |
79 |
|
| 528 |
23 |
| SvUTF8_on(arg); |
| 529 |
79 |
▶ | if (!p_state->is_cdata) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!p_state->is_cdata) { |
71 |
8 |
79 |
|
| 530 |
71 |
▶ | if (p_state->utf8_mode) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->utf8_mode) { |
8 |
63 |
71 |
|
| 531 |
8 |
| sv_utf8_decode(arg); |
| 532 |
8 |
| sv_utf8_upgrade(arg); |
| 533 |
|
| } |
| 534 |
71 |
| decode_entities(aTHX_ arg, p_state->entity2char, 1); |
| 535 |
71 |
▶ | if (p_state->utf8_mode) |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->utf8_mode) |
8 |
63 |
71 |
|
| 536 |
8 |
| SvUTF8_off(arg); |
| 537 |
|
| } |
| 538 |
|
| } |
| 539 |
156 |
| break; |
| 540 |
|
| |
| 541 |
17783 |
| case ARG_IS_CDATA: |
| 542 |
17783 |
▶ | if (event == E_TEXT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (event == E_TEXT) { |
17730 |
53 |
17783 |
|
| 543 |
17730 |
▶ | arg = boolSV(p_state->is_cdata); |
Branch: 1 branch
| Branch | True | False | Total |
| arg = boolSV(p_state->is_cdata); |
7 |
17723 |
17730 |
|
| 544 |
|
| } |
| 545 |
17783 |
| break; |
| 546 |
|
| |
| 547 |
14 |
| case ARG_SKIPPED_TEXT: |
| 548 |
14 |
| arg = sv_2mortal(p_state->skipped_text); |
| 549 |
14 |
| p_state->skipped_text = newSVpvs(""); |
| 550 |
14 |
| break; |
| 551 |
|
| |
| 552 |
122 |
| case ARG_OFFSET: |
| 553 |
122 |
| arg = sv_2mortal(newSViv(offset)); |
| 554 |
122 |
| break; |
| 555 |
|
| |
| 556 |
74 |
| case ARG_OFFSET_END: |
| 557 |
74 |
▶ | arg = sv_2mortal(newSViv(offset + CHR_DIST(end, beg))); |
Branch: 1 branch
| Branch | True | False | Total |
| arg = sv_2mortal(newSViv(offset + CHR_DIST(end, beg))); |
16 |
58 |
74 |
|
| 558 |
74 |
| break; |
| 559 |
|
| |
| 560 |
101 |
| case ARG_LENGTH: |
| 561 |
101 |
▶ | arg = sv_2mortal(newSViv(CHR_DIST(end, beg))); |
Branch: 1 branch
| Branch | True | False | Total |
| arg = sv_2mortal(newSViv(CHR_DIST(end, beg))); |
16 |
85 |
101 |
|
| 562 |
101 |
| break; |
| 563 |
|
| |
| 564 |
39 |
| case ARG_LINE: |
| 565 |
39 |
| arg = sv_2mortal(newSViv(line)); |
| 566 |
39 |
| break; |
| 567 |
|
| |
| 568 |
95 |
| case ARG_COLUMN: |
| 569 |
95 |
| arg = sv_2mortal(newSViv(column)); |
| 570 |
95 |
| break; |
| 571 |
|
| |
| 572 |
708 |
| case ARG_EVENT: |
| 573 |
|
| assert(event >= 0 && event < EVENT_COUNT); |
| 574 |
708 |
| arg = sv_2mortal(newSVpv(event_id_str[event], 0)); |
| 575 |
708 |
| break; |
| 576 |
|
| |
| 577 |
8319 |
| case ARG_LITERAL: |
| 578 |
|
| { |
| 579 |
8319 |
| int len = (unsigned char)s[1]; |
| 580 |
8319 |
| arg = sv_2mortal(newSVpvn(s+2, len)); |
| 581 |
8319 |
▶ | if (SvUTF8(h->argspec)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvUTF8(h->argspec)) |
0 |
8319 |
8319 |
|
| 582 |
0 |
| SvUTF8_on(arg); |
| 583 |
8319 |
| s += len + 1; |
| 584 |
|
| } |
| 585 |
8319 |
| break; |
| 586 |
|
| |
| 587 |
0 |
| case ARG_UNDEF: |
| 588 |
0 |
| arg = sv_mortalcopy(&PL_sv_undef); |
| 589 |
0 |
| break; |
| 590 |
|
| |
| 591 |
0 |
| default: |
| 592 |
0 |
| arg = sv_2mortal(newSVpvf("Bad argspec %d", *s)); |
| 593 |
0 |
| break; |
| 594 |
|
| } |
| 595 |
|
| |
| 596 |
84409 |
▶ | if (push_arg) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (push_arg) { |
84382 |
27 |
84409 |
|
| 597 |
84382 |
▶ | if (!arg) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!arg) |
366 |
84016 |
84382 |
|
| 598 |
366 |
| arg = sv_mortalcopy(&PL_sv_undef); |
| 599 |
|
| |
| 600 |
84382 |
▶ | if (array) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (array) { |
31113 |
53269 |
84382 |
|
| 601 |
|
| /* have to fix mortality here or add mortality to |
| 602 |
|
| * XPUSHs after removing it from the switch cases. |
| 603 |
|
| */ |
| 604 |
31113 |
| av_push(array, SvREFCNT_inc(arg)); |
| 605 |
|
| } |
| 606 |
|
| else { |
| 607 |
53269 |
▶ | XPUSHs(arg); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(arg); |
0 |
53269 |
53269 |
|
| 608 |
|
| } |
| 609 |
|
| } |
| 610 |
|
| } |
| 611 |
|
| |
| 612 |
25424 |
▶ | if (array) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (array) { |
8945 |
16479 |
25424 |
|
| 613 |
8945 |
▶ | if (array != (AV*)h->cb) |
Branch: 1 branch
| Branch | True | False | Total |
| if (array != (AV*)h->cb) |
8443 |
502 |
8945 |
|
| 614 |
8443 |
| av_push((AV*)h->cb, newRV_noinc((SV*)array)); |
| 615 |
|
| } |
| 616 |
|
| else { |
| 617 |
16479 |
| PUTBACK; |
| 618 |
|
| |
| 619 |
32491 |
▶ | if ((enum argcode)*argspec == ARG_SELF && !SvROK(h->cb)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((enum argcode)*argspec == ARG_SELF && !SvROK(h->cb)) { |
16082 |
397 |
16479 |
| if ((enum argcode)*argspec == ARG_SELF && !SvROK(h->cb)) { |
16012 |
70 |
16082 |
|
| 620 |
16012 |
| char *method = SvPV(h->cb, my_na); |
| 621 |
16012 |
| call_method(method, G_DISCARD | G_EVAL | G_VOID); |
| 622 |
|
| } |
| 623 |
|
| else { |
| 624 |
467 |
| call_sv(h->cb, G_DISCARD | G_EVAL | G_VOID); |
| 625 |
|
| } |
| 626 |
|
| |
| 627 |
16479 |
▶ | if (SvTRUE(ERRSV)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) { |
16479 |
0 |
16479 |
| if (SvTRUE(ERRSV)) { |
1 |
16478 |
16479 |
|
| 628 |
1 |
| RETHROW; |
| 629 |
|
| } |
| 630 |
|
| |
| 631 |
16478 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
16474 |
4 |
16478 |
|
| 632 |
16478 |
| LEAVE; |
| 633 |
|
| } |
| 634 |
25423 |
▶ | if (p_state->skipped_text) |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->skipped_text) |
14 |
25409 |
25423 |
|
| 635 |
14 |
| SvCUR_set(p_state->skipped_text, 0); |
| 636 |
25423 |
| return; |
| 637 |
|
| |
| 638 |
2268 |
| IGNORE_EVENT: |
| 639 |
2268 |
▶ | if (p_state->skipped_text) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->skipped_text) { |
38 |
2230 |
2268 |
|
| 640 |
38 |
▶ | if (event != E_TEXT && p_state->pend_text && SvOK(p_state->pend_text)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (event != E_TEXT && p_state->pend_text && SvOK(p_state->pend_text)) |
20 |
18 |
38 |
| if (event != E_TEXT && p_state->pend_text && SvOK(p_state->pend_text)) |
2 |
18 |
20 |
| if (event != E_TEXT && p_state->pend_text && SvOK(p_state->pend_text)) |
2 |
0 |
2 |
|
| 641 |
2 |
| flush_pending_text(p_state, self); |
| 642 |
38 |
▶ | if (utf8 && !SvUTF8(p_state->skipped_text)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (utf8 && !SvUTF8(p_state->skipped_text)) |
2 |
36 |
38 |
| if (utf8 && !SvUTF8(p_state->skipped_text)) |
1 |
1 |
2 |
|
| 643 |
1 |
| sv_utf8_upgrade(p_state->skipped_text); |
| 644 |
38 |
▶ | if (utf8 || !SvUTF8(p_state->skipped_text)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (utf8 || !SvUTF8(p_state->skipped_text)) { |
36 |
2 |
38 |
| if (utf8 || !SvUTF8(p_state->skipped_text)) { |
35 |
1 |
36 |
|
| 645 |
37 |
| sv_catpvn(p_state->skipped_text, beg, end - beg); |
| 646 |
|
| } |
| 647 |
|
| else { |
| 648 |
1 |
| SV *tmp = newSVpvn(beg, end - beg); |
| 649 |
1 |
| sv_utf8_upgrade(tmp); |
| 650 |
1 |
| sv_catsv(p_state->skipped_text, tmp); |
| 651 |
1 |
| SvREFCNT_dec(tmp); |
| 652 |
|
| } |
| 653 |
|
| } |
| 654 |
|
| #undef CHR_DIST |
| 655 |
2268 |
| return; |
| 656 |
|
| } |
| 657 |
|
| |
| 658 |
|
| |
| 659 |
|
| EXTERN SV* |
| 660 |
463 |
| argspec_compile(SV* src, PSTATE* p_state) |
| 661 |
|
| { |
| 662 |
|
| dTHX; |
| 663 |
463 |
| SV* argspec = newSVpvs(""); |
| 664 |
|
| STRLEN len; |
| 665 |
463 |
| char *s = SvPV(src, len); |
| 666 |
463 |
| char *end = s + len; |
| 667 |
|
| |
| 668 |
463 |
▶ | if (SvUTF8(src)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvUTF8(src)) |
0 |
463 |
463 |
|
| 669 |
0 |
| SvUTF8_on(argspec); |
| 670 |
|
| |
| 671 |
463 |
▶ | while (isHSPACE(*s)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHSPACE(*s)) |
0 |
463 |
463 |
|
| 672 |
0 |
| s++; |
| 673 |
|
| |
| 674 |
463 |
▶ | if (*s == '@') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '@') { |
7 |
456 |
463 |
|
| 675 |
|
| /* try to deal with '@{ ... }' wrapping */ |
| 676 |
7 |
| char *tmp = s + 1; |
| 677 |
7 |
▶ | while (isHSPACE(*tmp)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHSPACE(*tmp)) |
0 |
7 |
7 |
|
| 678 |
0 |
| tmp++; |
| 679 |
7 |
▶ | if (*tmp == '{') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*tmp == '{') { |
7 |
0 |
7 |
|
| 680 |
7 |
| char c = ARG_FLAG_FLAT_ARRAY; |
| 681 |
7 |
| sv_catpvn(argspec, &c, 1); |
| 682 |
7 |
| tmp++; |
| 683 |
7 |
▶ | while (isHSPACE(*tmp)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHSPACE(*tmp)) |
0 |
7 |
7 |
|
| 684 |
0 |
| tmp++; |
| 685 |
7 |
| s = tmp; |
| 686 |
|
| } |
| 687 |
|
| } |
| 688 |
1271 |
▶ | while (s < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (s < end) { |
1267 |
4 |
1271 |
|
| 689 |
2465 |
▶ | if (isHNAME_FIRST(*s) || *s == '@') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (isHNAME_FIRST(*s) || *s == '@') { |
71 |
1196 |
1267 |
| if (isHNAME_FIRST(*s) || *s == '@') { |
4 |
67 |
71 |
|
| 690 |
1200 |
| char *name = s; |
| 691 |
1200 |
| int a = ARG_SELF; |
| 692 |
|
| const char * const *arg_name; |
| 693 |
|
| |
| 694 |
1200 |
| s++; |
| 695 |
6076 |
▶ | while (isHNAME_CHAR(*s)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHNAME_CHAR(*s)) |
4876 |
1200 |
6076 |
|
| 696 |
4876 |
| s++; |
| 697 |
|
| |
| 698 |
|
| /* check identifier */ |
| 699 |
7622 |
▶ | for ( arg_name = argname; a < ARG_LITERAL ; ++a, ++arg_name ) { |
Branch: 1 branch
| Branch | True | False | Total |
| for ( arg_name = argname; a < ARG_LITERAL ; ++a, ++arg_name ) { |
7620 |
2 |
7622 |
|
| 700 |
7620 |
▶ | if (strnEQ(*arg_name, name, s - name) && |
Branch: 1 branch
| Branch | True | False | Total |
| if (strnEQ(*arg_name, name, s - name) && |
1202 |
6418 |
7620 |
|
| 701 |
1202 |
▶ | (*arg_name)[s - name] == '\0') |
Branch: 1 branch
| Branch | True | False | Total |
| (*arg_name)[s - name] == '\0') |
1198 |
4 |
1202 |
|
| 702 |
1198 |
| break; |
| 703 |
|
| } |
| 704 |
1200 |
▶ | if (a < ARG_LITERAL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (a < ARG_LITERAL) { |
1198 |
2 |
1200 |
|
| 705 |
1198 |
| char c = (unsigned char) a; |
| 706 |
1198 |
| sv_catpvn(argspec, &c, 1); |
| 707 |
|
| |
| 708 |
1198 |
▶ | if (a == ARG_LINE || a == ARG_COLUMN) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (a == ARG_LINE || a == ARG_COLUMN) { |
1194 |
4 |
1198 |
| if (a == ARG_LINE || a == ARG_COLUMN) { |
5 |
1189 |
1194 |
|
| 709 |
9 |
▶ | if (!p_state->line) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!p_state->line) |
5 |
4 |
9 |
|
| 710 |
5 |
| p_state->line = 1; /* enable tracing of line/column */ |
| 711 |
|
| } |
| 712 |
1198 |
▶ | if (a == ARG_SKIPPED_TEXT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (a == ARG_SKIPPED_TEXT) { |
7 |
1191 |
1198 |
|
| 713 |
7 |
▶ | if (!p_state->skipped_text) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!p_state->skipped_text) { |
5 |
2 |
7 |
|
| 714 |
5 |
| p_state->skipped_text = newSVpvs(""); |
| 715 |
|
| } |
| 716 |
|
| } |
| 717 |
1198 |
▶ | if (a == ARG_ATTR || a == ARG_ATTRARR) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (a == ARG_ATTR || a == ARG_ATTRARR) { |
1120 |
78 |
1198 |
| if (a == ARG_ATTR || a == ARG_ATTRARR) { |
4 |
1116 |
1120 |
|
| 718 |
82 |
▶ | if (p_state->argspec_entity_decode != ARG_DTEXT) |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->argspec_entity_decode != ARG_DTEXT) |
79 |
3 |
82 |
|
| 719 |
79 |
| p_state->argspec_entity_decode = ARG_ATTR; |
| 720 |
|
| } |
| 721 |
1116 |
▶ | else if (a == ARG_DTEXT) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (a == ARG_DTEXT) { |
10 |
1106 |
1116 |
|
| 722 |
10 |
| p_state->argspec_entity_decode = ARG_DTEXT; |
| 723 |
|
| } |
| 724 |
|
| } |
| 725 |
|
| else { |
| 726 |
2 |
| croak("Unrecognized identifier %.*s in argspec", (int) (s - name), name); |
| 727 |
|
| } |
| 728 |
|
| } |
| 729 |
131 |
▶ | else if (*s == '"' || *s == '\'') { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (*s == '"' || *s == '\'') { |
61 |
6 |
67 |
| else if (*s == '"' || *s == '\'') { |
61 |
0 |
61 |
|
| 730 |
67 |
| char *string_beg = s; |
| 731 |
67 |
| s++; |
| 732 |
656 |
▶ | while (s < end && *s != *string_beg && *s != '\\') |
Branch: 3 branches
| Branch | True | False | Total |
| while (s < end && *s != *string_beg && *s != '\\') |
655 |
1 |
656 |
| while (s < end && *s != *string_beg && *s != '\\') |
590 |
65 |
655 |
| while (s < end && *s != *string_beg && *s != '\\') |
589 |
1 |
590 |
|
| 733 |
589 |
| s++; |
| 734 |
67 |
▶ | if (*s == *string_beg) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == *string_beg) { |
65 |
2 |
67 |
|
| 735 |
|
| /* literal */ |
| 736 |
65 |
| int len = s - string_beg - 1; |
| 737 |
|
| unsigned char buf[2]; |
| 738 |
65 |
▶ | if (len > 255) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > 255) |
1 |
64 |
65 |
|
| 739 |
1 |
| croak("Literal string is longer than 255 chars in argspec"); |
| 740 |
64 |
| buf[0] = ARG_LITERAL; |
| 741 |
64 |
| buf[1] = len; |
| 742 |
64 |
| sv_catpvn(argspec, (char*)buf, 2); |
| 743 |
64 |
| sv_catpvn(argspec, string_beg+1, len); |
| 744 |
64 |
| s++; |
| 745 |
|
| } |
| 746 |
2 |
▶ | else if (*s == '\\') { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (*s == '\\') { |
1 |
1 |
2 |
|
| 747 |
1 |
| croak("Backslash reserved for literal string in argspec"); |
| 748 |
|
| } |
| 749 |
|
| else { |
| 750 |
1 |
| croak("Unterminated literal string in argspec"); |
| 751 |
|
| } |
| 752 |
|
| } |
| 753 |
|
| else { |
| 754 |
0 |
| croak("Bad argspec (%s)", s); |
| 755 |
|
| } |
| 756 |
|
| |
| 757 |
1263 |
▶ | while (isHSPACE(*s)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHSPACE(*s)) |
1 |
1262 |
1263 |
|
| 758 |
1 |
| s++; |
| 759 |
|
| |
| 760 |
1262 |
▶ | if (*s == '}' && SvPVX(argspec)[0] == ARG_FLAG_FLAT_ARRAY) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (*s == '}' && SvPVX(argspec)[0] == ARG_FLAG_FLAT_ARRAY) { |
7 |
1255 |
1262 |
| if (*s == '}' && SvPVX(argspec)[0] == ARG_FLAG_FLAT_ARRAY) { |
7 |
0 |
7 |
|
| 761 |
|
| /* end of '@{ ... }' */ |
| 762 |
7 |
| s++; |
| 763 |
7 |
▶ | while (isHSPACE(*s)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHSPACE(*s)) |
0 |
7 |
7 |
|
| 764 |
0 |
| s++; |
| 765 |
7 |
▶ | if (s < end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s < end) |
0 |
7 |
7 |
|
| 766 |
0 |
| croak("Bad argspec: stuff after @{...} (%s)", s); |
| 767 |
|
| } |
| 768 |
|
| |
| 769 |
1262 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
453 |
809 |
1262 |
|
| 770 |
453 |
| break; |
| 771 |
809 |
▶ | if (*s != ',') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s != ',') { |
1 |
808 |
809 |
|
| 772 |
1 |
| croak("Missing comma separator in argspec"); |
| 773 |
|
| } |
| 774 |
808 |
| s++; |
| 775 |
840 |
▶ | while (isHSPACE(*s)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHSPACE(*s)) |
32 |
808 |
840 |
|
| 776 |
32 |
| s++; |
| 777 |
|
| } |
| 778 |
457 |
| return argspec; |
| 779 |
|
| } |
| 780 |
|
| |
| 781 |
|
| |
| 782 |
|
| static void |
| 783 |
4358 |
| flush_pending_text(PSTATE* p_state, SV* self) |
| 784 |
|
| { |
| 785 |
|
| dTHX; |
| 786 |
4358 |
| bool old_unbroken_text = p_state->unbroken_text; |
| 787 |
4358 |
| SV* old_pend_text = p_state->pend_text; |
| 788 |
4358 |
| bool old_is_cdata = p_state->is_cdata; |
| 789 |
4358 |
| STRLEN old_offset = p_state->offset; |
| 790 |
4358 |
| STRLEN old_line = p_state->line; |
| 791 |
4358 |
| STRLEN old_column = p_state->column; |
| 792 |
|
| |
| 793 |
|
| assert(p_state->pend_text && SvOK(p_state->pend_text)); |
| 794 |
|
| |
| 795 |
4358 |
| p_state->unbroken_text = 0; |
| 796 |
4358 |
| p_state->pend_text = 0; |
| 797 |
4358 |
| p_state->is_cdata = p_state->pend_text_is_cdata; |
| 798 |
4358 |
| p_state->offset = p_state->pend_text_offset; |
| 799 |
4358 |
| p_state->line = p_state->pend_text_line; |
| 800 |
4358 |
| p_state->column = p_state->pend_text_column; |
| 801 |
|
| |
| 802 |
4358 |
| report_event(p_state, E_TEXT, |
| 803 |
4358 |
| SvPVX(old_pend_text), SvEND(old_pend_text), |
| 804 |
4358 |
| SvUTF8(old_pend_text), 0, 0, self); |
| 805 |
4358 |
▶ | SvOK_off(old_pend_text); |
Branch: 4 branches
| Branch | True | False | Total |
| SvOK_off(old_pend_text); |
0 |
4358 |
4358 |
| SvOK_off(old_pend_text); |
0 |
0 |
0 |
| SvOK_off(old_pend_text); |
0 |
0 |
0 |
| SvOK_off(old_pend_text); |
0 |
4358 |
4358 |
|
| 806 |
|
| |
| 807 |
4358 |
| p_state->unbroken_text = old_unbroken_text; |
| 808 |
4358 |
| p_state->pend_text = old_pend_text; |
| 809 |
4358 |
| p_state->is_cdata = old_is_cdata; |
| 810 |
4358 |
| p_state->offset = old_offset; |
| 811 |
4358 |
| p_state->line = old_line; |
| 812 |
4358 |
| p_state->column = old_column; |
| 813 |
4358 |
| } |
| 814 |
|
| |
| 815 |
|
| static char* |
| 816 |
2948 |
| skip_until_gt(char *beg, char *end) |
| 817 |
|
| { |
| 818 |
|
| /* tries to emulate quote skipping behaviour observed in MSIE */ |
| 819 |
2948 |
| char *s = beg; |
| 820 |
2948 |
| char quote = '\0'; |
| 821 |
2948 |
| char prev = ' '; |
| 822 |
12830 |
▶ | while (s < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (s < end) { |
12770 |
60 |
12830 |
|
| 823 |
12770 |
▶ | if (!quote && *s == '>') |
Branch: 2 branches
| Branch | True | False | Total |
| if (!quote && *s == '>') |
12739 |
31 |
12770 |
| if (!quote && *s == '>') |
2888 |
9851 |
12739 |
|
| 824 |
2888 |
| return s; |
| 825 |
9882 |
▶ | if (*s == '"' || *s == '\'') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (*s == '"' || *s == '\'') { |
9828 |
54 |
9882 |
| if (*s == '"' || *s == '\'') { |
44 |
9784 |
9828 |
|
| 826 |
98 |
▶ | if (*s == quote) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == quote) { |
6 |
92 |
98 |
|
| 827 |
6 |
| quote = '\0'; /* end of quoted string */ |
| 828 |
|
| } |
| 829 |
92 |
▶ | else if (!quote && (prev == ' ' || prev == '=')) { |
Branch: 3 branches
| Branch | True | False | Total |
| else if (!quote && (prev == ' ' || prev == '=')) { |
92 |
0 |
92 |
| else if (!quote && (prev == ' ' || prev == '=')) { |
86 |
6 |
92 |
| else if (!quote && (prev == ' ' || prev == '=')) { |
0 |
86 |
86 |
|
| 830 |
6 |
| quote = *s; |
| 831 |
|
| } |
| 832 |
|
| } |
| 833 |
9882 |
| prev = *s++; |
| 834 |
|
| } |
| 835 |
60 |
| return end; |
| 836 |
|
| } |
| 837 |
|
| |
| 838 |
|
| static char* |
| 839 |
177 |
| parse_comment(PSTATE* p_state, char *beg, char *end, U32 utf8, SV* self) |
| 840 |
|
| { |
| 841 |
177 |
| char *s = beg; |
| 842 |
|
| |
| 843 |
177 |
▶ | if (p_state->strict_comment) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->strict_comment) { |
6 |
171 |
177 |
|
| 844 |
6 |
| dTOKENS(4); |
| 845 |
6 |
| char *start_com = s; /* also used to signal inside/outside */ |
| 846 |
|
| |
| 847 |
|
| while (1) { |
| 848 |
|
| /* try to locate "--" */ |
| 849 |
15 |
| FIND_DASH_DASH: |
| 850 |
|
| /* printf("find_dash_dash: [%s]\n", s); */ |
| 851 |
125 |
▶ | while (s < end && *s != '-' && *s != '>') |
Branch: 3 branches
| Branch | True | False | Total |
| while (s < end && *s != '-' && *s != '>') |
125 |
0 |
125 |
| while (s < end && *s != '-' && *s != '>') |
112 |
13 |
125 |
| while (s < end && *s != '-' && *s != '>') |
104 |
8 |
112 |
|
| 852 |
104 |
| s++; |
| 853 |
|
| |
| 854 |
21 |
▶ | if (s == end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) { |
0 |
21 |
21 |
|
| 855 |
0 |
▶ | FREE_TOKENS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREE_TOKENS; |
0 |
0 |
0 |
|
| 856 |
0 |
| return beg; |
| 857 |
|
| } |
| 858 |
|
| |
| 859 |
21 |
▶ | if (*s == '>') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '>') { |
8 |
13 |
21 |
|
| 860 |
8 |
| s++; |
| 861 |
8 |
▶ | if (start_com) |
Branch: 1 branch
| Branch | True | False | Total |
| if (start_com) |
2 |
6 |
8 |
|
| 862 |
2 |
| goto FIND_DASH_DASH; |
| 863 |
|
| |
| 864 |
|
| /* we are done recognizing all comments, make callbacks */ |
| 865 |
6 |
| report_event(p_state, E_COMMENT, |
| 866 |
|
| beg - 4, s, utf8, |
| 867 |
|
| tokens, num_tokens, |
| 868 |
|
| self); |
| 869 |
6 |
▶ | FREE_TOKENS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREE_TOKENS; |
0 |
6 |
6 |
|
| 870 |
|
| |
| 871 |
6 |
| return s; |
| 872 |
|
| } |
| 873 |
|
| |
| 874 |
13 |
| s++; |
| 875 |
13 |
▶ | if (s == end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) { |
0 |
13 |
13 |
|
| 876 |
0 |
▶ | FREE_TOKENS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREE_TOKENS; |
0 |
0 |
0 |
|
| 877 |
0 |
| return beg; |
| 878 |
|
| } |
| 879 |
|
| |
| 880 |
13 |
▶ | if (*s == '-') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '-') { |
12 |
1 |
13 |
|
| 881 |
|
| /* two dashes in a row seen */ |
| 882 |
12 |
| s++; |
| 883 |
|
| /* do something */ |
| 884 |
12 |
▶ | if (start_com) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (start_com) { |
9 |
3 |
12 |
|
| 885 |
9 |
▶ | PUSH_TOKEN(start_com, s-2); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSH_TOKEN(start_com, s-2); |
0 |
9 |
9 |
|
| 886 |
9 |
| start_com = 0; |
| 887 |
|
| } |
| 888 |
|
| else { |
| 889 |
3 |
| start_com = s; |
| 890 |
|
| } |
| 891 |
|
| } |
| 892 |
|
| } |
| 893 |
|
| } |
| 894 |
171 |
▶ | else if (p_state->no_dash_dash_comment_end) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (p_state->no_dash_dash_comment_end) { |
2 |
169 |
171 |
|
| 895 |
|
| token_pos_t token; |
| 896 |
2 |
| token.beg = beg; |
| 897 |
|
| /* a lone '>' signals end-of-comment */ |
| 898 |
16 |
▶ | while (s < end && *s != '>') |
Branch: 2 branches
| Branch | True | False | Total |
| while (s < end && *s != '>') |
16 |
0 |
16 |
| while (s < end && *s != '>') |
14 |
2 |
16 |
|
| 899 |
14 |
| s++; |
| 900 |
2 |
| token.end = s; |
| 901 |
2 |
▶ | if (s < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s < end) { |
2 |
0 |
2 |
|
| 902 |
2 |
| s++; |
| 903 |
2 |
| report_event(p_state, E_COMMENT, beg-4, s, utf8, &token, 1, self); |
| 904 |
2 |
| return s; |
| 905 |
|
| } |
| 906 |
|
| else { |
| 907 |
0 |
| return beg; |
| 908 |
|
| } |
| 909 |
|
| } |
| 910 |
|
| else { /* non-strict comment */ |
| 911 |
|
| token_pos_t token; |
| 912 |
169 |
| token.beg = beg; |
| 913 |
|
| /* try to locate /--\s*>/ which signals end-of-comment */ |
| 914 |
199 |
| LOCATE_END: |
| 915 |
2330 |
▶ | while (s < end && *s != '-') |
Branch: 2 branches
| Branch | True | False | Total |
| while (s < end && *s != '-') |
2226 |
104 |
2330 |
| while (s < end && *s != '-') |
2131 |
95 |
2226 |
|
| 916 |
2131 |
| s++; |
| 917 |
199 |
| token.end = s; |
| 918 |
199 |
▶ | if (s < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s < end) { |
95 |
104 |
199 |
|
| 919 |
95 |
| s++; |
| 920 |
95 |
▶ | if (*s == '-') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '-') { |
78 |
17 |
95 |
|
| 921 |
78 |
| s++; |
| 922 |
93 |
▶ | while (isHSPACE(*s)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHSPACE(*s)) |
15 |
78 |
93 |
|
| 923 |
15 |
| s++; |
| 924 |
78 |
▶ | if (*s == '>') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '>') { |
48 |
30 |
78 |
|
| 925 |
48 |
| s++; |
| 926 |
|
| /* yup */ |
| 927 |
48 |
| report_event(p_state, E_COMMENT, beg-4, s, utf8, &token, 1, self); |
| 928 |
169 |
| return s; |
| 929 |
|
| } |
| 930 |
|
| } |
| 931 |
47 |
▶ | if (s < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s < end) { |
30 |
17 |
47 |
|
| 932 |
30 |
| s = token.end + 1; |
| 933 |
30 |
| goto LOCATE_END; |
| 934 |
|
| } |
| 935 |
|
| } |
| 936 |
|
| |
| 937 |
121 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
121 |
0 |
121 |
|
| 938 |
121 |
| return beg; |
| 939 |
|
| } |
| 940 |
|
| |
| 941 |
0 |
| return 0; |
| 942 |
|
| } |
| 943 |
|
| |
| 944 |
|
| |
| 945 |
|
| #ifdef MARKED_SECTION |
| 946 |
|
| |
| 947 |
|
| static void |
| 948 |
32 |
| marked_section_update(PSTATE* p_state) |
| 949 |
|
| { |
| 950 |
|
| dTHX; |
| 951 |
|
| /* we look at p_state->ms_stack to determine p_state->ms */ |
| 952 |
32 |
| AV* ms_stack = p_state->ms_stack; |
| 953 |
32 |
| p_state->ms = MS_NONE; |
| 954 |
|
| |
| 955 |
32 |
▶ | if (ms_stack) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ms_stack) { |
32 |
0 |
32 |
|
| 956 |
32 |
| int stack_len = av_len(ms_stack); |
| 957 |
|
| int stack_idx; |
| 958 |
50 |
▶ | for (stack_idx = 0; stack_idx <= stack_len; stack_idx++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (stack_idx = 0; stack_idx <= stack_len; stack_idx++) { |
18 |
32 |
50 |
|
| 959 |
18 |
| SV** svp = av_fetch(ms_stack, stack_idx, 0); |
| 960 |
18 |
▶ | if (svp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (svp) { |
18 |
0 |
18 |
|
| 961 |
18 |
| AV* tokens = (AV*)SvRV(*svp); |
| 962 |
18 |
| int tokens_len = av_len(tokens); |
| 963 |
|
| int i; |
| 964 |
|
| assert(SvTYPE(tokens) == SVt_PVAV); |
| 965 |
43 |
▶ | for (i = 0; i <= tokens_len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= tokens_len; i++) { |
25 |
18 |
43 |
|
| 966 |
25 |
| SV** svp = av_fetch(tokens, i, 0); |
| 967 |
25 |
▶ | if (svp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (svp) { |
25 |
0 |
25 |
|
| 968 |
|
| STRLEN len; |
| 969 |
25 |
| char *token_str = SvPV(*svp, len); |
| 970 |
|
| enum marked_section_t token; |
| 971 |
25 |
▶ | if (strEQ(token_str, "include")) |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(token_str, "include")) |
11 |
14 |
25 |
|
| 972 |
11 |
| token = MS_INCLUDE; |
| 973 |
14 |
▶ | else if (strEQ(token_str, "rcdata")) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(token_str, "rcdata")) |
4 |
10 |
14 |
|
| 974 |
4 |
| token = MS_RCDATA; |
| 975 |
10 |
▶ | else if (strEQ(token_str, "cdata")) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(token_str, "cdata")) |
7 |
3 |
10 |
|
| 976 |
7 |
| token = MS_CDATA; |
| 977 |
3 |
▶ | else if (strEQ(token_str, "ignore")) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(token_str, "ignore")) |
2 |
1 |
3 |
|
| 978 |
2 |
| token = MS_IGNORE; |
| 979 |
|
| else |
| 980 |
1 |
| token = MS_NONE; |
| 981 |
25 |
▶ | if (p_state->ms < token) |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->ms < token) |
24 |
1 |
25 |
|
| 982 |
24 |
| p_state->ms = token; |
| 983 |
|
| } |
| 984 |
|
| } |
| 985 |
|
| } |
| 986 |
|
| } |
| 987 |
|
| } |
| 988 |
|
| /* printf("MS %d\n", p_state->ms); */ |
| 989 |
32 |
| p_state->is_cdata = (p_state->ms == MS_CDATA); |
| 990 |
32 |
| return; |
| 991 |
|
| } |
| 992 |
|
| |
| 993 |
|
| |
| 994 |
|
| static char* |
| 995 |
16 |
| parse_marked_section(PSTATE* p_state, char *beg, char *end, U32 utf8, SV* self) |
| 996 |
|
| { |
| 997 |
|
| dTHX; |
| 998 |
|
| char *s; |
| 999 |
16 |
| AV* tokens = 0; |
| 1000 |
|
| |
| 1001 |
16 |
▶ | if (!p_state->marked_sections) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!p_state->marked_sections) |
0 |
16 |
16 |
|
| 1002 |
0 |
| return 0; |
| 1003 |
|
| |
| 1004 |
|
| assert(beg[0] == '<'); |
| 1005 |
|
| assert(beg[1] == '!'); |
| 1006 |
|
| assert(beg[2] == '['); |
| 1007 |
16 |
| s = beg + 3; |
| 1008 |
|
| |
| 1009 |
17 |
| FIND_NAMES: |
| 1010 |
22 |
▶ | while (isHSPACE(*s)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHSPACE(*s)) |
5 |
17 |
22 |
|
| 1011 |
5 |
| s++; |
| 1012 |
37 |
▶ | while (isHNAME_FIRST(*s)) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHNAME_FIRST(*s)) { |
20 |
17 |
37 |
|
| 1013 |
20 |
| char *name_start = s; |
| 1014 |
|
| char *name_end; |
| 1015 |
|
| SV *name; |
| 1016 |
20 |
| s++; |
| 1017 |
117 |
▶ | while (isHNAME_CHAR(*s)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHNAME_CHAR(*s)) |
97 |
20 |
117 |
|
| 1018 |
97 |
| s++; |
| 1019 |
20 |
| name_end = s; |
| 1020 |
39 |
▶ | while (isHSPACE(*s)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHSPACE(*s)) |
19 |
20 |
39 |
|
| 1021 |
19 |
| s++; |
| 1022 |
20 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
0 |
20 |
20 |
|
| 1023 |
0 |
| goto PREMATURE; |
| 1024 |
|
| |
| 1025 |
20 |
▶ | if (!tokens) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!tokens) |
13 |
7 |
20 |
|
| 1026 |
13 |
| tokens = newAV(); |
| 1027 |
20 |
| name = newSVpvn(name_start, name_end - name_start); |
| 1028 |
20 |
▶ | if (utf8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (utf8) |
1 |
19 |
20 |
|
| 1029 |
1 |
| SvUTF8_on(name); |
| 1030 |
20 |
| av_push(tokens, sv_lower(aTHX_ name)); |
| 1031 |
|
| } |
| 1032 |
17 |
▶ | if (*s == '-') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '-') { |
1 |
16 |
17 |
|
| 1033 |
1 |
| s++; |
| 1034 |
1 |
▶ | if (*s == '-') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '-') { |
1 |
0 |
1 |
|
| 1035 |
|
| /* comment */ |
| 1036 |
1 |
| s++; |
| 1037 |
|
| while (1) { |
| 1038 |
9 |
▶ | while (s < end && *s != '-') |
Branch: 2 branches
| Branch | True | False | Total |
| while (s < end && *s != '-') |
9 |
0 |
9 |
| while (s < end && *s != '-') |
8 |
1 |
9 |
|
| 1039 |
8 |
| s++; |
| 1040 |
1 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
0 |
1 |
1 |
|
| 1041 |
0 |
| goto PREMATURE; |
| 1042 |
|
| |
| 1043 |
1 |
| s++; /* skip first '-' */ |
| 1044 |
1 |
▶ | if (*s == '-') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '-') { |
1 |
0 |
1 |
|
| 1045 |
1 |
| s++; |
| 1046 |
|
| /* comment finished */ |
| 1047 |
1 |
| goto FIND_NAMES; |
| 1048 |
|
| } |
| 1049 |
|
| } |
| 1050 |
|
| } |
| 1051 |
|
| else |
| 1052 |
0 |
| goto FAIL; |
| 1053 |
|
| |
| 1054 |
|
| } |
| 1055 |
16 |
▶ | if (*s == '[') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '[') { |
16 |
0 |
16 |
|
| 1056 |
16 |
| s++; |
| 1057 |
|
| /* yup */ |
| 1058 |
|
| |
| 1059 |
16 |
▶ | if (!tokens) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!tokens) { |
3 |
13 |
16 |
|
| 1060 |
3 |
| tokens = newAV(); |
| 1061 |
3 |
| av_push(tokens, newSVpvs("include")); |
| 1062 |
|
| } |
| 1063 |
|
| |
| 1064 |
16 |
▶ | if (!p_state->ms_stack) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!p_state->ms_stack) |
4 |
12 |
16 |
|
| 1065 |
4 |
| p_state->ms_stack = newAV(); |
| 1066 |
16 |
| av_push(p_state->ms_stack, newRV_noinc((SV*)tokens)); |
| 1067 |
16 |
| marked_section_update(p_state); |
| 1068 |
16 |
| report_event(p_state, E_NONE, beg, s, utf8, 0, 0, self); |
| 1069 |
16 |
| return s; |
| 1070 |
|
| } |
| 1071 |
|
| |
| 1072 |
0 |
| FAIL: |
| 1073 |
0 |
| SvREFCNT_dec(tokens); |
| 1074 |
0 |
| return 0; /* not yet implemented */ |
| 1075 |
|
| |
| 1076 |
0 |
| PREMATURE: |
| 1077 |
0 |
| SvREFCNT_dec(tokens); |
| 1078 |
0 |
| return beg; |
| 1079 |
|
| } |
| 1080 |
|
| #endif |
| 1081 |
|
| |
| 1082 |
|
| |
| 1083 |
|
| static char* |
| 1084 |
538 |
| parse_decl(PSTATE* p_state, char *beg, char *end, U32 utf8, SV* self) |
| 1085 |
|
| { |
| 1086 |
538 |
| char *s = beg + 2; |
| 1087 |
|
| |
| 1088 |
538 |
▶ | if (*s == '-') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '-') { |
185 |
353 |
538 |
|
| 1089 |
|
| /* comment? */ |
| 1090 |
|
| |
| 1091 |
|
| char *tmp; |
| 1092 |
185 |
| s++; |
| 1093 |
185 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
6 |
179 |
185 |
|
| 1094 |
6 |
| return beg; |
| 1095 |
|
| |
| 1096 |
179 |
▶ | if (*s != '-') |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s != '-') |
2 |
177 |
179 |
|
| 1097 |
2 |
| goto DECL_FAIL; /* nope, illegal */ |
| 1098 |
|
| |
| 1099 |
|
| /* yes, two dashes seen */ |
| 1100 |
177 |
| s++; |
| 1101 |
|
| |
| 1102 |
177 |
| tmp = parse_comment(p_state, s, end, utf8, self); |
| 1103 |
177 |
▶ | return (tmp == s) ? beg : tmp; |
Branch: 1 branch
| Branch | True | False | Total |
| return (tmp == s) ? beg : tmp; |
121 |
56 |
177 |
|
| 1104 |
|
| } |
| 1105 |
|
| |
| 1106 |
|
| #ifdef MARKED_SECTION |
| 1107 |
353 |
▶ | if (*s == '[') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '[') { |
16 |
337 |
353 |
|
| 1108 |
|
| /* marked section */ |
| 1109 |
|
| char *tmp; |
| 1110 |
16 |
| tmp = parse_marked_section(p_state, beg, end, utf8, self); |
| 1111 |
16 |
▶ | if (!tmp) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!tmp) |
0 |
16 |
16 |
|
| 1112 |
0 |
| goto DECL_FAIL; |
| 1113 |
16 |
| return tmp; |
| 1114 |
|
| } |
| 1115 |
|
| #endif |
| 1116 |
|
| |
| 1117 |
337 |
▶ | if (*s == '>') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '>') { |
1 |
336 |
337 |
|
| 1118 |
|
| /* make <!> into empty comment <SGML Handbook 36:32> */ |
| 1119 |
|
| token_pos_t token; |
| 1120 |
1 |
| token.beg = s; |
| 1121 |
1 |
| token.end = s; |
| 1122 |
1 |
| s++; |
| 1123 |
1 |
| report_event(p_state, E_COMMENT, beg, s, utf8, &token, 1, self); |
| 1124 |
1 |
| return s; |
| 1125 |
|
| } |
| 1126 |
|
| |
| 1127 |
336 |
▶ | if (isALPHA(*s)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (isALPHA(*s)) { |
305 |
31 |
336 |
|
| 1128 |
305 |
| dTOKENS(8); |
| 1129 |
305 |
| char *decl_id = s; |
| 1130 |
|
| STRLEN decl_id_len; |
| 1131 |
|
| |
| 1132 |
305 |
| s++; |
| 1133 |
|
| /* declaration */ |
| 1134 |
1978 |
▶ | while (s < end && isHNAME_CHAR(*s)) |
Branch: 2 branches
| Branch | True | False | Total |
| while (s < end && isHNAME_CHAR(*s)) |
1962 |
16 |
1978 |
| while (s < end && isHNAME_CHAR(*s)) |
1673 |
289 |
1962 |
|
| 1135 |
1673 |
| s++; |
| 1136 |
305 |
| decl_id_len = s - decl_id; |
| 1137 |
305 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
16 |
289 |
305 |
|
| 1138 |
16 |
| goto PREMATURE; |
| 1139 |
|
| |
| 1140 |
|
| /* just hardcode a few names as the recognized declarations */ |
| 1141 |
555 |
▶ | if (!((decl_id_len == 7 && |
Branch: 1 branch
| Branch | True | False | Total |
| if (!((decl_id_len == 7 && |
4 |
20 |
24 |
|
| 1142 |
266 |
▶ | strnEQx(decl_id, "DOCTYPE", 7, !CASE_SENSITIVE(p_state))) || |
Branch: 2 branches
| Branch | True | False | Total |
| strnEQx(decl_id, "DOCTYPE", 7, !CASE_SENSITIVE(p_state))) || |
266 |
0 |
266 |
| strnEQx(decl_id, "DOCTYPE", 7, !CASE_SENSITIVE(p_state))) || |
266 |
0 |
266 |
|
| 1143 |
4 |
▶ | (decl_id_len == 6 && |
Branch: 1 branch
| Branch | True | False | Total |
| (decl_id_len == 6 && |
0 |
4 |
4 |
|
| 1144 |
4 |
▶ | strnEQx(decl_id, "ENTITY", 6, !CASE_SENSITIVE(p_state))) |
Branch: 2 branches
| Branch | True | False | Total |
| strnEQx(decl_id, "ENTITY", 6, !CASE_SENSITIVE(p_state))) |
3 |
1 |
4 |
| strnEQx(decl_id, "ENTITY", 6, !CASE_SENSITIVE(p_state))) |
3 |
0 |
3 |
|
| 1145 |
|
| ) |
| 1146 |
|
| ) |
| 1147 |
|
| { |
| 1148 |
20 |
| goto FAIL; |
| 1149 |
|
| } |
| 1150 |
|
| |
| 1151 |
|
| /* first word available */ |
| 1152 |
269 |
▶ | PUSH_TOKEN(decl_id, s); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSH_TOKEN(decl_id, s); |
0 |
269 |
269 |
|
| 1153 |
|
| |
| 1154 |
|
| while (1) { |
| 1155 |
50732 |
▶ | while (s < end && isHSPACE(*s)) |
Branch: 2 branches
| Branch | True | False | Total |
| while (s < end && isHSPACE(*s)) |
50567 |
165 |
50732 |
| while (s < end && isHSPACE(*s)) |
25413 |
25154 |
50567 |
|
| 1156 |
25413 |
| s++; |
| 1157 |
|
| |
| 1158 |
25319 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
165 |
25154 |
25319 |
|
| 1159 |
165 |
| goto PREMATURE; |
| 1160 |
|
| |
| 1161 |
25154 |
▶ | if (*s == '"' || *s == '\'' || (*s == '`' && p_state->backquote)) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (*s == '"' || *s == '\'' || (*s == '`' && p_state->backquote)) { |
25025 |
129 |
25154 |
| if (*s == '"' || *s == '\'' || (*s == '`' && p_state->backquote)) { |
25025 |
0 |
25025 |
| if (*s == '"' || *s == '\'' || (*s == '`' && p_state->backquote)) { |
0 |
25025 |
25025 |
| if (*s == '"' || *s == '\'' || (*s == '`' && p_state->backquote)) { |
0 |
0 |
0 |
|
| 1162 |
129 |
| char *str_beg = s; |
| 1163 |
129 |
| s++; |
| 1164 |
2914 |
▶ | while (s < end && *s != *str_beg) |
Branch: 2 branches
| Branch | True | False | Total |
| while (s < end && *s != *str_beg) |
2849 |
65 |
2914 |
| while (s < end && *s != *str_beg) |
2785 |
64 |
2849 |
|
| 1165 |
2785 |
| s++; |
| 1166 |
129 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
65 |
64 |
129 |
|
| 1167 |
65 |
| goto PREMATURE; |
| 1168 |
64 |
| s++; |
| 1169 |
64 |
▶ | PUSH_TOKEN(str_beg, s); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSH_TOKEN(str_beg, s); |
0 |
64 |
64 |
|
| 1170 |
|
| } |
| 1171 |
25025 |
▶ | else if (*s == '-') { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (*s == '-') { |
12405 |
12620 |
25025 |
|
| 1172 |
|
| /* comment */ |
| 1173 |
12405 |
| char *com_beg = s; |
| 1174 |
12405 |
| s++; |
| 1175 |
12405 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
0 |
12405 |
12405 |
|
| 1176 |
0 |
| goto PREMATURE; |
| 1177 |
12405 |
▶ | if (*s != '-') |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s != '-') |
0 |
12405 |
12405 |
|
| 1178 |
0 |
| goto FAIL; |
| 1179 |
12405 |
| s++; |
| 1180 |
|
| |
| 1181 |
|
| while (1) { |
| 1182 |
62054 |
▶ | while (s < end && *s != '-') |
Branch: 2 branches
| Branch | True | False | Total |
| while (s < end && *s != '-') |
62054 |
0 |
62054 |
| while (s < end && *s != '-') |
49647 |
12407 |
62054 |
|
| 1183 |
49647 |
| s++; |
| 1184 |
12407 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
0 |
12407 |
12407 |
|
| 1185 |
0 |
| goto PREMATURE; |
| 1186 |
12407 |
| s++; |
| 1187 |
12407 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
0 |
12407 |
12407 |
|
| 1188 |
0 |
| goto PREMATURE; |
| 1189 |
12407 |
▶ | if (*s == '-') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '-') { |
12405 |
2 |
12407 |
|
| 1190 |
12405 |
| s++; |
| 1191 |
12405 |
▶ | PUSH_TOKEN(com_beg, s); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSH_TOKEN(com_beg, s); |
0 |
12405 |
12405 |
|
| 1192 |
12405 |
| break; |
| 1193 |
|
| } |
| 1194 |
|
| } |
| 1195 |
|
| } |
| 1196 |
12620 |
▶ | else if (*s != '>') { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (*s != '>') { |
12598 |
22 |
12620 |
|
| 1197 |
|
| /* plain word */ |
| 1198 |
12598 |
| char *word_beg = s; |
| 1199 |
12598 |
| s++; |
| 1200 |
25722 |
▶ | while (s < end && isHNOT_SPACE_GT(*s)) |
Branch: 2 branches
| Branch | True | False | Total |
| while (s < end && isHNOT_SPACE_GT(*s)) |
25705 |
17 |
25722 |
| while (s < end && isHNOT_SPACE_GT(*s)) |
13124 |
12581 |
25705 |
|
| 1201 |
13124 |
| s++; |
| 1202 |
12598 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
17 |
12581 |
12598 |
|
| 1203 |
17 |
| goto PREMATURE; |
| 1204 |
12581 |
▶ | PUSH_TOKEN(word_beg, s); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSH_TOKEN(word_beg, s); |
696 |
11885 |
12581 |
|
| 1205 |
|
| } |
| 1206 |
|
| else { |
| 1207 |
22 |
| break; |
| 1208 |
|
| } |
| 1209 |
|
| } |
| 1210 |
|
| |
| 1211 |
22 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
0 |
22 |
22 |
|
| 1212 |
0 |
| goto PREMATURE; |
| 1213 |
22 |
▶ | if (*s == '>') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '>') { |
22 |
0 |
22 |
|
| 1214 |
22 |
| s++; |
| 1215 |
22 |
| report_event(p_state, E_DECLARATION, beg, s, utf8, tokens, num_tokens, self); |
| 1216 |
22 |
▶ | FREE_TOKENS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREE_TOKENS; |
1 |
21 |
22 |
|
| 1217 |
285 |
| return s; |
| 1218 |
|
| } |
| 1219 |
|
| |
| 1220 |
0 |
| FAIL: |
| 1221 |
20 |
▶ | FREE_TOKENS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREE_TOKENS; |
0 |
20 |
20 |
|
| 1222 |
20 |
| goto DECL_FAIL; |
| 1223 |
|
| |
| 1224 |
263 |
| PREMATURE: |
| 1225 |
263 |
▶ | FREE_TOKENS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREE_TOKENS; |
153 |
110 |
263 |
|
| 1226 |
263 |
| return beg; |
| 1227 |
|
| |
| 1228 |
|
| } |
| 1229 |
|
| |
| 1230 |
31 |
| DECL_FAIL: |
| 1231 |
53 |
▶ | if (p_state->strict_comment) |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->strict_comment) |
0 |
53 |
53 |
|
| 1232 |
0 |
| return 0; |
| 1233 |
|
| |
| 1234 |
|
| /* consider everything up to the first '>' a comment */ |
| 1235 |
12809 |
▶ | while (s < end && *s != '>') |
Branch: 2 branches
| Branch | True | False | Total |
| while (s < end && *s != '>') |
12794 |
15 |
12809 |
| while (s < end && *s != '>') |
12756 |
38 |
12794 |
|
| 1236 |
12756 |
| s++; |
| 1237 |
53 |
▶ | if (s < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s < end) { |
38 |
15 |
53 |
|
| 1238 |
|
| token_pos_t token; |
| 1239 |
38 |
| token.beg = beg + 2; |
| 1240 |
38 |
| token.end = s; |
| 1241 |
38 |
| s++; |
| 1242 |
38 |
| report_event(p_state, E_COMMENT, beg, s, utf8, &token, 1, self); |
| 1243 |
38 |
| return s; |
| 1244 |
|
| } |
| 1245 |
|
| else { |
| 1246 |
15 |
| return beg; |
| 1247 |
|
| } |
| 1248 |
|
| } |
| 1249 |
|
| |
| 1250 |
|
| |
| 1251 |
|
| static char* |
| 1252 |
6884 |
| parse_start(PSTATE* p_state, char *beg, char *end, U32 utf8, SV* self) |
| 1253 |
|
| { |
| 1254 |
6884 |
| char *s = beg; |
| 1255 |
6884 |
| int empty_tag = 0; |
| 1256 |
6884 |
| dTOKENS(16); |
| 1257 |
|
| |
| 1258 |
|
| hctype_t tag_name_char; |
| 1259 |
|
| hctype_t attr_name_first, attr_name_char; |
| 1260 |
|
| |
| 1261 |
6884 |
▶ | if (STRICT_NAMES(p_state)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (STRICT_NAMES(p_state)) { |
6864 |
20 |
6884 |
| if (STRICT_NAMES(p_state)) { |
0 |
6864 |
6864 |
|
| 1262 |
20 |
| attr_name_first = HCTYPE_NAME_FIRST; |
| 1263 |
20 |
| tag_name_char = attr_name_char = HCTYPE_NAME_CHAR; |
| 1264 |
|
| } |
| 1265 |
|
| else { |
| 1266 |
6864 |
| tag_name_char = HCTYPE_NOT_SPACE_GT; |
| 1267 |
6864 |
| attr_name_first = HCTYPE_NOT_SPACE_GT; |
| 1268 |
6864 |
| attr_name_char = HCTYPE_NOT_SPACE_EQ_GT; |
| 1269 |
|
| } |
| 1270 |
|
| |
| 1271 |
6884 |
| s += 2; |
| 1272 |
|
| |
| 1273 |
111032 |
▶ | while (s < end && isHCTYPE(*s, tag_name_char)) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (s < end && isHCTYPE(*s, tag_name_char)) { |
110820 |
212 |
111032 |
| while (s < end && isHCTYPE(*s, tag_name_char)) { |
104148 |
6672 |
110820 |
|
| 1274 |
104148 |
▶ | if (*s == '/' && ALLOW_EMPTY_TAG(p_state)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (*s == '/' && ALLOW_EMPTY_TAG(p_state)) { |
436 |
103712 |
104148 |
| if (*s == '/' && ALLOW_EMPTY_TAG(p_state)) { |
436 |
0 |
436 |
| if (*s == '/' && ALLOW_EMPTY_TAG(p_state)) { |
0 |
436 |
436 |
|
| 1275 |
0 |
▶ | if ((s + 1) == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((s + 1) == end) |
0 |
0 |
0 |
|
| 1276 |
0 |
| goto PREMATURE; |
| 1277 |
0 |
▶ | if (*(s + 1) == '>') |
Branch: 1 branch
| Branch | True | False | Total |
| if (*(s + 1) == '>') |
0 |
0 |
0 |
|
| 1278 |
0 |
| break; |
| 1279 |
|
| } |
| 1280 |
104148 |
| s++; |
| 1281 |
|
| } |
| 1282 |
6884 |
▶ | PUSH_TOKEN(beg+1, s); /* tagname */ |
Branch: 1 branch
| Branch | True | False | Total |
| PUSH_TOKEN(beg+1, s); /* tagname */ |
0 |
6884 |
6884 |
|
| 1283 |
|
| |
| 1284 |
12632 |
▶ | while (isHSPACE(*s)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHSPACE(*s)) |
5748 |
6884 |
12632 |
|
| 1285 |
5748 |
| s++; |
| 1286 |
6884 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
239 |
6645 |
6884 |
|
| 1287 |
239 |
| goto PREMATURE; |
| 1288 |
|
| |
| 1289 |
35155 |
▶ | while (isHCTYPE(*s, attr_name_first)) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHCTYPE(*s, attr_name_first)) { |
29954 |
5201 |
35155 |
|
| 1290 |
|
| /* attribute */ |
| 1291 |
29954 |
| char *attr_name_beg = s; |
| 1292 |
|
| char *attr_name_end; |
| 1293 |
29954 |
▶ | if (*s == '/' && ALLOW_EMPTY_TAG(p_state)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (*s == '/' && ALLOW_EMPTY_TAG(p_state)) { |
70 |
29884 |
29954 |
| if (*s == '/' && ALLOW_EMPTY_TAG(p_state)) { |
70 |
0 |
70 |
| if (*s == '/' && ALLOW_EMPTY_TAG(p_state)) { |
4 |
66 |
70 |
|
| 1294 |
4 |
▶ | if ((s + 1) == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((s + 1) == end) |
0 |
4 |
4 |
|
| 1295 |
0 |
| goto PREMATURE; |
| 1296 |
4 |
▶ | if (*(s + 1) == '>') |
Branch: 1 branch
| Branch | True | False | Total |
| if (*(s + 1) == '>') |
4 |
0 |
4 |
|
| 1297 |
4 |
| break; |
| 1298 |
|
| } |
| 1299 |
29950 |
| s++; |
| 1300 |
486596 |
▶ | while (s < end && isHCTYPE(*s, attr_name_char)) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (s < end && isHCTYPE(*s, attr_name_char)) { |
485794 |
802 |
486596 |
| while (s < end && isHCTYPE(*s, attr_name_char)) { |
456646 |
29148 |
485794 |
|
| 1301 |
456646 |
▶ | if (*s == '/' && ALLOW_EMPTY_TAG(p_state)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (*s == '/' && ALLOW_EMPTY_TAG(p_state)) { |
1689 |
454957 |
456646 |
| if (*s == '/' && ALLOW_EMPTY_TAG(p_state)) { |
1689 |
0 |
1689 |
| if (*s == '/' && ALLOW_EMPTY_TAG(p_state)) { |
0 |
1689 |
1689 |
|
| 1302 |
0 |
▶ | if ((s + 1) == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((s + 1) == end) |
0 |
0 |
0 |
|
| 1303 |
0 |
| goto PREMATURE; |
| 1304 |
0 |
▶ | if (*(s + 1) == '>') |
Branch: 1 branch
| Branch | True | False | Total |
| if (*(s + 1) == '>') |
0 |
0 |
0 |
|
| 1305 |
0 |
| break; |
| 1306 |
|
| } |
| 1307 |
456646 |
| s++; |
| 1308 |
|
| } |
| 1309 |
29950 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
802 |
29148 |
29950 |
|
| 1310 |
802 |
| goto PREMATURE; |
| 1311 |
|
| |
| 1312 |
29148 |
| attr_name_end = s; |
| 1313 |
29148 |
▶ | PUSH_TOKEN(attr_name_beg, attr_name_end); /* attr name */ |
Branch: 1 branch
| Branch | True | False | Total |
| PUSH_TOKEN(attr_name_beg, attr_name_end); /* attr name */ |
1322 |
27826 |
29148 |
|
| 1314 |
|
| |
| 1315 |
39746 |
▶ | while (isHSPACE(*s)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHSPACE(*s)) |
10598 |
29148 |
39746 |
|
| 1316 |
10598 |
| s++; |
| 1317 |
29148 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
19 |
29129 |
29148 |
|
| 1318 |
19 |
| goto PREMATURE; |
| 1319 |
|
| |
| 1320 |
29129 |
▶ | if (*s == '=') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '=') { |
17329 |
11800 |
29129 |
|
| 1321 |
|
| /* with a value */ |
| 1322 |
17329 |
| s++; |
| 1323 |
17371 |
▶ | while (isHSPACE(*s)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHSPACE(*s)) |
42 |
17329 |
17371 |
|
| 1324 |
42 |
| s++; |
| 1325 |
17329 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
31 |
17298 |
17329 |
|
| 1326 |
31 |
| goto PREMATURE; |
| 1327 |
17298 |
▶ | if (*s == '>') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '>') { |
8 |
17290 |
17298 |
|
| 1328 |
|
| /* parse it similar to ="" */ |
| 1329 |
8 |
▶ | PUSH_TOKEN(s, s); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSH_TOKEN(s, s); |
0 |
8 |
8 |
|
| 1330 |
8 |
| break; |
| 1331 |
|
| } |
| 1332 |
17290 |
▶ | if (*s == '"' || *s == '\'' || (*s == '`' && p_state->backquote)) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (*s == '"' || *s == '\'' || (*s == '`' && p_state->backquote)) { |
16449 |
841 |
17290 |
| if (*s == '"' || *s == '\'' || (*s == '`' && p_state->backquote)) { |
14290 |
2159 |
16449 |
| if (*s == '"' || *s == '\'' || (*s == '`' && p_state->backquote)) { |
10 |
14280 |
14290 |
| if (*s == '"' || *s == '\'' || (*s == '`' && p_state->backquote)) { |
1 |
9 |
10 |
|
| 1333 |
3001 |
| char *str_beg = s; |
| 1334 |
3001 |
| s++; |
| 1335 |
38942 |
▶ | while (s < end && *s != *str_beg) |
Branch: 2 branches
| Branch | True | False | Total |
| while (s < end && *s != *str_beg) |
38656 |
286 |
38942 |
| while (s < end && *s != *str_beg) |
35941 |
2715 |
38656 |
|
| 1336 |
35941 |
| s++; |
| 1337 |
3001 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
286 |
2715 |
3001 |
|
| 1338 |
286 |
| goto PREMATURE; |
| 1339 |
2715 |
| s++; |
| 1340 |
2715 |
▶ | PUSH_TOKEN(str_beg, s); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSH_TOKEN(str_beg, s); |
0 |
2715 |
2715 |
|
| 1341 |
|
| } |
| 1342 |
|
| else { |
| 1343 |
14289 |
| char *word_start = s; |
| 1344 |
87056 |
▶ | while (s < end && isHNOT_SPACE_GT(*s)) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (s < end && isHNOT_SPACE_GT(*s)) { |
86957 |
99 |
87056 |
| while (s < end && isHNOT_SPACE_GT(*s)) { |
72769 |
14188 |
86957 |
|
| 1345 |
72769 |
▶ | if (*s == '/' && ALLOW_EMPTY_TAG(p_state)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (*s == '/' && ALLOW_EMPTY_TAG(p_state)) { |
233 |
72536 |
72769 |
| if (*s == '/' && ALLOW_EMPTY_TAG(p_state)) { |
232 |
1 |
233 |
| if (*s == '/' && ALLOW_EMPTY_TAG(p_state)) { |
1 |
231 |
232 |
|
| 1346 |
2 |
▶ | if ((s + 1) == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((s + 1) == end) |
0 |
2 |
2 |
|
| 1347 |
0 |
| goto PREMATURE; |
| 1348 |
2 |
▶ | if (*(s + 1) == '>') |
Branch: 1 branch
| Branch | True | False | Total |
| if (*(s + 1) == '>') |
2 |
0 |
2 |
|
| 1349 |
2 |
| break; |
| 1350 |
|
| } |
| 1351 |
72767 |
| s++; |
| 1352 |
|
| } |
| 1353 |
14289 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
99 |
14190 |
14289 |
|
| 1354 |
99 |
| goto PREMATURE; |
| 1355 |
14190 |
▶ | PUSH_TOKEN(word_start, s); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSH_TOKEN(word_start, s); |
0 |
14190 |
14190 |
|
| 1356 |
|
| } |
| 1357 |
31126 |
▶ | while (isHSPACE(*s)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHSPACE(*s)) |
14221 |
16905 |
31126 |
|
| 1358 |
14221 |
| s++; |
| 1359 |
16905 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
195 |
16710 |
16905 |
|
| 1360 |
195 |
| goto PREMATURE; |
| 1361 |
|
| } |
| 1362 |
|
| else { |
| 1363 |
11800 |
▶ | PUSH_TOKEN(0, 0); /* boolean attr value */ |
Branch: 1 branch
| Branch | True | False | Total |
| PUSH_TOKEN(0, 0); /* boolean attr value */ |
0 |
11800 |
11800 |
|
| 1364 |
|
| } |
| 1365 |
|
| } |
| 1366 |
|
| |
| 1367 |
5213 |
▶ | if (ALLOW_EMPTY_TAG(p_state) && *s == '/') { |
Branch: 3 branches
| Branch | True | False | Total |
| if (ALLOW_EMPTY_TAG(p_state) && *s == '/') { |
5193 |
20 |
5213 |
| if (ALLOW_EMPTY_TAG(p_state) && *s == '/') { |
605 |
4588 |
5193 |
| if (ALLOW_EMPTY_TAG(p_state) && *s == '/') { |
7 |
618 |
625 |
|
| 1368 |
7 |
| s++; |
| 1369 |
7 |
▶ | if (s == end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) |
0 |
7 |
7 |
|
| 1370 |
0 |
| goto PREMATURE; |
| 1371 |
7 |
| empty_tag = 1; |
| 1372 |
|
| } |
| 1373 |
|
| |
| 1374 |
5213 |
▶ | if (*s == '>') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '>') { |
5213 |
0 |
5213 |
|
| 1375 |
5213 |
| s++; |
| 1376 |
|
| /* done */ |
| 1377 |
5213 |
| report_event(p_state, E_START, beg, s, utf8, tokens, num_tokens, self); |
| 1378 |
5213 |
▶ | if (empty_tag) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (empty_tag) { |
7 |
5206 |
5213 |
|
| 1379 |
7 |
| report_event(p_state, E_END, s, s, utf8, tokens, 1, self); |
| 1380 |
|
| } |
| 1381 |
5206 |
▶ | else if (!p_state->xml_mode) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (!p_state->xml_mode) { |
5189 |
17 |
5206 |
|
| 1382 |
|
| /* find out if this start tag should put us into literal_mode |
| 1383 |
|
| */ |
| 1384 |
|
| int i; |
| 1385 |
5189 |
| int tag_len = tokens[0].end - tokens[0].beg; |
| 1386 |
|
| |
| 1387 |
41224 |
▶ | for (i = 0; literal_mode_elem[i].len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; literal_mode_elem[i].len; i++) { |
36140 |
5084 |
41224 |
|
| 1388 |
36140 |
▶ | if (tag_len == literal_mode_elem[i].len) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tag_len == literal_mode_elem[i].len) { |
649 |
35491 |
36140 |
|
| 1389 |
|
| /* try to match it */ |
| 1390 |
649 |
| char *s = beg + 1; |
| 1391 |
649 |
| char *t = literal_mode_elem[i].str; |
| 1392 |
649 |
| int len = tag_len; |
| 1393 |
1101 |
▶ | while (len) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (len) { |
1101 |
0 |
1101 |
|
| 1394 |
1101 |
▶ | if (toLOWER(*s) != *t) |
Branch: 2 branches
| Branch | True | False | Total |
| if (toLOWER(*s) != *t) |
224 |
877 |
1101 |
| if (toLOWER(*s) != *t) |
544 |
557 |
1101 |
|
| 1395 |
544 |
| break; |
| 1396 |
557 |
| s++; |
| 1397 |
557 |
| t++; |
| 1398 |
557 |
▶ | if (!--len) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!--len) { |
105 |
452 |
557 |
|
| 1399 |
|
| /* found it */ |
| 1400 |
105 |
| p_state->literal_mode = literal_mode_elem[i].str; |
| 1401 |
105 |
| p_state->is_cdata = literal_mode_elem[i].is_cdata; |
| 1402 |
|
| /* printf("Found %s\n", p_state->literal_mode); */ |
| 1403 |
105 |
| goto END_OF_LITERAL_SEARCH; |
| 1404 |
|
| } |
| 1405 |
|
| } |
| 1406 |
|
| } |
| 1407 |
|
| } |
| 1408 |
5189 |
| END_OF_LITERAL_SEARCH: |
| 1409 |
|
| ; |
| 1410 |
|
| } |
| 1411 |
|
| |
| 1412 |
5213 |
▶ | FREE_TOKENS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREE_TOKENS; |
479 |
4734 |
5213 |
|
| 1413 |
5213 |
| return s; |
| 1414 |
|
| } |
| 1415 |
|
| |
| 1416 |
0 |
▶ | FREE_TOKENS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREE_TOKENS; |
0 |
0 |
0 |
|
| 1417 |
0 |
| return 0; |
| 1418 |
|
| |
| 1419 |
1671 |
| PREMATURE: |
| 1420 |
1671 |
▶ | FREE_TOKENS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREE_TOKENS; |
312 |
1359 |
1671 |
|
| 1421 |
1671 |
| return beg; |
| 1422 |
|
| } |
| 1423 |
|
| |
| 1424 |
|
| |
| 1425 |
|
| static char* |
| 1426 |
2948 |
| parse_end(PSTATE* p_state, char *beg, char *end, U32 utf8, SV* self) |
| 1427 |
|
| { |
| 1428 |
2948 |
| char *s = beg+2; |
| 1429 |
|
| hctype_t name_first, name_char; |
| 1430 |
|
| |
| 1431 |
2948 |
▶ | if (STRICT_NAMES(p_state)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (STRICT_NAMES(p_state)) { |
2931 |
17 |
2948 |
| if (STRICT_NAMES(p_state)) { |
0 |
2931 |
2931 |
|
| 1432 |
17 |
| name_first = HCTYPE_NAME_FIRST; |
| 1433 |
17 |
| name_char = HCTYPE_NAME_CHAR; |
| 1434 |
|
| } |
| 1435 |
|
| else { |
| 1436 |
2931 |
| name_first = name_char = HCTYPE_NOT_SPACE_GT; |
| 1437 |
|
| } |
| 1438 |
|
| |
| 1439 |
2948 |
▶ | if (isHCTYPE(*s, name_first)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (isHCTYPE(*s, name_first)) { |
2945 |
3 |
2948 |
|
| 1440 |
|
| token_pos_t tagname; |
| 1441 |
2945 |
| tagname.beg = s; |
| 1442 |
2945 |
| s++; |
| 1443 |
5921 |
▶ | while (s < end && isHCTYPE(*s, name_char)) |
Branch: 2 branches
| Branch | True | False | Total |
| while (s < end && isHCTYPE(*s, name_char)) |
5875 |
46 |
5921 |
| while (s < end && isHCTYPE(*s, name_char)) |
2976 |
2899 |
5875 |
|
| 1444 |
2976 |
| s++; |
| 1445 |
2945 |
| tagname.end = s; |
| 1446 |
|
| |
| 1447 |
2945 |
▶ | if (p_state->strict_end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->strict_end) { |
0 |
2945 |
2945 |
|
| 1448 |
0 |
▶ | while (isHSPACE(*s)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHSPACE(*s)) |
0 |
0 |
0 |
|
| 1449 |
0 |
| s++; |
| 1450 |
|
| } |
| 1451 |
|
| else { |
| 1452 |
2945 |
| s = skip_until_gt(s, end); |
| 1453 |
|
| } |
| 1454 |
2945 |
▶ | if (s < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s < end) { |
2885 |
60 |
2945 |
|
| 1455 |
2885 |
▶ | if (*s == '>') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '>') { |
2885 |
0 |
2885 |
|
| 1456 |
2885 |
| s++; |
| 1457 |
|
| /* a complete end tag has been recognized */ |
| 1458 |
2885 |
| report_event(p_state, E_END, beg, s, utf8, &tagname, 1, self); |
| 1459 |
2944 |
| return s; |
| 1460 |
|
| } |
| 1461 |
|
| } |
| 1462 |
|
| else { |
| 1463 |
60 |
| return beg; |
| 1464 |
|
| } |
| 1465 |
|
| } |
| 1466 |
3 |
▶ | else if (!p_state->strict_comment) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (!p_state->strict_comment) { |
3 |
0 |
3 |
|
| 1467 |
3 |
| s = skip_until_gt(s, end); |
| 1468 |
3 |
▶ | if (s < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s < end) { |
3 |
0 |
3 |
|
| 1469 |
|
| token_pos_t token; |
| 1470 |
3 |
| token.beg = beg + 2; |
| 1471 |
3 |
| token.end = s; |
| 1472 |
3 |
| s++; |
| 1473 |
3 |
| report_event(p_state, E_COMMENT, beg, s, utf8, &token, 1, self); |
| 1474 |
3 |
| return s; |
| 1475 |
|
| } |
| 1476 |
|
| else { |
| 1477 |
0 |
| return beg; |
| 1478 |
|
| } |
| 1479 |
|
| } |
| 1480 |
0 |
| return 0; |
| 1481 |
|
| } |
| 1482 |
|
| |
| 1483 |
|
| |
| 1484 |
|
| static char* |
| 1485 |
87 |
| parse_process(PSTATE* p_state, char *beg, char *end, U32 utf8, SV* self) |
| 1486 |
|
| { |
| 1487 |
87 |
| char *s = beg + 2; /* skip '<?' */ |
| 1488 |
|
| /* processing instruction */ |
| 1489 |
|
| token_pos_t token_pos; |
| 1490 |
87 |
| token_pos.beg = s; |
| 1491 |
|
| |
| 1492 |
10868 |
▶ | while (s < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (s < end) { |
10845 |
23 |
10868 |
|
| 1493 |
10845 |
▶ | if (*s == '>') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '>') { |
66 |
10779 |
10845 |
|
| 1494 |
66 |
| token_pos.end = s; |
| 1495 |
66 |
| s++; |
| 1496 |
|
| |
| 1497 |
66 |
▶ | if (p_state->xml_mode || p_state->xml_pic) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (p_state->xml_mode || p_state->xml_pic) { |
60 |
6 |
66 |
| if (p_state->xml_mode || p_state->xml_pic) { |
2 |
58 |
60 |
|
| 1498 |
|
| /* XML processing instructions are ended by "?>" */ |
| 1499 |
8 |
▶ | if (s - beg < 4 || s[-2] != '?') |
Branch: 2 branches
| Branch | True | False | Total |
| if (s - beg < 4 || s[-2] != '?') |
8 |
0 |
8 |
| if (s - beg < 4 || s[-2] != '?') |
2 |
6 |
8 |
|
| 1500 |
2 |
| continue; |
| 1501 |
6 |
| token_pos.end = s - 2; |
| 1502 |
|
| } |
| 1503 |
|
| |
| 1504 |
|
| /* a complete processing instruction seen */ |
| 1505 |
64 |
| report_event(p_state, E_PROCESS, beg, s, utf8, |
| 1506 |
|
| &token_pos, 1, self); |
| 1507 |
64 |
| return s; |
| 1508 |
|
| } |
| 1509 |
10779 |
| s++; |
| 1510 |
|
| } |
| 1511 |
23 |
| return beg; /* could not find end */ |
| 1512 |
|
| } |
| 1513 |
|
| |
| 1514 |
|
| |
| 1515 |
|
| #ifdef USE_PFUNC |
| 1516 |
|
| static char* |
| 1517 |
|
| parse_null(PSTATE* p_state, char *beg, char *end, U32 utf8, SV* self) |
| 1518 |
|
| { |
| 1519 |
|
| return 0; |
| 1520 |
|
| } |
| 1521 |
|
| |
| 1522 |
|
| |
| 1523 |
|
| |
| 1524 |
|
| #include "pfunc.h" /* declares the parsefunc[] */ |
| 1525 |
|
| #endif /* USE_PFUNC */ |
| 1526 |
|
| |
| 1527 |
|
| static char* |
| 1528 |
7393 |
| parse_buf(pTHX_ PSTATE* p_state, char *beg, char *end, U32 utf8, SV* self) |
| 1529 |
|
| { |
| 1530 |
7393 |
| char *s = beg; |
| 1531 |
7393 |
| char *t = beg; |
| 1532 |
|
| char *new_pos; |
| 1533 |
|
| |
| 1534 |
24056 |
▶ | while (!p_state->eof) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (!p_state->eof) { |
24050 |
6 |
24056 |
|
| 1535 |
|
| /* |
| 1536 |
|
| * At the start of this loop we will always be ready for eating text |
| 1537 |
|
| * or a new tag. We will never be inside some tag. The 't' points |
| 1538 |
|
| * to where we started and the 's' is advanced as we go. |
| 1539 |
|
| */ |
| 1540 |
|
| |
| 1541 |
48268 |
▶ | while (p_state->literal_mode) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p_state->literal_mode) { |
287 |
23931 |
24218 |
|
| 1542 |
287 |
| char *l = p_state->literal_mode; |
| 1543 |
|
| char *end_text; |
| 1544 |
|
| |
| 1545 |
2705 |
▶ | while (s < end && *s != '<') { |
Branch: 2 branches
| Branch | True | False | Total |
| while (s < end && *s != '<') { |
2586 |
119 |
2705 |
| while (s < end && *s != '<') { |
2418 |
168 |
2586 |
|
| 1546 |
2418 |
| s++; |
| 1547 |
|
| } |
| 1548 |
|
| |
| 1549 |
287 |
▶ | if (s == end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) { |
119 |
168 |
287 |
|
| 1550 |
119 |
| s = t; |
| 1551 |
119 |
| goto DONE; |
| 1552 |
|
| } |
| 1553 |
|
| |
| 1554 |
168 |
| end_text = s; |
| 1555 |
168 |
| s++; |
| 1556 |
|
| |
| 1557 |
|
| /* here we rely on '\0' termination of perl svpv buffers */ |
| 1558 |
168 |
▶ | if (*s == '/') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '/') { |
147 |
21 |
168 |
|
| 1559 |
147 |
| s++; |
| 1560 |
777 |
▶ | while (*l && toLOWER(*s) == *l) { |
Branch: 3 branches
| Branch | True | False | Total |
| while (*l && toLOWER(*s) == *l) { |
666 |
111 |
777 |
| while (*l && toLOWER(*s) == *l) { |
15 |
651 |
666 |
| while (*l && toLOWER(*s) == *l) { |
630 |
36 |
666 |
|
| 1561 |
630 |
| s++; |
| 1562 |
630 |
| l++; |
| 1563 |
|
| } |
| 1564 |
|
| |
| 1565 |
147 |
▶ | if (!*l && (strNE(p_state->literal_mode, "plaintext") || p_state->closing_plaintext)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!*l && (strNE(p_state->literal_mode, "plaintext") || p_state->closing_plaintext)) { |
111 |
36 |
147 |
| if (!*l && (strNE(p_state->literal_mode, "plaintext") || p_state->closing_plaintext)) { |
2 |
109 |
111 |
| if (!*l && (strNE(p_state->literal_mode, "plaintext") || p_state->closing_plaintext)) { |
1 |
1 |
2 |
|
| 1566 |
|
| /* matched it all */ |
| 1567 |
|
| token_pos_t end_token; |
| 1568 |
110 |
| end_token.beg = end_text + 2; |
| 1569 |
110 |
| end_token.end = s; |
| 1570 |
|
| |
| 1571 |
110 |
▶ | while (isHSPACE(*s)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isHSPACE(*s)) |
0 |
110 |
110 |
|
| 1572 |
0 |
| s++; |
| 1573 |
110 |
▶ | if (*s == '>') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '>') { |
101 |
9 |
110 |
|
| 1574 |
101 |
| s++; |
| 1575 |
101 |
▶ | if (t != end_text) |
Branch: 1 branch
| Branch | True | False | Total |
| if (t != end_text) |
101 |
0 |
101 |
|
| 1576 |
101 |
| report_event(p_state, E_TEXT, t, end_text, utf8, |
| 1577 |
|
| 0, 0, self); |
| 1578 |
101 |
| report_event(p_state, E_END, end_text, s, utf8, |
| 1579 |
|
| &end_token, 1, self); |
| 1580 |
101 |
| p_state->literal_mode = 0; |
| 1581 |
101 |
| p_state->is_cdata = 0; |
| 1582 |
101 |
| t = s; |
| 1583 |
|
| } |
| 1584 |
|
| } |
| 1585 |
|
| } |
| 1586 |
|
| } |
| 1587 |
|
| |
| 1588 |
|
| #ifdef MARKED_SECTION |
| 1589 |
23940 |
▶ | while (p_state->ms == MS_CDATA || p_state->ms == MS_RCDATA) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (p_state->ms == MS_CDATA || p_state->ms == MS_RCDATA) { |
8 |
23932 |
23940 |
| while (p_state->ms == MS_CDATA || p_state->ms == MS_RCDATA) { |
2 |
23930 |
23932 |
|
| 1590 |
116 |
▶ | while (s < end && *s != ']') |
Branch: 2 branches
| Branch | True | False | Total |
| while (s < end && *s != ']') |
115 |
1 |
116 |
| while (s < end && *s != ']') |
106 |
9 |
115 |
|
| 1591 |
106 |
| s++; |
| 1592 |
10 |
▶ | if (*s == ']') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == ']') { |
9 |
1 |
10 |
|
| 1593 |
9 |
| char *end_text = s; |
| 1594 |
9 |
| s++; |
| 1595 |
9 |
▶ | if (*s == ']' && *(s + 1) == '>') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (*s == ']' && *(s + 1) == '>') { |
9 |
0 |
9 |
| if (*s == ']' && *(s + 1) == '>') { |
8 |
1 |
9 |
|
| 1596 |
8 |
| s += 2; |
| 1597 |
|
| /* marked section end */ |
| 1598 |
8 |
▶ | if (t != end_text) |
Branch: 1 branch
| Branch | True | False | Total |
| if (t != end_text) |
8 |
0 |
8 |
|
| 1599 |
8 |
| report_event(p_state, E_TEXT, t, end_text, utf8, |
| 1600 |
|
| 0, 0, self); |
| 1601 |
8 |
| report_event(p_state, E_NONE, end_text, s, utf8, 0, 0, self); |
| 1602 |
8 |
| t = s; |
| 1603 |
8 |
| SvREFCNT_dec(av_pop(p_state->ms_stack)); |
| 1604 |
8 |
| marked_section_update(p_state); |
| 1605 |
8 |
| continue; |
| 1606 |
|
| } |
| 1607 |
|
| } |
| 1608 |
2 |
▶ | if (s == end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s == end) { |
1 |
1 |
2 |
|
| 1609 |
1 |
| s = t; |
| 1610 |
1 |
| goto DONE; |
| 1611 |
|
| } |
| 1612 |
|
| } |
| 1613 |
|
| #endif |
| 1614 |
|
| |
| 1615 |
|
| /* first we try to match as much text as possible */ |
| 1616 |
2271132 |
▶ | while (s < end && *s != '<') { |
Branch: 2 branches
| Branch | True | False | Total |
| while (s < end && *s != '<') { |
2266228 |
4904 |
2271132 |
| while (s < end && *s != '<') { |
2247202 |
19026 |
2266228 |
|
| 1617 |
|
| #ifdef MARKED_SECTION |
| 1618 |
2247202 |
▶ | if (p_state->ms && *s == ']') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (p_state->ms && *s == ']') { |
65 |
2247137 |
2247202 |
| if (p_state->ms && *s == ']') { |
8 |
57 |
65 |
|
| 1619 |
8 |
| char *end_text = s; |
| 1620 |
8 |
| s++; |
| 1621 |
8 |
▶ | if (*s == ']') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == ']') { |
8 |
0 |
8 |
|
| 1622 |
8 |
| s++; |
| 1623 |
8 |
▶ | if (*s == '>') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '>') { |
8 |
0 |
8 |
|
| 1624 |
8 |
| s++; |
| 1625 |
8 |
| report_event(p_state, E_TEXT, t, end_text, utf8, |
| 1626 |
|
| 0, 0, self); |
| 1627 |
8 |
| report_event(p_state, E_NONE, end_text, s, utf8, |
| 1628 |
|
| 0, 0, self); |
| 1629 |
8 |
| t = s; |
| 1630 |
8 |
| SvREFCNT_dec(av_pop(p_state->ms_stack)); |
| 1631 |
8 |
| marked_section_update(p_state); |
| 1632 |
8 |
| continue; |
| 1633 |
|
| } |
| 1634 |
|
| } |
| 1635 |
|
| } |
| 1636 |
|
| #endif |
| 1637 |
2247194 |
| s++; |
| 1638 |
|
| } |
| 1639 |
23930 |
▶ | if (s != t) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s != t) { |
19922 |
4008 |
23930 |
|
| 1640 |
19922 |
▶ | if (*s == '<') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == '<') { |
15184 |
4738 |
19922 |
|
| 1641 |
15184 |
| report_event(p_state, E_TEXT, t, s, utf8, 0, 0, self); |
| 1642 |
15184 |
| t = s; |
| 1643 |
|
| } |
| 1644 |
|
| else { |
| 1645 |
4738 |
| s--; |
| 1646 |
4738 |
▶ | if (isHSPACE(*s)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (isHSPACE(*s)) { |
379 |
4359 |
4738 |
|
| 1647 |
|
| /* wait with white space at end */ |
| 1648 |
821 |
▶ | while (s >= t && isHSPACE(*s)) |
Branch: 2 branches
| Branch | True | False | Total |
| while (s >= t && isHSPACE(*s)) |
688 |
133 |
821 |
| while (s >= t && isHSPACE(*s)) |
442 |
246 |
688 |
|
| 1649 |
442 |
| s--; |
| 1650 |
|
| } |
| 1651 |
|
| else { |
| 1652 |
|
| /* might be a chopped up entities/words */ |
| 1653 |
144379 |
▶ | while (s >= t && !isHSPACE(*s)) |
Branch: 2 branches
| Branch | True | False | Total |
| while (s >= t && !isHSPACE(*s)) |
143599 |
780 |
144379 |
| while (s >= t && !isHSPACE(*s)) |
140020 |
3579 |
143599 |
|
| 1654 |
140020 |
| s--; |
| 1655 |
8048 |
▶ | while (s >= t && isHSPACE(*s)) |
Branch: 2 branches
| Branch | True | False | Total |
| while (s >= t && isHSPACE(*s)) |
7018 |
1030 |
8048 |
| while (s >= t && isHSPACE(*s)) |
3689 |
3329 |
7018 |
|
| 1656 |
3689 |
| s--; |
| 1657 |
|
| } |
| 1658 |
4738 |
| s++; |
| 1659 |
4738 |
▶ | if (s != t) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s != t) |
3575 |
1163 |
4738 |
|
| 1660 |
3575 |
| report_event(p_state, E_TEXT, t, s, utf8, 0, 0, self); |
| 1661 |
4738 |
| break; |
| 1662 |
|
| } |
| 1663 |
|
| } |
| 1664 |
|
| |
| 1665 |
19192 |
▶ | if (end - s < 3) |
Branch: 1 branch
| Branch | True | False | Total |
| if (end - s < 3) |
369 |
18823 |
19192 |
|
| 1666 |
369 |
| break; |
| 1667 |
|
| |
| 1668 |
|
| /* next char is known to be '<' and pointed to by 't' as well as 's' */ |
| 1669 |
18823 |
| s++; |
| 1670 |
|
| |
| 1671 |
|
| #ifdef USE_PFUNC |
| 1672 |
|
| new_pos = parsefunc[(unsigned char)*s](p_state, t, end, utf8, self); |
| 1673 |
|
| #else |
| 1674 |
18823 |
▶ | if (isHNAME_FIRST(*s)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (isHNAME_FIRST(*s)) |
6884 |
11939 |
18823 |
|
| 1675 |
6884 |
| new_pos = parse_start(p_state, t, end, utf8, self); |
| 1676 |
11939 |
▶ | else if (*s == '/') |
Branch: 1 branch
| Branch | True | False | Total |
| else if (*s == '/') |
2948 |
8991 |
11939 |
|
| 1677 |
2948 |
| new_pos = parse_end(p_state, t, end, utf8, self); |
| 1678 |
8991 |
▶ | else if (*s == '!') |
Branch: 1 branch
| Branch | True | False | Total |
| else if (*s == '!') |
538 |
8453 |
8991 |
|
| 1679 |
538 |
| new_pos = parse_decl(p_state, t, end, utf8, self); |
| 1680 |
8453 |
▶ | else if (*s == '?') |
Branch: 1 branch
| Branch | True | False | Total |
| else if (*s == '?') |
87 |
8366 |
8453 |
|
| 1681 |
87 |
| new_pos = parse_process(p_state, t, end, utf8, self); |
| 1682 |
|
| else |
| 1683 |
8366 |
| new_pos = 0; |
| 1684 |
|
| #endif /* USE_PFUNC */ |
| 1685 |
|
| |
| 1686 |
18822 |
▶ | if (new_pos) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (new_pos) { |
10456 |
8366 |
18822 |
|
| 1687 |
10456 |
▶ | if (new_pos == t) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (new_pos == t) { |
2159 |
8297 |
10456 |
|
| 1688 |
|
| /* no progress, need more data to know what it is */ |
| 1689 |
2159 |
| s = t; |
| 1690 |
2159 |
| break; |
| 1691 |
|
| } |
| 1692 |
8297 |
| t = s = new_pos; |
| 1693 |
|
| } |
| 1694 |
|
| |
| 1695 |
|
| /* if we get out here then this was not a conforming tag, so |
| 1696 |
|
| * treat it is plain text at the top of the loop again (we |
| 1697 |
|
| * have already skipped past the "<"). |
| 1698 |
|
| */ |
| 1699 |
|
| } |
| 1700 |
|
| |
| 1701 |
6 |
| DONE: |
| 1702 |
7392 |
| return s; |
| 1703 |
|
| |
| 1704 |
|
| } |
| 1705 |
|
| |
| 1706 |
|
| EXTERN void |
| 1707 |
7590 |
| parse(pTHX_ |
| 1708 |
|
| PSTATE* p_state, |
| 1709 |
|
| SV* chunk, |
| 1710 |
|
| SV* self) |
| 1711 |
|
| { |
| 1712 |
|
| char *s, *beg, *end; |
| 1713 |
7590 |
| U32 utf8 = 0; |
| 1714 |
|
| STRLEN len; |
| 1715 |
|
| |
| 1716 |
7590 |
▶ | if (!p_state->start_document) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!p_state->start_document) { |
211 |
7379 |
7590 |
|
| 1717 |
|
| char dummy[1]; |
| 1718 |
211 |
| report_event(p_state, E_START_DOCUMENT, dummy, dummy, 0, 0, 0, self); |
| 1719 |
211 |
| p_state->start_document = 1; |
| 1720 |
|
| } |
| 1721 |
|
| |
| 1722 |
7590 |
▶ | if (!chunk) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!chunk) { |
197 |
7393 |
7590 |
|
| 1723 |
|
| /* eof */ |
| 1724 |
|
| char empty[1]; |
| 1725 |
197 |
▶ | if (p_state->buf && SvOK(p_state->buf)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (p_state->buf && SvOK(p_state->buf)) { |
151 |
46 |
197 |
| if (p_state->buf && SvOK(p_state->buf)) { |
149 |
2 |
151 |
|
| 1726 |
|
| /* flush it */ |
| 1727 |
149 |
| s = SvPV(p_state->buf, len); |
| 1728 |
149 |
| end = s + len; |
| 1729 |
149 |
| utf8 = SvUTF8(p_state->buf); |
| 1730 |
|
| assert(len); |
| 1731 |
|
| |
| 1732 |
153 |
▶ | while (s < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (s < end) { |
153 |
0 |
153 |
|
| 1733 |
153 |
▶ | if (p_state->literal_mode) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->literal_mode) { |
2 |
151 |
153 |
|
| 1734 |
2 |
▶ | if (strEQ(p_state->literal_mode, "plaintext") || |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(p_state->literal_mode, "plaintext") || |
0 |
2 |
2 |
|
| 1735 |
0 |
▶ | strEQ(p_state->literal_mode, "xmp") || |
Branch: 1 branch
| Branch | True | False | Total |
| strEQ(p_state->literal_mode, "xmp") || |
0 |
0 |
0 |
|
| 1736 |
0 |
▶ | strEQ(p_state->literal_mode, "iframe") || |
Branch: 1 branch
| Branch | True | False | Total |
| strEQ(p_state->literal_mode, "iframe") || |
0 |
0 |
0 |
|
| 1737 |
0 |
▶ | strEQ(p_state->literal_mode, "textarea")) |
Branch: 1 branch
| Branch | True | False | Total |
| strEQ(p_state->literal_mode, "textarea")) |
0 |
0 |
0 |
|
| 1738 |
|
| { |
| 1739 |
|
| /* rest is considered text */ |
| 1740 |
|
| break; |
| 1741 |
|
| } |
| 1742 |
0 |
▶ | if (strEQ(p_state->literal_mode, "script") || |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(p_state->literal_mode, "script") || |
0 |
0 |
0 |
|
| 1743 |
0 |
▶ | strEQ(p_state->literal_mode, "style")) |
Branch: 1 branch
| Branch | True | False | Total |
| strEQ(p_state->literal_mode, "style")) |
0 |
0 |
0 |
|
| 1744 |
0 |
| { |
| 1745 |
|
| /* effectively make it an empty element */ |
| 1746 |
|
| token_pos_t t; |
| 1747 |
|
| char dummy; |
| 1748 |
0 |
| t.beg = p_state->literal_mode; |
| 1749 |
0 |
| t.end = p_state->literal_mode + strlen(p_state->literal_mode); |
| 1750 |
0 |
| report_event(p_state, E_END, &dummy, &dummy, 0, &t, 1, self); |
| 1751 |
|
| } |
| 1752 |
|
| else { |
| 1753 |
0 |
| p_state->pending_end_tag = p_state->literal_mode; |
| 1754 |
|
| } |
| 1755 |
0 |
| p_state->literal_mode = 0; |
| 1756 |
0 |
| s = parse_buf(aTHX_ p_state, s, end, utf8, self); |
| 1757 |
0 |
| continue; |
| 1758 |
|
| } |
| 1759 |
|
| |
| 1760 |
151 |
▶ | if (!p_state->strict_comment && !p_state->no_dash_dash_comment_end && *s == '<') { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!p_state->strict_comment && !p_state->no_dash_dash_comment_end && *s == '<') { |
136 |
15 |
151 |
| if (!p_state->strict_comment && !p_state->no_dash_dash_comment_end && *s == '<') { |
132 |
4 |
136 |
| if (!p_state->strict_comment && !p_state->no_dash_dash_comment_end && *s == '<') { |
4 |
128 |
132 |
|
| 1761 |
4 |
| p_state->no_dash_dash_comment_end = 1; |
| 1762 |
4 |
| s = parse_buf(aTHX_ p_state, s, end, utf8, self); |
| 1763 |
4 |
| continue; |
| 1764 |
|
| } |
| 1765 |
|
| |
| 1766 |
147 |
▶ | if (!p_state->strict_comment && *s == '<') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!p_state->strict_comment && *s == '<') { |
132 |
15 |
147 |
| if (!p_state->strict_comment && *s == '<') { |
4 |
128 |
132 |
|
| 1767 |
4 |
| char *s1 = s + 1; |
| 1768 |
4 |
▶ | if (s1 == end || isHNAME_FIRST(*s1) || *s1 == '/' || *s1 == '!' || *s1 == '?') { |
Branch: 5 branches
| Branch | True | False | Total |
| if (s1 == end || isHNAME_FIRST(*s1) || *s1 == '/' || *s1 == '!' || *s1 == '?') { |
4 |
0 |
4 |
| if (s1 == end || isHNAME_FIRST(*s1) || *s1 == '/' || *s1 == '!' || *s1 == '?') { |
2 |
2 |
4 |
| if (s1 == end || isHNAME_FIRST(*s1) || *s1 == '/' || *s1 == '!' || *s1 == '?') { |
2 |
0 |
2 |
| if (s1 == end || isHNAME_FIRST(*s1) || *s1 == '/' || *s1 == '!' || *s1 == '?') { |
2 |
0 |
2 |
| if (s1 == end || isHNAME_FIRST(*s1) || *s1 == '/' || *s1 == '!' || *s1 == '?') { |
0 |
2 |
2 |
|
| 1769 |
|
| /* some kind of unterminated markup. Report rest as as comment */ |
| 1770 |
|
| token_pos_t token; |
| 1771 |
2 |
| token.beg = s + 1; |
| 1772 |
2 |
| token.end = end; |
| 1773 |
2 |
| report_event(p_state, E_COMMENT, s, end, utf8, &token, 1, self); |
| 1774 |
2 |
| s = end; |
| 1775 |
|
| } |
| 1776 |
|
| } |
| 1777 |
|
| |
| 1778 |
147 |
| break; |
| 1779 |
|
| } |
| 1780 |
|
| |
| 1781 |
149 |
▶ | if (s < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s < end) { |
147 |
2 |
149 |
|
| 1782 |
|
| /* report rest as text */ |
| 1783 |
147 |
| report_event(p_state, E_TEXT, s, end, utf8, 0, 0, self); |
| 1784 |
|
| } |
| 1785 |
|
| |
| 1786 |
149 |
| SvREFCNT_dec(p_state->buf); |
| 1787 |
149 |
| p_state->buf = 0; |
| 1788 |
|
| } |
| 1789 |
197 |
▶ | if (p_state->pend_text && SvOK(p_state->pend_text)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (p_state->pend_text && SvOK(p_state->pend_text)) |
60 |
137 |
197 |
| if (p_state->pend_text && SvOK(p_state->pend_text)) |
60 |
0 |
60 |
|
| 1790 |
60 |
| flush_pending_text(p_state, self); |
| 1791 |
|
| |
| 1792 |
197 |
▶ | if (p_state->ignoring_element) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->ignoring_element) { |
0 |
197 |
197 |
|
| 1793 |
|
| /* document not balanced */ |
| 1794 |
0 |
| SvREFCNT_dec(p_state->ignoring_element); |
| 1795 |
0 |
| p_state->ignoring_element = 0; |
| 1796 |
|
| } |
| 1797 |
197 |
| report_event(p_state, E_END_DOCUMENT, empty, empty, 0, 0, 0, self); |
| 1798 |
|
| |
| 1799 |
|
| /* reset state */ |
| 1800 |
197 |
| p_state->offset = 0; |
| 1801 |
197 |
▶ | if (p_state->line) |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->line) |
10 |
187 |
197 |
|
| 1802 |
10 |
| p_state->line = 1; |
| 1803 |
197 |
| p_state->column = 0; |
| 1804 |
197 |
| p_state->start_document = 0; |
| 1805 |
197 |
| p_state->literal_mode = 0; |
| 1806 |
197 |
| p_state->is_cdata = 0; |
| 1807 |
197 |
| return; |
| 1808 |
|
| } |
| 1809 |
|
| |
| 1810 |
7393 |
▶ | if (p_state->utf8_mode) |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->utf8_mode) |
5 |
7388 |
7393 |
|
| 1811 |
5 |
| sv_utf8_downgrade(chunk, 0); |
| 1812 |
|
| |
| 1813 |
7393 |
▶ | if (p_state->buf && SvOK(p_state->buf)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (p_state->buf && SvOK(p_state->buf)) { |
7162 |
231 |
7393 |
| if (p_state->buf && SvOK(p_state->buf)) { |
7057 |
105 |
7162 |
|
| 1814 |
7057 |
| sv_catsv(p_state->buf, chunk); |
| 1815 |
7057 |
| beg = SvPV(p_state->buf, len); |
| 1816 |
7057 |
| utf8 = SvUTF8(p_state->buf); |
| 1817 |
|
| } |
| 1818 |
|
| else { |
| 1819 |
336 |
| beg = SvPV(chunk, len); |
| 1820 |
336 |
| utf8 = SvUTF8(chunk); |
| 1821 |
336 |
▶ | if (p_state->offset == 0 && DOWARN) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (p_state->offset == 0 && DOWARN) { |
211 |
125 |
336 |
| if (p_state->offset == 0 && DOWARN) { |
15 |
196 |
211 |
|
| 1822 |
|
| /* Print warnings if we find unexpected Unicode BOM forms */ |
| 1823 |
15 |
▶ | if (p_state->argspec_entity_decode && |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->argspec_entity_decode && |
14 |
1 |
15 |
|
| 1824 |
14 |
▶ | !(p_state->attr_encoded && p_state->argspec_entity_decode == ARG_ATTR) && |
Branch: 2 branches
| Branch | True | False | Total |
| !(p_state->attr_encoded && p_state->argspec_entity_decode == ARG_ATTR) && |
1 |
13 |
14 |
| !(p_state->attr_encoded && p_state->argspec_entity_decode == ARG_ATTR) && |
0 |
1 |
1 |
|
| 1825 |
13 |
▶ | !p_state->utf8_mode && ( |
Branch: 2 branches
| Branch | True | False | Total |
| !p_state->utf8_mode && ( |
10 |
3 |
13 |
| !p_state->utf8_mode && ( |
7 |
3 |
10 |
|
| 1826 |
10 |
▶ | (!utf8 && len >= 3 && strnEQ(beg, "\xEF\xBB\xBF", 3)) || |
Branch: 3 branches
| Branch | True | False | Total |
| (!utf8 && len >= 3 && strnEQ(beg, "\xEF\xBB\xBF", 3)) || |
7 |
0 |
7 |
| (!utf8 && len >= 3 && strnEQ(beg, "\xEF\xBB\xBF", 3)) || |
5 |
2 |
7 |
| (!utf8 && len >= 3 && strnEQ(beg, "\xEF\xBB\xBF", 3)) || |
3 |
5 |
8 |
|
| 1827 |
8 |
▶ | (utf8 && len >= 6 && strnEQ(beg, "\xC3\xAF\xC2\xBB\xC2\xBF", 6)) || |
Branch: 3 branches
| Branch | True | False | Total |
| (utf8 && len >= 6 && strnEQ(beg, "\xC3\xAF\xC2\xBB\xC2\xBF", 6)) || |
3 |
0 |
3 |
| (utf8 && len >= 6 && strnEQ(beg, "\xC3\xAF\xC2\xBB\xC2\xBF", 6)) || |
2 |
1 |
3 |
| (utf8 && len >= 6 && strnEQ(beg, "\xC3\xAF\xC2\xBB\xC2\xBF", 6)) || |
5 |
2 |
7 |
|
| 1828 |
5 |
▶ | (!utf8 && probably_utf8_chunk(aTHX_ beg, len)) |
Branch: 1 branch
| Branch | True | False | Total |
| (!utf8 && probably_utf8_chunk(aTHX_ beg, len)) |
1 |
4 |
5 |
|
| 1829 |
|
| ) |
| 1830 |
|
| ) |
| 1831 |
|
| { |
| 1832 |
4 |
| warn("Parsing of undecoded UTF-8 will give garbage when decoding entities"); |
| 1833 |
|
| } |
| 1834 |
15 |
▶ | if (utf8 && len >= 2 && strnEQ(beg, "\xFF\xFE", 2)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (utf8 && len >= 2 && strnEQ(beg, "\xFF\xFE", 2)) { |
3 |
12 |
15 |
| if (utf8 && len >= 2 && strnEQ(beg, "\xFF\xFE", 2)) { |
3 |
0 |
3 |
| if (utf8 && len >= 2 && strnEQ(beg, "\xFF\xFE", 2)) { |
0 |
3 |
3 |
|
| 1835 |
0 |
| warn("Parsing string decoded with wrong endianness"); |
| 1836 |
|
| } |
| 1837 |
15 |
▶ | if (!utf8 && len >= 4 && |
Branch: 2 branches
| Branch | True | False | Total |
| if (!utf8 && len >= 4 && |
12 |
3 |
15 |
| if (!utf8 && len >= 4 && |
12 |
0 |
12 |
|
| 1838 |
12 |
▶ | (strnEQ(beg, "\x00\x00\xFE\xFF", 4) || |
Branch: 1 branch
| Branch | True | False | Total |
| (strnEQ(beg, "\x00\x00\xFE\xFF", 4) || |
11 |
1 |
12 |
|
| 1839 |
11 |
▶ | strnEQ(beg, "\xFE\xFF\x00\x00", 4)) |
Branch: 1 branch
| Branch | True | False | Total |
| strnEQ(beg, "\xFE\xFF\x00\x00", 4)) |
1 |
10 |
11 |
|
| 1840 |
|
| ) |
| 1841 |
|
| { |
| 1842 |
2 |
| warn("Parsing of undecoded UTF-32"); |
| 1843 |
|
| } |
| 1844 |
13 |
▶ | else if (!utf8 && len >= 2 && |
Branch: 2 branches
| Branch | True | False | Total |
| else if (!utf8 && len >= 2 && |
10 |
3 |
13 |
| else if (!utf8 && len >= 2 && |
10 |
0 |
10 |
|
| 1845 |
10 |
▶ | (strnEQ(beg, "\xFE\xFF", 2) || strnEQ(beg, "\xFF\xFE", 2)) |
Branch: 2 branches
| Branch | True | False | Total |
| (strnEQ(beg, "\xFE\xFF", 2) || strnEQ(beg, "\xFF\xFE", 2)) |
9 |
1 |
10 |
| (strnEQ(beg, "\xFE\xFF", 2) || strnEQ(beg, "\xFF\xFE", 2)) |
1 |
8 |
9 |
|
| 1846 |
|
| ) |
| 1847 |
|
| { |
| 1848 |
2 |
| warn("Parsing of undecoded UTF-16"); |
| 1849 |
|
| } |
| 1850 |
|
| } |
| 1851 |
|
| } |
| 1852 |
|
| |
| 1853 |
7393 |
▶ | if (!len) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!len) |
4 |
7389 |
7393 |
|
| 1854 |
4 |
| return; /* nothing to do */ |
| 1855 |
|
| |
| 1856 |
7389 |
| end = beg + len; |
| 1857 |
7389 |
| s = parse_buf(aTHX_ p_state, beg, end, utf8, self); |
| 1858 |
|
| |
| 1859 |
7388 |
▶ | if (s == end || p_state->eof) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (s == end || p_state->eof) { |
7216 |
172 |
7388 |
| if (s == end || p_state->eof) { |
8 |
7208 |
7216 |
|
| 1860 |
180 |
▶ | if (p_state->buf) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->buf) { |
110 |
70 |
180 |
|
| 1861 |
110 |
▶ | SvOK_off(p_state->buf); |
Branch: 4 branches
| Branch | True | False | Total |
| SvOK_off(p_state->buf); |
0 |
110 |
110 |
| SvOK_off(p_state->buf); |
0 |
0 |
0 |
| SvOK_off(p_state->buf); |
0 |
0 |
0 |
| SvOK_off(p_state->buf); |
49 |
61 |
110 |
|
| 1862 |
|
| } |
| 1863 |
|
| } |
| 1864 |
|
| else { |
| 1865 |
|
| /* need to keep rest in buffer */ |
| 1866 |
7208 |
▶ | if (p_state->buf) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p_state->buf) { |
7052 |
156 |
7208 |
|
| 1867 |
|
| /* chop off some chars at the beginning */ |
| 1868 |
7052 |
▶ | if (SvOK(p_state->buf)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(p_state->buf)) { |
6961 |
91 |
7052 |
|
| 1869 |
6961 |
| sv_chop(p_state->buf, s); |
| 1870 |
|
| } |
| 1871 |
|
| else { |
| 1872 |
91 |
| sv_setpvn(p_state->buf, s, end - s); |
| 1873 |
91 |
▶ | if (utf8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (utf8) |
16 |
75 |
91 |
|
| 1874 |
16 |
| SvUTF8_on(p_state->buf); |
| 1875 |
|
| else |
| 1876 |
75 |
| SvUTF8_off(p_state->buf); |
| 1877 |
|
| } |
| 1878 |
|
| } |
| 1879 |
|
| else { |
| 1880 |
156 |
| p_state->buf = newSVpv(s, end - s); |
| 1881 |
156 |
▶ | if (utf8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (utf8) |
8 |
148 |
156 |
|
| 1882 |
8 |
| SvUTF8_on(p_state->buf); |
| 1883 |
|
| } |
| 1884 |
|
| } |
| 1885 |
7388 |
| return; |
| 1886 |
|
| } |