Strip.xs

filter: Statementstmt 87.1% 27 / 31 Branchbran 56.2% 9 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 76.6% 36 / 47 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« strip_html.c ↑ Summary
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4  
5 #include "strip_html.h"
6  
7 MODULE = HTML::Strip PACKAGE = HTML::Strip
8  
9 PROTOTYPES: ENABLE
10  
11 Stripper *
12 _create()
13 PREINIT:
14 Stripper * stripper;
15 CODE:
16 18 Newx( stripper, 1, Stripper );
17 18 _reset( stripper );
18 18 RETVAL = stripper;
19 OUTPUT:
20 RETVAL
21  
22 void
23 _xs_destroy( stripper )
24 Stripper * stripper
25 CODE:
26 18 Safefree( stripper );
27  
28 SV *
29 _strip_html( stripper, text )
30 Stripper * stripper
31 SV * text
32 PREINIT:
33 41 char * raw = (char *)SvPV_nolen(text);
34 char * clean;
35 41 int size = strlen(raw)+1;
36 INIT:
37 41 Newx( clean, size+1, char);
38 CODE:
39 41 _strip_html( stripper, raw, clean, SvUTF8(text) );
40 41 RETVAL = newSVpv(clean, strlen(clean));
41 41 ▶ if( SvUTF8(text) )
Branch: 1 branch
BranchTrueFalseTotal
if( SvUTF8(text) ) 3 38 41
42 3 SvUTF8_on(RETVAL);
43 OUTPUT:
44 RETVAL
45 CLEANUP:
46 41 Safefree( clean );
47  
48 void
49 _reset( stripper )
50 Stripper * stripper
51  
52 void
53 clear_striptags( stripper )
54 Stripper * stripper
55  
56 void
57 add_striptag( stripper, tag )
58 Stripper * stripper
59 char * tag
60  
61 void
62 set_emit_spaces( stripper, emit )
63 Stripper * stripper
64 int emit
65 CODE:
66 18 stripper->o_emit_spaces = emit;
67  
68 void
69 set_decode_entities( stripper, decode )
70 Stripper * stripper
71 int decode
72 CODE:
73 18 stripper->o_decode_entities = decode;
74  
75 int
76 decode_entities( stripper )
77 Stripper * stripper
78 CODE:
79 39 ▶ RETVAL = stripper->o_decode_entities;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = stripper->o_decode_entities; 27 12 39
80 OUTPUT:
81 RETVAL
82  
83 void
84 _set_striptags_ref( stripper, tagref )
85 Stripper * stripper
86 SV * tagref
87 PREINIT:
88 AV * tags;
89 20 I32 numtags = 0;
90 int n;
91 20 ▶ if( (SvROK(tagref)) &&
Branch: 1 branch
BranchTrueFalseTotal
if( (SvROK(tagref)) && 20 0 20
92 20 ▶ (SvTYPE(SvRV(tagref)) == SVt_PVAV) ) {
Branch: 1 branch
BranchTrueFalseTotal
(SvTYPE(SvRV(tagref)) == SVt_PVAV) ) { 20 0 20
93 20 tags = (AV *) SvRV(tagref);
94 } else {
95 0 XSRETURN_UNDEF;
96 }
97 20 numtags = av_len(tags);
98 20 ▶ if( numtags < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if( numtags < 0 ) { 0 20 20
99 0 XSRETURN_UNDEF;
100 }
101 CODE:
102 20 clear_striptags( stripper );
103 95 ▶ for (n = 0; n <= numtags; n++) {
Branch: 1 branch
BranchTrueFalseTotal
for (n = 0; n <= numtags; n++) { 75 20 95
104 STRLEN l;
105 75 char * tag = SvPV(*av_fetch(tags, n, 0), l);
106 75 add_striptag( stripper, tag );
107 }
108  
109 void
110 set_auto_reset( stripper, value )
111 Stripper * stripper
112 int value
113 CODE:
114 18 stripper->o_auto_reset = value;
115  
116 int
117 auto_reset( stripper )
118 Stripper * stripper
119 CODE:
120 0 ▶ RETVAL = stripper->o_auto_reset;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = stripper->o_auto_reset; 0 0 0
121 OUTPUT:
122 RETVAL
123  
124 void
125 set_debug( stripper, value )
126 Stripper * stripper
127 int value
128 CODE:
129 18 stripper->o_debug = value;
130  
131 int
132 debug( stripper )
133 Stripper * stripper
134 CODE:
135 0 ▶ RETVAL = stripper->o_debug;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = stripper->o_debug; 0 0 0
136 OUTPUT:
137 RETVAL
« strip_html.c ↑ Summary