Parser.xs

filter: Statementstmt 92.0% 185 / 201 Branchbran 82.3% 107 / 130 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 88.2% 292 / 331 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« hparser.c ↑ Summary tokenpos.h »
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 #define PERL_NO_GET_CONTEXT /* we want efficiency */
10 #include "EXTERN.h"
11 #include "perl.h"
12 #include "XSUB.h"
13 #include "ppport.h"
14  
15 #define DOWARN (PL_dowarn & G_WARN_ON)
16 #define RETHROW croak(Nullch)
17  
18 /*
19 * Include stuff. We include .c files instead of linking them,
20 * so that they don't have to pollute the external dll name space.
21 */
22  
23 #ifdef EXTERN
24 #undef EXTERN
25 #endif
26  
27 #define EXTERN static /* Don't pollute */
28  
29 #include "hparser.h"
30 #include "util.c"
31 #include "hparser.c"
32  
33  
34 /*
35 * Support functions for the XS glue
36 */
37  
38 static SV*
39 514 check_handler(pTHX_ SV* h)
40 {
41 514 ▶ SvGETMAGIC(h);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(h); 1 513 514
SvGETMAGIC(h); 0 1 1
42 514 ▶ if (SvROK(h)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(h)) { 288 226 514
43 288 SV* myref = SvRV(h);
44 288 ▶ if (SvTYPE(myref) == SVt_PVCV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(myref) == SVt_PVCV) 162 126 288
45 162 return newSVsv(h);
46 126 ▶ if (SvTYPE(myref) == SVt_PVAV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(myref) == SVt_PVAV) 125 1 126
47 125 return SvREFCNT_inc(myref);
48 1 croak("Only code or array references allowed as handler");
49 }
50 226 ▶ return SvOK(h) ? newSVsv(h) : 0;
Branch: 1 branch
BranchTrueFalseTotal
return SvOK(h) ? newSVsv(h) : 0; 224 2 226
51 }
52  
53  
54 static PSTATE*
55 8050 get_pstate_iv(pTHX_ SV* sv)
56 {
57 PSTATE *p;
58 8050 ▶ MAGIC *mg = SvMAGICAL(sv) ? mg_find(sv, '~') : NULL;
Branch: 1 branch
BranchTrueFalseTotal
MAGIC *mg = SvMAGICAL(sv) ? mg_find(sv, '~') : NULL; 8049 1 8050
59  
60 8050 ▶ if (!mg)
Branch: 1 branch
BranchTrueFalseTotal
if (!mg) 1 8049 8050
61 1 croak("Lost parser state magic");
62 8049 p = (PSTATE *)mg->mg_ptr;
63 8049 ▶ if (!p)
Branch: 1 branch
BranchTrueFalseTotal
if (!p) 0 8049 8049
64 0 croak("Lost parser state magic");
65 8049 ▶ if (p->signature != P_SIGNATURE)
Branch: 1 branch
BranchTrueFalseTotal
if (p->signature != P_SIGNATURE) 0 8049 8049
66 0 croak("Bad signature in parser state object at %p", p);
67 8049 return p;
68 }
69  
70  
71 static PSTATE*
72 8052 get_pstate_hv(pTHX_ SV* sv) /* used by XS typemap */
73 {
74 HV* hv;
75 SV** svp;
76  
77 8052 sv = SvRV(sv);
78 8052 ▶ if (!sv || SvTYPE(sv) != SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
if (!sv || SvTYPE(sv) != SVt_PVHV) 8052 0 8052
if (!sv || SvTYPE(sv) != SVt_PVHV) 0 8052 8052
79 0 croak("Not a reference to a hash");
80 8052 hv = (HV*)sv;
81 8052 svp = hv_fetchs(hv, "_hparser_xs_state", 0);
82 8052 ▶ if (svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (svp) { 8051 1 8052
83 8051 ▶ if (SvROK(*svp))
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(*svp)) 8050 1 8051
84 8050 return get_pstate_iv(aTHX_ SvRV(*svp));
85 else
86 1 croak("_hparser_xs_state element is not a reference");
87 }
88 1 croak("Can't find '_hparser_xs_state' element in HTML::Parser hash");
89 return 0;
90 }
91  
92  
93 static void
94 129 free_pstate(pTHX_ PSTATE* pstate)
95 {
96 int i;
97 129 SvREFCNT_dec(pstate->buf);
98 129 SvREFCNT_dec(pstate->pend_text);
99 129 SvREFCNT_dec(pstate->skipped_text);
100 #ifdef MARKED_SECTION
101 129 SvREFCNT_dec(pstate->ms_stack);
102 #endif
103 129 SvREFCNT_dec(pstate->bool_attr_val);
104 1290 ▶ for (i = 0; i < EVENT_COUNT; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < EVENT_COUNT; i++) { 1161 129 1290
105 1161 SvREFCNT_dec(pstate->handlers[i].cb);
106 1161 SvREFCNT_dec(pstate->handlers[i].argspec);
107 }
108  
109 129 SvREFCNT_dec(pstate->report_tags);
110 129 SvREFCNT_dec(pstate->ignore_tags);
111 129 SvREFCNT_dec(pstate->ignore_elements);
112 129 SvREFCNT_dec(pstate->ignoring_element);
113  
114 129 SvREFCNT_dec(pstate->tmp);
115  
116 129 pstate->signature = 0;
117 129 Safefree(pstate);
118 129 }
119  
120 static int
121 129 magic_free_pstate(pTHX_ SV *sv, MAGIC *mg)
122 {
123 129 free_pstate(aTHX_ (PSTATE *)mg->mg_ptr);
124 129 return 0;
125 }
126  
127 #if defined(USE_ITHREADS)
128  
129 static PSTATE *
130 dup_pstate(pTHX_ PSTATE *pstate, CLONE_PARAMS *params)
131 {
132 PSTATE *pstate2;
133 int i;
134  
135 Newz(56, pstate2, 1, PSTATE);
136 pstate2->signature = pstate->signature;
137  
138 pstate2->buf = SvREFCNT_inc(sv_dup(pstate->buf, params));
139 pstate2->offset = pstate->offset;
140 pstate2->line = pstate->line;
141 pstate2->column = pstate->column;
142 pstate2->start_document = pstate->start_document;
143 pstate2->parsing = pstate->parsing;
144 pstate2->eof = pstate->eof;
145  
146 pstate2->literal_mode = pstate->literal_mode;
147 pstate2->is_cdata = pstate->is_cdata;
148 pstate2->no_dash_dash_comment_end = pstate->no_dash_dash_comment_end;
149 pstate2->pending_end_tag = pstate->pending_end_tag;
150  
151 pstate2->pend_text = SvREFCNT_inc(sv_dup(pstate->pend_text, params));
152 pstate2->pend_text_is_cdata = pstate->pend_text_is_cdata;
153 pstate2->pend_text_offset = pstate->pend_text_offset;
154 pstate2->pend_text_line = pstate->pend_text_offset;
155 pstate2->pend_text_column = pstate->pend_text_column;
156  
157 pstate2->skipped_text = SvREFCNT_inc(sv_dup(pstate->skipped_text, params));
158  
159 #ifdef MARKED_SECTION
160 pstate2->ms = pstate->ms;
161 pstate2->ms_stack =
162 (AV *)SvREFCNT_inc(sv_dup((SV *)pstate->ms_stack, params));
163 pstate2->marked_sections = pstate->marked_sections;
164 #endif
165  
166 pstate2->strict_comment = pstate->strict_comment;
167 pstate2->strict_names = pstate->strict_names;
168 pstate2->strict_end = pstate->strict_end;
169 pstate2->xml_mode = pstate->xml_mode;
170 pstate2->unbroken_text = pstate->unbroken_text;
171 pstate2->attr_encoded = pstate->attr_encoded;
172 pstate2->case_sensitive = pstate->case_sensitive;
173 pstate2->closing_plaintext = pstate->closing_plaintext;
174 pstate2->utf8_mode = pstate->utf8_mode;
175 pstate2->empty_element_tags = pstate->empty_element_tags;
176 pstate2->xml_pic = pstate->xml_pic;
177 pstate2->backquote = pstate->backquote;
178  
179 pstate2->bool_attr_val =
180 SvREFCNT_inc(sv_dup(pstate->bool_attr_val, params));
181 for (i = 0; i < EVENT_COUNT; i++) {
182 pstate2->handlers[i].cb =
183 SvREFCNT_inc(sv_dup(pstate->handlers[i].cb, params));
184 pstate2->handlers[i].argspec =
185 SvREFCNT_inc(sv_dup(pstate->handlers[i].argspec, params));
186 }
187 pstate2->argspec_entity_decode = pstate->argspec_entity_decode;
188  
189 pstate2->report_tags =
190 (HV *)SvREFCNT_inc(sv_dup((SV *)pstate->report_tags, params));
191 pstate2->ignore_tags =
192 (HV *)SvREFCNT_inc(sv_dup((SV *)pstate->ignore_tags, params));
193 pstate2->ignore_elements =
194 (HV *)SvREFCNT_inc(sv_dup((SV *)pstate->ignore_elements, params));
195  
196 pstate2->ignoring_element =
197 SvREFCNT_inc(sv_dup(pstate->ignoring_element, params));
198 pstate2->ignore_depth = pstate->ignore_depth;
199  
200 if (params->flags & CLONEf_JOIN_IN) {
201 pstate2->entity2char =
202 get_hv("HTML::Entities::entity2char", GV_ADD);
203 } else {
204 pstate2->entity2char = (HV *)sv_dup((SV *)pstate->entity2char, params);
205 }
206 pstate2->tmp = SvREFCNT_inc(sv_dup(pstate->tmp, params));
207  
208 return pstate2;
209 }
210  
211 static int
212 magic_dup_pstate(pTHX_ MAGIC *mg, CLONE_PARAMS *params)
213 {
214 mg->mg_ptr = (char *)dup_pstate(aTHX_ (PSTATE *)mg->mg_ptr, params);
215 return 0;
216 }
217  
218 #endif
219  
220 const MGVTBL vtbl_pstate =
221 {
222 0,
223 0,
224 0,
225 0,
226 MEMBER_TO_FPTR(magic_free_pstate),
227 #if defined(USE_ITHREADS)
228 0,
229 MEMBER_TO_FPTR(magic_dup_pstate),
230 #endif
231 };
232  
233  
234 /*
235 * XS interface definition.
236 */
237  
238 MODULE = HTML::Parser PACKAGE = HTML::Parser
239  
240 PROTOTYPES: DISABLE
241  
242 void
243 _alloc_pstate(self)
244 SV* self;
245 PREINIT:
246 PSTATE* pstate;
247 SV* sv;
248 HV* hv;
249 MAGIC* mg;
250  
251 CODE:
252 129 sv = SvRV(self);
253 129 ▶ if (!sv || SvTYPE(sv) != SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
if (!sv || SvTYPE(sv) != SVt_PVHV) 129 0 129
if (!sv || SvTYPE(sv) != SVt_PVHV) 0 129 129
254 0 croak("Not a reference to a hash");
255 129 hv = (HV*)sv;
256  
257 129 Newz(56, pstate, 1, PSTATE);
258 129 pstate->signature = P_SIGNATURE;
259 129 pstate->entity2char = get_hv("HTML::Entities::entity2char", GV_ADD);
260 129 pstate->tmp = NEWSV(0, 20);
261  
262 129 sv = newSViv(PTR2IV(pstate));
263 129 sv_magic(sv, 0, '~', (char *)pstate, 0);
264 129 mg = mg_find(sv, '~');
265 assert(mg);
266 129 mg->mg_virtual = (MGVTBL*)&vtbl_pstate;
267 #if defined(USE_ITHREADS)
268 mg->mg_flags |= MGf_DUP;
269 #endif
270 129 SvREADONLY_on(sv);
271  
272 129 hv_stores(hv, "_hparser_xs_state", newRV_noinc(sv));
273  
274 void
275 parse(self, chunk)
276 SV* self;
277 SV* chunk
278 PREINIT:
279 7213 PSTATE* p_state = get_pstate_hv(aTHX_ self);
280 PPCODE:
281 7213 (void)sv_2mortal(SvREFCNT_inc(SvRV(self)));
282 7213 ▶ if (p_state->parsing)
Branch: 1 branch
BranchTrueFalseTotal
if (p_state->parsing) 1 7212 7213
283 1 croak("Parse loop not allowed");
284 7212 p_state->parsing = 1;
285 7258 ▶ if (SvROK(chunk) && SvTYPE(SvRV(chunk)) == SVt_PVCV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(chunk) && SvTYPE(SvRV(chunk)) == SVt_PVCV) { 47 7165 7212
if (SvROK(chunk) && SvTYPE(SvRV(chunk)) == SVt_PVCV) { 47 0 47
286 47 SV* generator = chunk;
287 STRLEN len;
288 do {
289 int count;
290 275 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 275 275
291 275 count = call_sv(generator, G_SCALAR|G_EVAL);
292 275 SPAGAIN;
293 275 ▶ chunk = count ? POPs : 0;
Branch: 1 branch
BranchTrueFalseTotal
chunk = count ? POPs : 0; 275 0 275
294 275 PUTBACK;
295  
296 275 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 275 0 275
if (SvTRUE(ERRSV)) { 1 274 275
297 1 p_state->parsing = 0;
298 1 p_state->eof = 0;
299 1 RETHROW;
300 }
301  
302 274 ▶ if (chunk && SvOK(chunk)) {
Branch: 2 branches
BranchTrueFalseTotal
if (chunk && SvOK(chunk)) { 274 0 274
if (chunk && SvOK(chunk)) { 274 0 274
303 274 (void)SvPV(chunk, len); /* get length */
304 }
305 else {
306 0 len = 0;
307 }
308 274 ▶ parse(aTHX_ p_state, len ? chunk : 0, self);
Branch: 1 branch
BranchTrueFalseTotal
parse(aTHX_ p_state, len ? chunk : 0, self); 228 46 274
309 274 SPAGAIN;
310  
311 274 ▶ } while (len && !p_state->eof);
Branch: 2 branches
BranchTrueFalseTotal
} while (len && !p_state->eof); 228 46 274
} while (len && !p_state->eof); 228 0 228
312 }
313 else {
314 7165 parse(aTHX_ p_state, chunk, self);
315 7164 SPAGAIN;
316 }
317 7210 p_state->parsing = 0;
318 7210 ▶ if (p_state->eof) {
Branch: 1 branch
BranchTrueFalseTotal
if (p_state->eof) { 9 7201 7210
319 9 p_state->eof = 0;
320 9 PUSHs(sv_newmortal());
321 }
322 else {
323 7201 PUSHs(self);
324 }
325  
326 void
327 eof(self)
328 SV* self;
329 PREINIT:
330 162 PSTATE* p_state = get_pstate_hv(aTHX_ self);
331 PPCODE:
332 162 ▶ if (p_state->parsing)
Branch: 1 branch
BranchTrueFalseTotal
if (p_state->parsing) 11 151 162
333 11 p_state->eof = 1;
334 else {
335 151 p_state->parsing = 1;
336 151 parse(aTHX_ p_state, 0, self); /* flush */
337 151 SPAGAIN;
338 151 p_state->parsing = 0;
339 }
340 162 PUSHs(self);
341  
342 SV*
343 strict_comment(pstate,...)
344 PSTATE* pstate
345 ALIAS:
346 HTML::Parser::strict_comment = 1
347 HTML::Parser::strict_names = 2
348 HTML::Parser::xml_mode = 3
349 HTML::Parser::unbroken_text = 4
350 HTML::Parser::marked_sections = 5
351 HTML::Parser::attr_encoded = 6
352 HTML::Parser::case_sensitive = 7
353 HTML::Parser::strict_end = 8
354 HTML::Parser::closing_plaintext = 9
355 HTML::Parser::utf8_mode = 10
356 HTML::Parser::empty_element_tags = 11
357 HTML::Parser::xml_pic = 12
358 HTML::Parser::backquote = 13
359 PREINIT:
360 bool *attr;
361 CODE:
362 106 switch (ix) {
363 31 case 1: attr = &pstate->strict_comment; break;
364 0 case 2: attr = &pstate->strict_names; break;
365 15 case 3: attr = &pstate->xml_mode; break;
366 18 case 4: attr = &pstate->unbroken_text; break;
367 4 case 5:
368 #ifdef MARKED_SECTION
369 4 attr = &pstate->marked_sections; break;
370 #else
371 croak("marked sections not supported"); break;
372 #endif
373 3 case 6: attr = &pstate->attr_encoded; break;
374 8 case 7: attr = &pstate->case_sensitive; break;
375 0 case 8: attr = &pstate->strict_end; break;
376 2 case 9: attr = &pstate->closing_plaintext; break;
377 19 case 10: attr = &pstate->utf8_mode; break;
378 4 case 11: attr = &pstate->empty_element_tags; break;
379 1 case 12: attr = &pstate->xml_pic; break;
380 1 case 13: attr = &pstate->backquote; break;
381 0 default:
382 0 croak("Unknown boolean attribute (%d)", (int)ix);
383 }
384 106 ▶ RETVAL = boolSV(*attr);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = boolSV(*attr); 17 89 106
385 106 ▶ if (items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) 87 19 106
386 87 *attr = SvTRUE(ST(1));
387 OUTPUT:
388 RETVAL
389  
390 SV*
391 boolean_attribute_value(pstate,...)
392 PSTATE* pstate
393 CODE:
394 3 RETVAL = pstate->bool_attr_val ? newSVsv(pstate->bool_attr_val)
395 5 ▶ : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
: &PL_sv_undef; 3 2 5
396 5 ▶ if (items > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) { 3 2 5
397 3 SvREFCNT_dec(pstate->bool_attr_val);
398 3 pstate->bool_attr_val = newSVsv(ST(1));
399 }
400 OUTPUT:
401 RETVAL
402  
403 void
404 ignore_tags(pstate,...)
405 PSTATE* pstate
406 ALIAS:
407 HTML::Parser::report_tags = 1
408 HTML::Parser::ignore_tags = 2
409 HTML::Parser::ignore_elements = 3
410 PREINIT:
411 HV** attr;
412 int i;
413 CODE:
414 37 switch (ix) {
415 15 case 1: attr = &pstate->report_tags; break;
416 11 case 2: attr = &pstate->ignore_tags; break;
417 11 case 3: attr = &pstate->ignore_elements; break;
418 0 default:
419 0 croak("Unknown tag-list attribute (%d)", (int)ix);
420 }
421 37 ▶ if (GIMME_V != G_VOID)
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V != G_VOID) 0 37 37
422 0 croak("Can't report tag lists yet");
423  
424 37 items--; /* pstate */
425 37 ▶ if (items) {
Branch: 1 branch
BranchTrueFalseTotal
if (items) { 34 3 37
426 34 ▶ if (*attr)
Branch: 1 branch
BranchTrueFalseTotal
if (*attr) 3 31 34
427 3 hv_clear(*attr);
428 else
429 31 *attr = newHV();
430  
431 75 ▶ for (i = 0; i < items; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < items; i++) { 41 34 75
432 41 SV* sv = ST(i+1);
433 41 ▶ if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sv)) { 14 27 41
434 14 sv = SvRV(sv);
435 14 ▶ if (SvTYPE(sv) == SVt_PVAV) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(sv) == SVt_PVAV) { 14 0 14
436 14 AV* av = (AV*)sv;
437 STRLEN j;
438 14 STRLEN top = av_top_index(av);
439 121 ▶ for (j = 0; j <= top; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j <= top; j++) { 107 14 121
440 107 SV**svp = av_fetch(av, j, 0);
441 107 ▶ if (svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (svp) { 107 0 107
442 107 hv_store_ent(*attr, *svp, newSViv(0), 0);
443 }
444 }
445 }
446 else
447 0 croak("Tag list must be plain scalars and arrays");
448 }
449 else {
450 27 hv_store_ent(*attr, sv, newSViv(0), 0);
451 }
452 }
453 }
454 3 ▶ else if (*attr) {
Branch: 1 branch
BranchTrueFalseTotal
else if (*attr) { 3 0 3
455 3 SvREFCNT_dec(*attr);
456 3 *attr = 0;
457 }
458  
459 void
460 handler(pstate, eventname,...)
461 PSTATE* pstate
462 SV* eventname
463 PREINIT:
464 STRLEN name_len;
465 526 char *name = SvPV(eventname, name_len);
466 526 int event = -1;
467 int i;
468 struct p_handler *h;
469 PPCODE:
470 /* map event name string to event_id */
471 2271 ▶ for (i = 0; i < EVENT_COUNT; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < EVENT_COUNT; i++) { 2270 1 2271
472 2270 ▶ if (strEQ(name, event_id_str[i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(name, event_id_str[i])) { 525 1745 2270
473 525 event = i;
474 525 break;
475 }
476 }
477 526 ▶ if (event < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (event < 0) 1 525 526
478 1 croak("No handler for %s events", name);
479  
480 525 h = &pstate->handlers[event];
481  
482 /* set up return value */
483 525 ▶ if (h->cb) {
Branch: 1 branch
BranchTrueFalseTotal
if (h->cb) { 64 461 525
484 64 ▶ PUSHs((SvTYPE(h->cb) == SVt_PVAV)
Branch: 1 branch
BranchTrueFalseTotal
PUSHs((SvTYPE(h->cb) == SVt_PVAV) 50 14 64
485 ? sv_2mortal(newRV_inc(h->cb))
486 : sv_2mortal(newSVsv(h->cb)));
487 }
488 else {
489 461 PUSHs(&PL_sv_undef);
490 }
491  
492 /* update */
493 525 ▶ if (items > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 3) { 463 62 525
494 463 SvREFCNT_dec(h->argspec);
495 463 h->argspec = 0;
496 463 h->argspec = argspec_compile(ST(3), pstate);
497 }
498 519 ▶ if (items > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 2) { 514 5 519
499 514 SvREFCNT_dec(h->cb);
500 514 h->cb = 0;
501 514 h->cb = check_handler(aTHX_ ST(2));
502 }
503  
504  
505 MODULE = HTML::Parser PACKAGE = HTML::Entities
506  
507 void
508 decode_entities(...)
509 PREINIT:
510 int i;
511 65 HV *entity2char = get_hv("HTML::Entities::entity2char", 0);
512 PPCODE:
513 65 ▶ if (GIMME_V == G_SCALAR && items > 1)
Branch: 2 branches
BranchTrueFalseTotal
if (GIMME_V == G_SCALAR && items > 1) 36 29 65
if (GIMME_V == G_SCALAR && items > 1) 0 36 36
514 0 items = 1;
515 130 ▶ for (i = 0; i < items; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < items; i++) { 65 65 130
516 65 ▶ if (GIMME_V != G_VOID)
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V != G_VOID) 36 29 65
517 36 ST(i) = sv_2mortal(newSVsv(ST(i)));
518 else {
519 #ifdef SV_CHECK_THINKFIRST
520 29 ▶ SV_CHECK_THINKFIRST(ST(i));
Branch: 1 branch
BranchTrueFalseTotal
SV_CHECK_THINKFIRST(ST(i)); 8 21 29
521 #endif
522 29 ▶ if (SvREADONLY(ST(i)))
Branch: 1 branch
BranchTrueFalseTotal
if (SvREADONLY(ST(i))) 0 29 29
523 0 croak("Can't inline decode readonly string in decode_entities()");
524 }
525 65 decode_entities(aTHX_ ST(i), entity2char, 0);
526 }
527 65 SP += items;
528  
529 void
530 _decode_entities(string, entities, ...)
531 SV* string
532 SV* entities
533 PREINIT:
534 HV* entities_hv;
535 29 ▶ bool expand_prefix = (items > 2) ? SvTRUE(ST(2)) : 0;
Branch: 2 branches
BranchTrueFalseTotal
bool expand_prefix = (items > 2) ? SvTRUE(ST(2)) : 0; 4 25 29
bool expand_prefix = (items > 2) ? SvTRUE(ST(2)) : 0; 4 0 4
536 CODE:
537 29 ▶ if (SvOK(entities)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(entities)) { 27 2 29
538 27 ▶ if (SvROK(entities) && SvTYPE(SvRV(entities)) == SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(entities) && SvTYPE(SvRV(entities)) == SVt_PVHV) { 26 1 27
if (SvROK(entities) && SvTYPE(SvRV(entities)) == SVt_PVHV) { 25 1 26
539 25 entities_hv = (HV*)SvRV(entities);
540 }
541 else {
542 2 croak("2nd argument must be hash reference");
543 }
544 }
545 else {
546 2 entities_hv = 0;
547 }
548 #ifdef SV_CHECK_THINKFIRST
549 27 ▶ SV_CHECK_THINKFIRST(string);
Branch: 1 branch
BranchTrueFalseTotal
SV_CHECK_THINKFIRST(string); 18 9 27
550 #endif
551 26 ▶ if (SvREADONLY(string))
Branch: 1 branch
BranchTrueFalseTotal
if (SvREADONLY(string)) 0 26 26
552 0 croak("Can't inline decode readonly string in _decode_entities()");
553 26 decode_entities(aTHX_ string, entities_hv, expand_prefix);
554  
555 bool
556 _probably_utf8_chunk(string)
557 SV* string
558 PREINIT:
559 STRLEN len;
560 char *s;
561 CODE:
562 8 sv_utf8_downgrade(string, 0);
563 8 s = SvPV(string, len);
564 8 RETVAL = probably_utf8_chunk(aTHX_ s, len);
565 OUTPUT:
566 RETVAL
567  
568 int
569 UNICODE_SUPPORT()
570 PROTOTYPE:
571 CODE:
572 3 ▶ RETVAL = 1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 1; 0 3 3
573 OUTPUT:
574 RETVAL
575  
576  
577 MODULE = HTML::Parser PACKAGE = HTML::Parser
« hparser.c ↑ Summary tokenpos.h »