DOM.xs

filter: Statementstmt 0.0% 0 / 1312 Branchbran 0.0% 0 / 2098 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 3410 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/HTML5/DOM.pm ↑ Summary gen/modest_errors.c »
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4  
5 #define NEED_newRV_noinc
6 #define NEED_sv_2pv_flags
7 #include "ppport.h"
8 #include "utils.h"
9  
10 //#define DOM_GC_TRACE(msg, ...) fprintf(stderr, "[GC] " msg "\n", ##__VA_ARGS__);
11 #define DOM_GC_TRACE(...)
12  
13 // HACK: sv_derived_from_pvn faster than sv_derived_from
14 #if PERL_BCDVERSION > 0x5015004
15 #undef sv_derived_from
16 #define sv_derived_from(sv, name) sv_derived_from_pvn(sv, name, sizeof(name) - 1, 0)
17 #else
18 #define sv_derived_from_pvn(sv, name, len) sv_derived_from(sv, name)
19 #endif
20  
21 #define sub_croak(cv, msg, ...) do { \
22 const GV *const __gv = CvGV(cv); \
23 if (__gv) { \
24 const char *__gvname = GvNAME(__gv); \
25 const HV *__stash = GvSTASH(__gv); \
26 const char *__hvname = __stash ? HvNAME(__stash) : NULL; \
27 croak("%s%s%s(): " msg, __hvname ? __hvname : __gvname, __hvname ? "::" : "", __hvname ? __gvname : "", ##__VA_ARGS__); \
28 } \
29 } while (0);
30  
31 typedef html5_dom_parser_t * HTML5__DOM;
32 typedef myhtml_collection_t * HTML5__DOM__Collection;
33 typedef myhtml_tree_node_t * HTML5__DOM__Node;
34 typedef myhtml_tree_node_t * HTML5__DOM__Element;
35 typedef myhtml_tree_node_t * HTML5__DOM__Text;
36 typedef myhtml_tree_node_t * HTML5__DOM__Comment;
37 typedef myhtml_tree_node_t * HTML5__DOM__Document;
38 typedef myhtml_tree_node_t * HTML5__DOM__Fragment;
39 typedef myhtml_tree_node_t * HTML5__DOM__DocType;
40 typedef html5_dom_tree_t * HTML5__DOM__Tree;
41 typedef html5_css_parser_t * HTML5__DOM__CSS;
42 typedef html5_css_selector_t * HTML5__DOM__CSS__Selector;
43 typedef html5_css_selector_entry_t * HTML5__DOM__CSS__Selector__Entry;
44 typedef html5_dom_async_result * HTML5__DOM__AsyncResult;
45  
46 0 static mystatus_t sv_serialization_callback(const char *data, size_t len, void *ctx) {
47 0 sv_catpvn((SV *) ctx, data, len);
48 0 return MyCORE_STATUS_OK;
49 }
50  
51 0 static inline SV *pack_pointer(const char *clazz, void *ptr) {
52 0 SV *sv = newSV(0);
53 0 sv_setref_pv(sv, clazz, ptr);
54 0 return sv;
55 }
56  
57 0 static void html5_dom_recursive_node_text(myhtml_tree_node_t *node, SV *sv) {
58 0 node = myhtml_node_child(node);
59 0 ▶ while (node) {
Branch: 1 branch
BranchTrueFalseTotal
while (node) { 0 0 0
60 0 ▶ if (node->tag_id == MyHTML_TAG__TEXT) {
Branch: 1 branch
BranchTrueFalseTotal
if (node->tag_id == MyHTML_TAG__TEXT) { 0 0 0
61 0 size_t text_len = 0;
62 0 const char *text = myhtml_node_text(node, &text_len);
63 0 ▶ if (text_len)
Branch: 1 branch
BranchTrueFalseTotal
if (text_len) 0 0 0
64 0 sv_catpvn(sv, text, text_len);
65 0 ▶ } else if (node_is_element(node)) {
Branch: 4 branches
BranchTrueFalseTotal
} else if (node_is_element(node)) { 0 0 0
} else if (node_is_element(node)) { 0 0 0
} else if (node_is_element(node)) { 0 0 0
} else if (node_is_element(node)) { 0 0 0
66 0 html5_dom_recursive_node_text(node, sv);
67 }
68 0 node = myhtml_node_next(node);
69 }
70 0 }
71  
72 0 static SV *create_tree_object(myhtml_tree_t *tree, SV *parent, html5_dom_parser_t *parser) {
73 0 tree->context = safemalloc(sizeof(html5_dom_tree_t));
74
75 0 html5_dom_tree_t *tree_obj = (html5_dom_tree_t *) tree->context;
76 0 tree_obj->tree = tree;
77 0 tree_obj->parent = parent;
78 0 tree_obj->parser = parser;
79 0 tree_obj->fragment_tag_id = MyHTML_TAG__UNDEF;
80
81 0 SvREFCNT_inc(parent);
82
83 0 SV *sv = pack_pointer("HTML5::DOM::Tree", tree_obj);
84 0 tree_obj->sv = SvRV(sv);
85
86 DOM_GC_TRACE("DOM::Tree::NEW (refcnt=%d)", SvREFCNT(sv));
87
88 0 return sv;
89 }
90  
91 0 static inline const char *get_node_class(myhtml_tree_node_t *node) {
92 0 html5_dom_tree_t *context = (html5_dom_tree_t *) node->tree->context;
93
94 0 ▶ if (node->tag_id != MyHTML_TAG__UNDEF) {
Branch: 1 branch
BranchTrueFalseTotal
if (node->tag_id != MyHTML_TAG__UNDEF) { 0 0 0
95 0 ▶ if (node->tag_id == MyHTML_TAG__TEXT) {
Branch: 1 branch
BranchTrueFalseTotal
if (node->tag_id == MyHTML_TAG__TEXT) { 0 0 0
96 0 return "HTML5::DOM::Text";
97 0 ▶ } else if (node->tag_id == MyHTML_TAG__COMMENT) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (node->tag_id == MyHTML_TAG__COMMENT) { 0 0 0
98 0 return "HTML5::DOM::Comment";
99 0 ▶ } else if (node->tag_id == MyHTML_TAG__DOCTYPE) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (node->tag_id == MyHTML_TAG__DOCTYPE) { 0 0 0
100 0 return "HTML5::DOM::DocType";
101 0 ▶ } else if (context->fragment_tag_id && node->tag_id == context->fragment_tag_id) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (context->fragment_tag_id && node->tag_id == context->fragment_tag_id) { 0 0 0
} else if (context->fragment_tag_id && node->tag_id == context->fragment_tag_id) { 0 0 0
102 0 return "HTML5::DOM::Fragment";
103 }
104 0 return "HTML5::DOM::Element";
105 }
106
107 // Modest myhtml bug - document node has tag_id == MyHTML_TAG__UNDEF
108 0 ▶ if (node_is_document(node))
Branch: 2 branches
BranchTrueFalseTotal
if (node_is_document(node)) 0 0 0
if (node_is_document(node)) 0 0 0
109 0 return "HTML5::DOM::Document";
110
111 0 return "HTML5::DOM::Node";
112 }
113  
114 0 static SV *tree_to_sv(myhtml_tree_t *tree) {
115 0 html5_dom_tree_t *context = (html5_dom_tree_t *) tree->context;
116 0 return newRV(context->sv);
117 }
118  
119 0 static SV *myhtml_to_sv(myhtml_tree_t *tree) {
120 0 html5_dom_tree_t *context = (html5_dom_tree_t *) tree->context;
121 0 return newRV(context->parent);
122 }
123  
124 0 static SV *node_to_sv(myhtml_tree_node_t *node) {
125 0 ▶ if (!node)
Branch: 1 branch
BranchTrueFalseTotal
if (!node) 0 0 0
126 0 return &PL_sv_undef;
127
128 0 SV *sv = (SV *) myhtml_node_get_data(node);
129 0 ▶ if (!sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv) { 0 0 0
130 0 SV *node_ref = pack_pointer(get_node_class(node), (void *) node);
131 0 sv = SvRV(node_ref);
132 0 myhtml_node_set_data(node, (void *) sv);
133
134 DOM_GC_TRACE("DOM::Node::NEW (new refcnt=%d)", SvREFCNT(sv));
135
136 0 html5_dom_tree_t *tree = (html5_dom_tree_t *) node->tree->context;
137 0 SvREFCNT_inc(tree->sv);
138
139 0 return node_ref;
140 } else {
141 0 SV *node_ref = newRV(sv);
142 DOM_GC_TRACE("DOM::Node::NEW (reuse refcnt=%d)", SvREFCNT(sv));
143 0 return node_ref;
144 }
145 }
146  
147 0 static SV *collection_to_blessed_array(myhtml_collection_t *collection) {
148 0 AV *arr = newAV();
149 0 ▶ if (collection) {
Branch: 1 branch
BranchTrueFalseTotal
if (collection) { 0 0 0
150 0 ▶ for (int i = 0; i < collection->length; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (int i = 0; i < collection->length; ++i) 0 0 0
151 0 av_push(arr, node_to_sv(collection->list[i]));
152 }
153 0 return sv_bless(newRV_noinc((SV *) arr), gv_stashpv("HTML5::DOM::Collection", 0));
154 }
155  
156 0 static SV *sv_stringify(SV *sv) {
157 0 ▶ if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sv)) { 0 0 0
158 0 SV *tmp_sv = SvRV(sv);
159 0 ▶ if (SvOBJECT(tmp_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOBJECT(tmp_sv)) { 0 0 0
160 0 HV *stash = SvSTASH(tmp_sv);
161 0 GV *to_string = gv_fetchmethod_autoload(stash, "\x28\x22\x22", 0);
162
163 0 ▶ if (to_string) {
Branch: 1 branch
BranchTrueFalseTotal
if (to_string) { 0 0 0
164 0 dSP;
165 0 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 0 0
166 0 ▶ XPUSHs(sv_bless(sv_2mortal(newRV_inc(tmp_sv)), stash));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_bless(sv_2mortal(newRV_inc(tmp_sv)), stash)); 0 0 0
167 0 PUTBACK;
168 0 call_sv((SV *) GvCV(to_string), G_SCALAR);
169 0 SPAGAIN;
170
171 0 SV *new_sv = POPs;
172
173 0 PUTBACK;
174 0 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 0 0 0
175
176 0 return new_sv;
177 }
178 }
179 }
180 0 return sv;
181 }
182  
183 0 static SV *html5_node_find(CV *cv, html5_dom_parser_t *parser, myhtml_tree_node_t *scope, SV *query, SV *combinator, bool one) {
184 mystatus_t status;
185 0 mycss_selectors_entries_list_t *list = NULL;
186 0 size_t list_size = 0;
187 0 mycss_selectors_list_t *selector = NULL;
188 0 modest_finder_selector_combinator_f selector_func = modest_finder_node_combinator_descendant;
189 0 SV *result = &PL_sv_undef;
190
191 // Custom combinator as args
192 0 ▶ if (combinator) {
Branch: 1 branch
BranchTrueFalseTotal
if (combinator) { 0 0 0
193 0 query = sv_stringify(query);
194
195 STRLEN combo_len;
196 0 const char *combo = SvPV_const(combinator, combo_len);
197
198 0 ▶ if (combo_len > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (combo_len > 0) 0 0 0
199 0 selector_func = html5_find_selector_func(combo, combo_len);
200 }
201
202 0 ▶ if (SvROK(query)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(query)) { 0 0 0
203 0 ▶ if (sv_derived_from(query, "HTML5::DOM::CSS::Selector")) { // Precompiler selectors
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(query, "HTML5::DOM::CSS::Selector")) { // Precompiler selectors 0 0 0
204 0 html5_css_selector_t *selector = INT2PTR(html5_css_selector_t *, SvIV((SV*)SvRV(query)));
205 0 list = selector->list->entries_list;
206 0 list_size = selector->list->entries_list_length;
207 0 ▶ } else if (sv_derived_from(query, "HTML5::DOM::CSS::Selector::Entry")) { // One precompiled selector
Branch: 1 branch
BranchTrueFalseTotal
} else if (sv_derived_from(query, "HTML5::DOM::CSS::Selector::Entry")) { // One precompiled selector 0 0 0
208 0 html5_css_selector_entry_t *selector = INT2PTR(html5_css_selector_entry_t *, SvIV((SV*)SvRV(query)));
209 0 list = selector->list;
210 0 list_size = 1;
211 } else {
212 0 ▶ sub_croak(cv, "%s: %s is not of type %s or %s", "HTML5::DOM::Tree::find", "query", "HTML5::DOM::CSS::Selector", "HTML5::DOM::CSS::Selector::Entry");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "%s: %s is not of type %s or %s", "HTML5::DOM::Tree::find", "query", "HTML5::DOM::CSS::Selector", "HTML5::DOM::CSS::Selector::Entry"); 0 0 0
sub_croak(cv, "%s: %s is not of type %s or %s", "HTML5::DOM::Tree::find", "query", "HTML5::DOM::CSS::Selector", "HTML5::DOM::CSS::Selector::Entry"); 0 0 0
sub_croak(cv, "%s: %s is not of type %s or %s", "HTML5::DOM::Tree::find", "query", "HTML5::DOM::CSS::Selector", "HTML5::DOM::CSS::Selector::Entry"); 0 0 0
sub_croak(cv, "%s: %s is not of type %s or %s", "HTML5::DOM::Tree::find", "query", "HTML5::DOM::CSS::Selector", "HTML5::DOM::CSS::Selector::Entry"); 0 0 0
sub_croak(cv, "%s: %s is not of type %s or %s", "HTML5::DOM::Tree::find", "query", "HTML5::DOM::CSS::Selector", "HTML5::DOM::CSS::Selector::Entry"); 0 0 0
sub_croak(cv, "%s: %s is not of type %s or %s", "HTML5::DOM::Tree::find", "query", "HTML5::DOM::CSS::Selector", "HTML5::DOM::CSS::Selector::Entry"); 0 0 0
sub_croak(cv, "%s: %s is not of type %s or %s", "HTML5::DOM::Tree::find", "query", "HTML5::DOM::CSS::Selector", "HTML5::DOM::CSS::Selector::Entry"); 0 0 0
sub_croak(cv, "%s: %s is not of type %s or %s", "HTML5::DOM::Tree::find", "query", "HTML5::DOM::CSS::Selector", "HTML5::DOM::CSS::Selector::Entry"); 0 0 0
sub_croak(cv, "%s: %s is not of type %s or %s", "HTML5::DOM::Tree::find", "query", "HTML5::DOM::CSS::Selector", "HTML5::DOM::CSS::Selector::Entry"); 0 0 0
sub_croak(cv, "%s: %s is not of type %s or %s", "HTML5::DOM::Tree::find", "query", "HTML5::DOM::CSS::Selector", "HTML5::DOM::CSS::Selector::Entry"); 0 0 0
sub_croak(cv, "%s: %s is not of type %s or %s", "HTML5::DOM::Tree::find", "query", "HTML5::DOM::CSS::Selector", "HTML5::DOM::CSS::Selector::Entry"); 0 0 0
213 }
214 } else {
215 // String selector, compile it
216 0 query = sv_stringify(query);
217
218 STRLEN query_len;
219 0 const char *query_str = SvPV_const(query, query_len);
220
221 0 status = html5_dom_init_css(parser);
222 0 ▶ if (status)
Branch: 1 branch
BranchTrueFalseTotal
if (status) 0 0 0
223 0 ▶ sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
224
225 0 selector = html5_parse_selector(parser->mycss_entry, query_str, query_len, &status);
226
227 0 ▶ if (!selector)
Branch: 1 branch
BranchTrueFalseTotal
if (!selector) 0 0 0
228 0 ▶ sub_croak(cv, "bad selector: %s", query_str);
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "bad selector: %s", query_str); 0 0 0
sub_croak(cv, "bad selector: %s", query_str); 0 0 0
sub_croak(cv, "bad selector: %s", query_str); 0 0 0
sub_croak(cv, "bad selector: %s", query_str); 0 0 0
sub_croak(cv, "bad selector: %s", query_str); 0 0 0
sub_croak(cv, "bad selector: %s", query_str); 0 0 0
sub_croak(cv, "bad selector: %s", query_str); 0 0 0
sub_croak(cv, "bad selector: %s", query_str); 0 0 0
sub_croak(cv, "bad selector: %s", query_str); 0 0 0
sub_croak(cv, "bad selector: %s", query_str); 0 0 0
sub_croak(cv, "bad selector: %s", query_str); 0 0 0
229
230 0 list = selector->entries_list;
231 0 list_size = selector->entries_list_length;
232 }
233
234 0 ▶ if (one) { // search one element
Branch: 1 branch
BranchTrueFalseTotal
if (one) { // search one element 0 0 0
235 0 myhtml_tree_node_t *node = (myhtml_tree_node_t *) html5_node_finder(parser, selector_func, scope, list, list_size, &status, 1);
236 0 result = node_to_sv(node);
237 } else { // search multiple elements
238 0 myhtml_collection_t *collection = (myhtml_collection_t *) html5_node_finder(parser, selector_func, scope, list, list_size, &status, 0);
239 0 result = collection_to_blessed_array(collection);
240 0 ▶ if (collection)
Branch: 1 branch
BranchTrueFalseTotal
if (collection) 0 0 0
241 0 myhtml_collection_destroy(collection);
242 }
243
244 // destroy parsed selector
245 0 ▶ if (selector)
Branch: 1 branch
BranchTrueFalseTotal
if (selector) 0 0 0
246 0 mycss_selectors_list_destroy(mycss_entry_selectors(parser->mycss_entry), selector, true);
247
248 0 return result;
249 }
250  
251 0 static SV *html5_node_simple_find(CV *cv, myhtml_tree_node_t *self, SV *key, SV *val, SV *cmp, bool icase, int ix) {
252 0 ▶ if (!self)
Branch: 1 branch
BranchTrueFalseTotal
if (!self) 0 0 0
253 0 return collection_to_blessed_array(NULL);
254
255 0 SV *result = &PL_sv_undef;
256 0 key = sv_stringify(key);
257
258 STRLEN key_len;
259 0 const char *key_str = SvPV_const(key, key_len);
260
261 0 myhtml_collection_t *collection = NULL;
262 0 switch (ix) {
263 0 case 0: case 1: // tag name
264 0 collection = myhtml_get_nodes_by_name_in_scope(self->tree, NULL, self, key_str, key_len, NULL);
265 0 result = collection_to_blessed_array(collection);
266 0 break;
267 0 case 2: case 3: // class
268 0 collection = myhtml_get_nodes_by_attribute_value_whitespace_separated(self->tree, NULL, self, false, "class", 5, key_str, key_len, NULL);
269 0 result = collection_to_blessed_array(collection);
270 0 break;
271 0 case 4: case 5: // id (first)
272 0 collection = myhtml_get_nodes_by_attribute_value(self->tree, NULL, self, false, "id", 2, key_str, key_len, NULL);
273 0 ▶ if (collection && collection->length)
Branch: 2 branches
BranchTrueFalseTotal
if (collection && collection->length) 0 0 0
if (collection && collection->length) 0 0 0
274 0 result = node_to_sv(collection->list[0]);
275 0 break;
276 0 case 6: case 7: // attribute
277 0 ▶ if (val) {
Branch: 1 branch
BranchTrueFalseTotal
if (val) { 0 0 0
278 STRLEN val_len;
279 0 const char *val_str = SvPV_const(val, val_len);
280
281 0 char cmp_type = '=';
282 0 ▶ if (cmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (cmp) { 0 0 0
283 0 cmp = sv_stringify(cmp);
284 STRLEN cmp_len;
285 0 const char *cmp_str = SvPV_const(cmp, cmp_len);
286
287 0 ▶ if (cmp_len)
Branch: 1 branch
BranchTrueFalseTotal
if (cmp_len) 0 0 0
288 0 cmp_type = cmp_str[0];
289 }
290
291 0 ▶ if (cmp_type == '=') {
Branch: 1 branch
BranchTrueFalseTotal
if (cmp_type == '=') { 0 0 0
292 // [key=val]
293 0 collection = myhtml_get_nodes_by_attribute_value(self->tree, NULL, self, icase, key_str, key_len, val_str, val_len, NULL);
294 0 ▶ } else if (cmp_type == '~') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (cmp_type == '~') { 0 0 0
295 // [key~=val]
296 0 collection = myhtml_get_nodes_by_attribute_value_whitespace_separated(self->tree, NULL, self, icase, key_str, key_len, val_str, val_len, NULL);
297 0 ▶ } else if (cmp_type == '^') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (cmp_type == '^') { 0 0 0
298 // [key^=val]
299 0 collection = myhtml_get_nodes_by_attribute_value_begin(self->tree, NULL, self, icase, key_str, key_len, val_str, val_len, NULL);
300 0 ▶ } else if (cmp_type == '$') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (cmp_type == '$') { 0 0 0
301 // [key$=val]
302 0 collection = myhtml_get_nodes_by_attribute_value_end(self->tree, NULL, self, icase, key_str, key_len, val_str, val_len, NULL);
303 0 ▶ } else if (cmp_type == '*') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (cmp_type == '*') { 0 0 0
304 // [key*=val]
305 0 collection = myhtml_get_nodes_by_attribute_value_contain(self->tree, NULL, self, icase, key_str, key_len, val_str, val_len, NULL);
306 0 ▶ } else if (cmp_type == '|') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (cmp_type == '|') { 0 0 0
307 // [key|=val]
308 0 collection = myhtml_get_nodes_by_attribute_value_hyphen_separated(self->tree, NULL, self, icase, key_str, key_len, val_str, val_len, NULL);
309 } else {
310 0 ▶ sub_croak(cv, "unknown cmp type: %c", cmp_type);
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "unknown cmp type: %c", cmp_type); 0 0 0
sub_croak(cv, "unknown cmp type: %c", cmp_type); 0 0 0
sub_croak(cv, "unknown cmp type: %c", cmp_type); 0 0 0
sub_croak(cv, "unknown cmp type: %c", cmp_type); 0 0 0
sub_croak(cv, "unknown cmp type: %c", cmp_type); 0 0 0
sub_croak(cv, "unknown cmp type: %c", cmp_type); 0 0 0
sub_croak(cv, "unknown cmp type: %c", cmp_type); 0 0 0
sub_croak(cv, "unknown cmp type: %c", cmp_type); 0 0 0
sub_croak(cv, "unknown cmp type: %c", cmp_type); 0 0 0
sub_croak(cv, "unknown cmp type: %c", cmp_type); 0 0 0
sub_croak(cv, "unknown cmp type: %c", cmp_type); 0 0 0
311 }
312 } else {
313 // [key]
314 0 collection = myhtml_get_nodes_by_attribute_key(self->tree, NULL, self, key_str, key_len, NULL);
315 }
316 0 result = collection_to_blessed_array(collection);
317 0 break;
318 }
319
320 0 ▶ if (collection)
Branch: 1 branch
BranchTrueFalseTotal
if (collection) 0 0 0
321 0 myhtml_collection_destroy(collection);
322
323 0 return result;
324 }
325  
326 0 static long hv_get_int_value(HV *hv, const char *key, int length, long def) {
327 0 ▶ if (hv) {
Branch: 1 branch
BranchTrueFalseTotal
if (hv) { 0 0 0
328 0 SV **sv = hv_fetch(hv, key, length, 0);
329 0 ▶ if (sv && *sv)
Branch: 2 branches
BranchTrueFalseTotal
if (sv && *sv) 0 0 0
if (sv && *sv) 0 0 0
330 0 return SvIV(*sv);
331 }
332 0 return def;
333 }
334  
335 0 static myencoding_t hv_get_encoding_value(HV *hv, const char *key, int length, myencoding_t def) {
336 0 ▶ if (hv) {
Branch: 1 branch
BranchTrueFalseTotal
if (hv) { 0 0 0
337 0 SV **sv = hv_fetch(hv, key, length, 0);
338 0 ▶ if (sv && *sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv && *sv) { 0 0 0
if (sv && *sv) { 0 0 0
339 0 SV *encoding = sv_stringify(*sv);
340
341 STRLEN enc_length;
342 0 const char *enc_str = SvPV_const(encoding, enc_length);
343
344 0 ▶ if (enc_length > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (enc_length > 0) { 0 0 0
345 myencoding_t enc_id;
346 0 ▶ if (isdigit(enc_str[0])) { // May be encoding id
Branch: 1 branch
BranchTrueFalseTotal
if (isdigit(enc_str[0])) { // May be encoding id 0 0 0
347 0 enc_id = SvIV(encoding);
348 0 ▶ if (enc_id == MyENCODING_AUTO || enc_id == MyENCODING_DEFAULT || enc_id == MyENCODING_NOT_DETERMINED)
Branch: 3 branches
BranchTrueFalseTotal
if (enc_id == MyENCODING_AUTO || enc_id == MyENCODING_DEFAULT || enc_id == MyENCODING_NOT_DETERMINED) 0 0 0
if (enc_id == MyENCODING_AUTO || enc_id == MyENCODING_DEFAULT || enc_id == MyENCODING_NOT_DETERMINED) 0 0 0
if (enc_id == MyENCODING_AUTO || enc_id == MyENCODING_DEFAULT || enc_id == MyENCODING_NOT_DETERMINED) 0 0 0
349 0 return enc_id;
350 0 ▶ if (!myencoding_name_by_id(enc_id, NULL))
Branch: 1 branch
BranchTrueFalseTotal
if (!myencoding_name_by_id(enc_id, NULL)) 0 0 0
351 0 return MyENCODING_NOT_DETERMINED;
352 } else { // May be encoding name
353 0 ▶ if (!myencoding_by_name(key, length, &enc_id)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!myencoding_by_name(key, length, &enc_id)) { 0 0 0
354 0 ▶ if (length == 4 && strcasecmp(key, "auto") == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (length == 4 && strcasecmp(key, "auto") == 0) 0 0 0
if (length == 4 && strcasecmp(key, "auto") == 0) 0 0 0
355 0 return MyENCODING_AUTO;
356 0 ▶ if (length == 7 && strcasecmp(key, "default") == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (length == 7 && strcasecmp(key, "default") == 0) 0 0 0
if (length == 7 && strcasecmp(key, "default") == 0) 0 0 0
357 0 return MyENCODING_DEFAULT;
358 0 return MyENCODING_NOT_DETERMINED;
359 }
360 }
361 0 return enc_id;
362 }
363 }
364 }
365 0 return def;
366 }
367  
368 0 static void html5_dom_parse_options(html5_dom_options_t *opts, html5_dom_options_t *extend, HV *options) {
369 0 ▶ opts->threads = hv_get_int_value(options, "threads", 7, extend ? extend->threads : 0);
Branch: 1 branch
BranchTrueFalseTotal
opts->threads = hv_get_int_value(options, "threads", 7, extend ? extend->threads : 0); 0 0 0
370 0 ▶ opts->ignore_whitespace = hv_get_int_value(options, "ignore_whitespace", 17, extend ? extend->ignore_whitespace : 0) > 0;
Branch: 1 branch
BranchTrueFalseTotal
opts->ignore_whitespace = hv_get_int_value(options, "ignore_whitespace", 17, extend ? extend->ignore_whitespace : 0) > 0; 0 0 0
371 0 ▶ opts->ignore_doctype = hv_get_int_value(options, "ignore_doctype", 14, extend ? extend->ignore_doctype : 0) > 0;
Branch: 1 branch
BranchTrueFalseTotal
opts->ignore_doctype = hv_get_int_value(options, "ignore_doctype", 14, extend ? extend->ignore_doctype : 0) > 0; 0 0 0
372 0 ▶ opts->scripts = hv_get_int_value(options, "scripts", 7, extend ? extend->scripts : 0) > 0;
Branch: 1 branch
BranchTrueFalseTotal
opts->scripts = hv_get_int_value(options, "scripts", 7, extend ? extend->scripts : 0) > 0; 0 0 0
373 0 ▶ opts->encoding = hv_get_encoding_value(options, "encoding", 8, extend ? extend->encoding : MyENCODING_AUTO);
Branch: 1 branch
BranchTrueFalseTotal
opts->encoding = hv_get_encoding_value(options, "encoding", 8, extend ? extend->encoding : MyENCODING_AUTO); 0 0 0
374 0 ▶ opts->default_encoding = hv_get_encoding_value(options, "default_encoding", 16, extend ? extend->default_encoding : MyENCODING_DEFAULT);
Branch: 1 branch
BranchTrueFalseTotal
opts->default_encoding = hv_get_encoding_value(options, "default_encoding", 16, extend ? extend->default_encoding : MyENCODING_DEFAULT); 0 0 0
375 0 ▶ opts->encoding_use_meta = hv_get_int_value(options, "encoding_use_meta", 17, extend ? extend->encoding_use_meta : 1) > 0;
Branch: 1 branch
BranchTrueFalseTotal
opts->encoding_use_meta = hv_get_int_value(options, "encoding_use_meta", 17, extend ? extend->encoding_use_meta : 1) > 0; 0 0 0
376 0 ▶ opts->encoding_use_bom = hv_get_int_value(options, "encoding_use_bom", 16, extend ? extend->encoding_use_bom : 1) > 0;
Branch: 1 branch
BranchTrueFalseTotal
opts->encoding_use_bom = hv_get_int_value(options, "encoding_use_bom", 16, extend ? extend->encoding_use_bom : 1) > 0; 0 0 0
377 0 ▶ opts->encoding_prescan_limit = hv_get_int_value(options, "encoding_prescan_limit", 22, extend ? extend->encoding_prescan_limit : 1024);
Branch: 1 branch
BranchTrueFalseTotal
opts->encoding_prescan_limit = hv_get_int_value(options, "encoding_prescan_limit", 22, extend ? extend->encoding_prescan_limit : 1024); 0 0 0
378
379 #ifdef MyCORE_BUILD_WITHOUT_THREADS
380 opts->threads = 0;
381 #endif
382 0 }
383  
384 0 static void html5_dom_check_options(CV *cv, html5_dom_options_t *opts) {
385 0 ▶ if (opts->encoding == MyENCODING_NOT_DETERMINED)
Branch: 1 branch
BranchTrueFalseTotal
if (opts->encoding == MyENCODING_NOT_DETERMINED) 0 0 0
386 0 ▶ sub_croak(cv, "invalid encoding value");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "invalid encoding value"); 0 0 0
sub_croak(cv, "invalid encoding value"); 0 0 0
sub_croak(cv, "invalid encoding value"); 0 0 0
sub_croak(cv, "invalid encoding value"); 0 0 0
sub_croak(cv, "invalid encoding value"); 0 0 0
sub_croak(cv, "invalid encoding value"); 0 0 0
sub_croak(cv, "invalid encoding value"); 0 0 0
sub_croak(cv, "invalid encoding value"); 0 0 0
sub_croak(cv, "invalid encoding value"); 0 0 0
sub_croak(cv, "invalid encoding value"); 0 0 0
sub_croak(cv, "invalid encoding value"); 0 0 0
387 0 ▶ if (opts->default_encoding == MyENCODING_NOT_DETERMINED || opts->default_encoding == MyENCODING_AUTO)
Branch: 2 branches
BranchTrueFalseTotal
if (opts->default_encoding == MyENCODING_NOT_DETERMINED || opts->default_encoding == MyENCODING_AUTO) 0 0 0
if (opts->default_encoding == MyENCODING_NOT_DETERMINED || opts->default_encoding == MyENCODING_AUTO) 0 0 0
388 0 ▶ sub_croak(cv, "invalid default_encoding value");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "invalid default_encoding value"); 0 0 0
sub_croak(cv, "invalid default_encoding value"); 0 0 0
sub_croak(cv, "invalid default_encoding value"); 0 0 0
sub_croak(cv, "invalid default_encoding value"); 0 0 0
sub_croak(cv, "invalid default_encoding value"); 0 0 0
sub_croak(cv, "invalid default_encoding value"); 0 0 0
sub_croak(cv, "invalid default_encoding value"); 0 0 0
sub_croak(cv, "invalid default_encoding value"); 0 0 0
sub_croak(cv, "invalid default_encoding value"); 0 0 0
sub_croak(cv, "invalid default_encoding value"); 0 0 0
sub_croak(cv, "invalid default_encoding value"); 0 0 0
389 0 ▶ if (opts->threads < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (opts->threads < 0) 0 0 0
390 0 ▶ sub_croak(cv, "invalid threads count");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "invalid threads count"); 0 0 0
sub_croak(cv, "invalid threads count"); 0 0 0
sub_croak(cv, "invalid threads count"); 0 0 0
sub_croak(cv, "invalid threads count"); 0 0 0
sub_croak(cv, "invalid threads count"); 0 0 0
sub_croak(cv, "invalid threads count"); 0 0 0
sub_croak(cv, "invalid threads count"); 0 0 0
sub_croak(cv, "invalid threads count"); 0 0 0
sub_croak(cv, "invalid threads count"); 0 0 0
sub_croak(cv, "invalid threads count"); 0 0 0
sub_croak(cv, "invalid threads count"); 0 0 0
391 0 ▶ if (opts->encoding_prescan_limit < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (opts->encoding_prescan_limit < 0) 0 0 0
392 0 ▶ sub_croak(cv, "invalid encoding_prescan_limit value");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "invalid encoding_prescan_limit value"); 0 0 0
sub_croak(cv, "invalid encoding_prescan_limit value"); 0 0 0
sub_croak(cv, "invalid encoding_prescan_limit value"); 0 0 0
sub_croak(cv, "invalid encoding_prescan_limit value"); 0 0 0
sub_croak(cv, "invalid encoding_prescan_limit value"); 0 0 0
sub_croak(cv, "invalid encoding_prescan_limit value"); 0 0 0
sub_croak(cv, "invalid encoding_prescan_limit value"); 0 0 0
sub_croak(cv, "invalid encoding_prescan_limit value"); 0 0 0
sub_croak(cv, "invalid encoding_prescan_limit value"); 0 0 0
sub_croak(cv, "invalid encoding_prescan_limit value"); 0 0 0
sub_croak(cv, "invalid encoding_prescan_limit value"); 0 0 0
393 0 }
394  
395 // selectors to AST serialization
396 static void html5_dom_css_serialize_entry(mycss_selectors_list_t *selector, mycss_selectors_entry_t *entry, AV *result);
397  
398 0 static void html5_dom_css_serialize_selector(mycss_selectors_list_t *selector, AV *result) {
399 0 ▶ while (selector) {
Branch: 1 branch
BranchTrueFalseTotal
while (selector) { 0 0 0
400 0 ▶ for (size_t i = 0; i < selector->entries_list_length; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (size_t i = 0; i < selector->entries_list_length; ++i) { 0 0 0
401 0 mycss_selectors_entries_list_t *entries = &selector->entries_list[i];
402 0 AV *chain = newAV();
403 0 html5_dom_css_serialize_entry(selector, entries->entry, chain);
404 0 av_push(result, newRV_noinc((SV *) chain));
405 }
406 0 selector = selector->next;
407 }
408 0 }
409  
410 0 static void html5_dom_css_serialize_entry(mycss_selectors_list_t *selector, mycss_selectors_entry_t *entry, AV *result) {
411 // combinators names
412 static const struct {
413 const char name[16];
414 size_t len;
415 } combinators[] = {
416 {"", 0},
417 {"descendant", 10}, // >>
418 {"child", 5}, // >
419 {"sibling", 7}, // +
420 {"adjacent", 8}, // ~
421 {"column", 6} // ||
422 };
423
424 // attribute eq names
425 static const struct {
426 const char name[16];
427 size_t len;
428 } attr_match_names[] = {
429 {"equal", 5}, // =
430 {"include", 7}, // ~=
431 {"dash", 4}, // |=
432 {"prefix", 6}, // ^=
433 {"suffix", 6}, // $=
434 {"substring", 9} // *=
435 };
436
437 0 ▶ while (entry) {
Branch: 1 branch
BranchTrueFalseTotal
while (entry) { 0 0 0
438 0 ▶ if (entry->combinator != MyCSS_SELECTORS_COMBINATOR_UNDEF) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry->combinator != MyCSS_SELECTORS_COMBINATOR_UNDEF) { 0 0 0
439 0 HV *data = newHV();
440 0 hv_store_ent(data, sv_2mortal(newSVpv("type", 4)), newSVpv("combinator", 10), 0);
441 0 hv_store_ent(data, sv_2mortal(newSVpv("value", 5)), newSVpv(combinators[entry->combinator].name, combinators[entry->combinator].len), 0);
442 0 av_push(result, newRV_noinc((SV *) data));
443 }
444
445 0 HV *data = newHV();
446
447 0 ▶ if ((selector->flags) & MyCSS_SELECTORS_FLAGS_SELECTOR_BAD)
Branch: 1 branch
BranchTrueFalseTotal
if ((selector->flags) & MyCSS_SELECTORS_FLAGS_SELECTOR_BAD) 0 0 0
448 0 hv_store_ent(data, sv_2mortal(newSVpv("invalid", 7)), newSViv(1), 0);
449
450 0 switch (entry->type) {
451 0 case MyCSS_SELECTORS_TYPE_ID:
452 case MyCSS_SELECTORS_TYPE_CLASS:
453 case MyCSS_SELECTORS_TYPE_ELEMENT:
454 case MyCSS_SELECTORS_TYPE_PSEUDO_CLASS:
455 case MyCSS_SELECTORS_TYPE_PSEUDO_ELEMENT:
456 {
457 0 switch (entry->type) {
458 0 case MyCSS_SELECTORS_TYPE_ELEMENT:
459 0 hv_store_ent(data, sv_2mortal(newSVpv("type", 4)), newSVpv("tag", 3), 0);
460 0 break;
461 0 case MyCSS_SELECTORS_TYPE_ID:
462 0 hv_store_ent(data, sv_2mortal(newSVpv("type", 4)), newSVpv("id", 2), 0);
463 0 break;
464 0 case MyCSS_SELECTORS_TYPE_CLASS:
465 0 hv_store_ent(data, sv_2mortal(newSVpv("type", 4)), newSVpv("class", 5), 0);
466 0 break;
467 0 case MyCSS_SELECTORS_TYPE_PSEUDO_CLASS:
468 0 hv_store_ent(data, sv_2mortal(newSVpv("type", 4)), newSVpv("pseudo-class", 12), 0);
469 0 break;
470 0 case MyCSS_SELECTORS_TYPE_PSEUDO_ELEMENT:
471 0 hv_store_ent(data, sv_2mortal(newSVpv("type", 4)), newSVpv("pseudo-element", 14), 0);
472 0 break;
473 }
474
475 0 ▶ if (entry->key)
Branch: 1 branch
BranchTrueFalseTotal
if (entry->key) 0 0 0
476 0 ▶ hv_store_ent(data, sv_2mortal(newSVpv("value", 5)), newSVpv(entry->key->data ? entry->key->data : "", entry->key->length), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store_ent(data, sv_2mortal(newSVpv("value", 5)), newSVpv(entry->key->data ? entry->key->data : "", entry->key->length), 0); 0 0 0
477 }
478 0 break;
479 0 case MyCSS_SELECTORS_TYPE_ATTRIBUTE:
480 {
481 0 hv_store_ent(data, sv_2mortal(newSVpv("type", 4)), newSVpv("attribute", 9), 0);
482
483 /* key */
484 0 ▶ if (entry->key)
Branch: 1 branch
BranchTrueFalseTotal
if (entry->key) 0 0 0
485 0 ▶ hv_store_ent(data, sv_2mortal(newSVpv("name", 4)), newSVpv(entry->key->data ? entry->key->data : "", entry->key->length), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store_ent(data, sv_2mortal(newSVpv("name", 4)), newSVpv(entry->key->data ? entry->key->data : "", entry->key->length), 0); 0 0 0
486
487 /* value */
488 0 ▶ if (mycss_selector_value_attribute(entry->value)->value) {
Branch: 1 branch
BranchTrueFalseTotal
if (mycss_selector_value_attribute(entry->value)->value) { 0 0 0
489 0 mycore_string_t *str_value = mycss_selector_value_attribute(entry->value)->value;
490 0 ▶ hv_store_ent(data, sv_2mortal(newSVpv("value", 5)), newSVpv(str_value->data ? str_value->data : "", str_value->length), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store_ent(data, sv_2mortal(newSVpv("value", 5)), newSVpv(str_value->data ? str_value->data : "", str_value->length), 0); 0 0 0
491 } else {
492 0 hv_store_ent(data, sv_2mortal(newSVpv("value", 5)), newSVpv("", 0), 0);
493 }
494
495 /* match */
496 0 int match = mycss_selector_value_attribute(entry->value)->match;
497 0 hv_store_ent(data, sv_2mortal(newSVpv("match", 5)), newSVpv(attr_match_names[match].name, attr_match_names[match].len), 0);
498
499 /* modificator */
500 0 ▶ if (mycss_selector_value_attribute(entry->value)->mod & MyCSS_SELECTORS_MOD_I) {
Branch: 1 branch
BranchTrueFalseTotal
if (mycss_selector_value_attribute(entry->value)->mod & MyCSS_SELECTORS_MOD_I) { 0 0 0
501 0 hv_store_ent(data, sv_2mortal(newSVpv("ignoreCase", 10)), newSViv(1), 0);
502 } else {
503 0 hv_store_ent(data, sv_2mortal(newSVpv("ignoreCase", 10)), newSViv(0), 0);
504 }
505 }
506 0 break;
507 0 case MyCSS_SELECTORS_TYPE_PSEUDO_CLASS_FUNCTION:
508 {
509 0 hv_store_ent(data, sv_2mortal(newSVpv("type", 4)), newSVpv("function", 8), 0);
510
511 0 switch (entry->sub_type) {
512 0 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CONTAINS:
513 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_HAS:
514 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NOT:
515 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_MATCHES:
516 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CURRENT:
517 {
518 0 switch (entry->sub_type) {
519 0 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CONTAINS:
520 0 hv_store_ent(data, sv_2mortal(newSVpv("name", 4)), newSVpv("contains", 8), 0);
521 0 break;
522 0 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_HAS:
523 0 hv_store_ent(data, sv_2mortal(newSVpv("name", 4)), newSVpv("has", 3), 0);
524 0 break;
525 0 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NOT:
526 0 hv_store_ent(data, sv_2mortal(newSVpv("name", 4)), newSVpv("not", 3), 0);
527 0 break;
528 0 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_MATCHES:
529 0 hv_store_ent(data, sv_2mortal(newSVpv("name", 4)), newSVpv("matches", 7), 0);
530 0 break;
531 0 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CURRENT:
532 0 hv_store_ent(data, sv_2mortal(newSVpv("name", 4)), newSVpv("current", 7), 0);
533 0 break;
534 }
535
536 0 AV *value = newAV();
537 0 html5_dom_css_serialize_selector(entry->value, value);
538 0 hv_store_ent(data, sv_2mortal(newSVpv("value", 5)), newRV_noinc((SV *) value), 0);
539 }
540 0 break;
541
542 0 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_CHILD:
543 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_LAST_CHILD:
544 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_COLUMN:
545 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_LAST_COLUMN:
546 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_OF_TYPE:
547 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_LAST_OF_TYPE:
548 {
549 0 mycss_an_plus_b_entry_t *a_plus_b = mycss_selector_value_an_plus_b(entry->value);
550 0 hv_store_ent(data, sv_2mortal(newSVpv("name", 4)), newSVpv("nth-child", 9), 0);
551 0 hv_store_ent(data, sv_2mortal(newSVpv("a", 1)), newSViv(a_plus_b->a), 0);
552 0 hv_store_ent(data, sv_2mortal(newSVpv("b", 1)), newSViv(a_plus_b->b), 0);
553
554 0 ▶ if (a_plus_b->of) {
Branch: 1 branch
BranchTrueFalseTotal
if (a_plus_b->of) { 0 0 0
555 0 AV *of = newAV();
556 0 html5_dom_css_serialize_selector(a_plus_b->of, of);
557 0 hv_store_ent(data, sv_2mortal(newSVpv("of", 2)), newRV_noinc((SV *) of), 0);
558 }
559 }
560 0 break;
561
562 0 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_DIR:
563 {
564 0 hv_store_ent(data, sv_2mortal(newSVpv("name", 4)), newSVpv("dir", 3), 0);
565 0 ▶ if (entry->value) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry->value) { 0 0 0
566 0 mycore_string_t *str_fname = mycss_selector_value_string(entry->value);
567 0 ▶ hv_store_ent(data, sv_2mortal(newSVpv("value", 5)), newSVpv(str_fname->data ? str_fname->data : "", str_fname->length), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store_ent(data, sv_2mortal(newSVpv("value", 5)), newSVpv(str_fname->data ? str_fname->data : "", str_fname->length), 0); 0 0 0
568 } else {
569 0 hv_store_ent(data, sv_2mortal(newSVpv("value", 5)), newSVpv("", 0), 0);
570 }
571 }
572 0 break;
573
574 0 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_DROP:
575 {
576 0 hv_store_ent(data, sv_2mortal(newSVpv("name", 4)), newSVpv("drop", 4), 0);
577 0 mycss_selectors_function_drop_type_t drop_val = mycss_selector_value_drop(entry->value);
578
579 0 AV *langs = newAV();
580 0 ▶ if (drop_val & MyCSS_SELECTORS_FUNCTION_DROP_TYPE_ACTIVE)
Branch: 1 branch
BranchTrueFalseTotal
if (drop_val & MyCSS_SELECTORS_FUNCTION_DROP_TYPE_ACTIVE) 0 0 0
581 0 av_push(langs, newSVpv("active", 6));
582 0 ▶ if (drop_val & MyCSS_SELECTORS_FUNCTION_DROP_TYPE_VALID)
Branch: 1 branch
BranchTrueFalseTotal
if (drop_val & MyCSS_SELECTORS_FUNCTION_DROP_TYPE_VALID) 0 0 0
583 0 av_push(langs, newSVpv("valid", 5));
584 0 ▶ if (drop_val & MyCSS_SELECTORS_FUNCTION_DROP_TYPE_INVALID)
Branch: 1 branch
BranchTrueFalseTotal
if (drop_val & MyCSS_SELECTORS_FUNCTION_DROP_TYPE_INVALID) 0 0 0
585 0 av_push(langs, newSVpv("invalid", 7));
586 0 hv_store_ent(data, sv_2mortal(newSVpv("value", 5)), newRV_noinc((SV *) langs), 0);
587 }
588 0 break;
589
590 0 case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_LANG:
591 {
592 0 hv_store_ent(data, sv_2mortal(newSVpv("name", 4)), newSVpv("lang", 4), 0);
593 0 AV *langs = newAV();
594 0 ▶ if (entry->value) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry->value) { 0 0 0
595 0 mycss_selectors_value_lang_t *lang = mycss_selector_value_lang(entry->value);
596 0 ▶ while (lang) {
Branch: 1 branch
BranchTrueFalseTotal
while (lang) { 0 0 0
597 0 ▶ av_push(langs, newSVpv(lang->str.data ? lang->str.data : "", lang->str.length));
Branch: 1 branch
BranchTrueFalseTotal
av_push(langs, newSVpv(lang->str.data ? lang->str.data : "", lang->str.length)); 0 0 0
598 0 lang = lang->next;
599 }
600 }
601 0 hv_store_ent(data, sv_2mortal(newSVpv("value", 5)), newRV_noinc((SV *) langs), 0);
602 }
603 0 break;
604
605 0 default:
606 0 hv_store_ent(data, sv_2mortal(newSVpv("name", 4)), newSVpv("unknown", 7), 0);
607 0 break;
608 }
609 }
610 0 break;
611
612 0 default:
613 0 hv_store_ent(data, sv_2mortal(newSVpv("type", 4)), newSVpv("unknown", 7), 0);
614 0 break;
615 }
616
617 0 av_push(result, newRV_noinc((SV *) data));
618
619 0 entry = entry->next;
620 }
621 0 }
622  
623 0 static html5_dom_async_result *html5_dom_async_parse_init(CV *cv, html5_dom_parser_t *self, SV *html, HV *options, int ev_fd) {
624 0 html5_dom_async_result *result = (html5_dom_async_result *) safemalloc(sizeof(html5_dom_async_result));
625 0 memset(result, 0, sizeof(html5_dom_async_result));
626
627 0 result->fd = ev_fd;
628
629 // extends options
630 0 html5_dom_parse_options(&result->opts, &self->opts, options);
631 0 html5_dom_check_options(cv, &result->opts);
632
633 mystatus_t status;
634
635 STRLEN html_len;
636 0 const char *html_str = SvPV_const(html, html_len);
637
638 // copy html source
639 0 result->html = safemalloc(html_len);
640 0 result->length = html_len;
641 0 memcpy(result->html, html_str, html_len);
642
643 #ifndef MyCORE_BUILD_WITHOUT_THREADS
644 // create parsing thread
645 0 result->thread = mythread_create();
646 0 status = mythread_init(result->thread, MyTHREAD_TYPE_STREAM, 1, 0);
647
648 0 ▶ if (status) {
Branch: 1 branch
BranchTrueFalseTotal
if (status) { 0 0 0
649 0 mythread_destroy(result->thread, NULL, NULL, true);
650 0 safefree(result->html);
651 0 safefree(result);
652 0 ▶ sub_croak(cv, "mythread_init failed: %d (%s)", status, modest_strerror(status));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "mythread_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
653 0 return NULL;
654 }
655
656 0 result->thread->context = result;
657
658 0 status = myhread_entry_create(result->thread, html5_dom_mythread_function, html5_dom_async_parse_worker, MyTHREAD_OPT_STOP);
659 0 mythread_option_set(result->thread, MyTHREAD_OPT_QUIT);
660
661 0 ▶ if (status) {
Branch: 1 branch
BranchTrueFalseTotal
if (status) { 0 0 0
662 0 mythread_destroy(result->thread, NULL, NULL, true);
663 0 safefree(result->html);
664 0 safefree(result);
665 0 ▶ sub_croak(cv, "myhread_entry_create failed: %d (%s)", status, modest_strerror(status));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "myhread_entry_create failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhread_entry_create failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhread_entry_create failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhread_entry_create failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhread_entry_create failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhread_entry_create failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhread_entry_create failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhread_entry_create failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhread_entry_create failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhread_entry_create failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhread_entry_create failed: %d (%s)", status, modest_strerror(status)); 0 0 0
666 0 return NULL;
667 }
668
669 // start parsing thread
670 0 status = mythread_resume(result->thread, MyTHREAD_OPT_UNDEF);
671
672 0 ▶ if (status) {
Branch: 1 branch
BranchTrueFalseTotal
if (status) { 0 0 0
673 0 mythread_destroy(result->thread, NULL, NULL, true);
674 0 safefree(result->html);
675 0 safefree(result);
676 0 ▶ sub_croak(cv, "mythread_resume failed: %d (%s)", status, modest_strerror(status));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "mythread_resume failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_resume failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_resume failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_resume failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_resume failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_resume failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_resume failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_resume failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_resume failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_resume failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mythread_resume failed: %d (%s)", status, modest_strerror(status)); 0 0 0
677 0 return NULL;
678 }
679 #else
680 // sync fallback
681 html5_dom_async_parse(result);
682 #endif
683
684 0 return result;
685 }
686  
687 0 static SV *html5_dom_async_parse_done(CV *cv, html5_dom_async_result *result, bool wait) {
688 0 ▶ if (!wait && !result->done)
Branch: 2 branches
BranchTrueFalseTotal
if (!wait && !result->done) 0 0 0
if (!wait && !result->done) 0 0 0
689 0 return NULL;
690
691 #ifndef MyCORE_BUILD_WITHOUT_THREADS
692 0 ▶ if (result->thread)
Branch: 1 branch
BranchTrueFalseTotal
if (result->thread) 0 0 0
693 0 result->thread = mythread_destroy(result->thread, NULL, NULL, true);
694 #endif
695
696 0 ▶ if (result->html) {
Branch: 1 branch
BranchTrueFalseTotal
if (result->html) { 0 0 0
697 0 result->html = NULL;
698 0 safefree(result->html);
699 }
700
701 0 ▶ if (result->status) {
Branch: 1 branch
BranchTrueFalseTotal
if (result->status) { 0 0 0
702 0 ▶ sub_croak(cv, "parse failed: %d (%s)", result->status, modest_strerror(result->status));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "parse failed: %d (%s)", result->status, modest_strerror(result->status)); 0 0 0
sub_croak(cv, "parse failed: %d (%s)", result->status, modest_strerror(result->status)); 0 0 0
sub_croak(cv, "parse failed: %d (%s)", result->status, modest_strerror(result->status)); 0 0 0
sub_croak(cv, "parse failed: %d (%s)", result->status, modest_strerror(result->status)); 0 0 0
sub_croak(cv, "parse failed: %d (%s)", result->status, modest_strerror(result->status)); 0 0 0
sub_croak(cv, "parse failed: %d (%s)", result->status, modest_strerror(result->status)); 0 0 0
sub_croak(cv, "parse failed: %d (%s)", result->status, modest_strerror(result->status)); 0 0 0
sub_croak(cv, "parse failed: %d (%s)", result->status, modest_strerror(result->status)); 0 0 0
sub_croak(cv, "parse failed: %d (%s)", result->status, modest_strerror(result->status)); 0 0 0
sub_croak(cv, "parse failed: %d (%s)", result->status, modest_strerror(result->status)); 0 0 0
sub_croak(cv, "parse failed: %d (%s)", result->status, modest_strerror(result->status)); 0 0 0
703 0 return NULL;
704 }
705
706 0 ▶ if (result->tree) {
Branch: 1 branch
BranchTrueFalseTotal
if (result->tree) { 0 0 0
707 DOM_GC_TRACE("DOM::new");
708 0 SV *myhtml_sv = pack_pointer("HTML5::DOM", result->parser);
709 0 result->tree_sv = (void *) create_tree_object(result->tree, SvRV(myhtml_sv), result->parser);
710 0 result->tree = NULL;
711 0 SvREFCNT_dec(myhtml_sv);
712 }
713
714 0 ▶ return result->tree_sv ? SvREFCNT_inc((SV *) result->tree_sv) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
return result->tree_sv ? SvREFCNT_inc((SV *) result->tree_sv) : &PL_sv_undef; 0 0 0
715 }
716  
717 MODULE = HTML5::DOM PACKAGE = HTML5::DOM
718  
719 #################################################################
720 # HTML5::DOM (Parser)
721 #################################################################
722 HTML5::DOM
723 new(SV *CLASS, HV *options = NULL)
724 CODE:
725 DOM_GC_TRACE("DOM::new");
726 mystatus_t status;
727
728 0 html5_dom_options_t opts = {0};
729 0 html5_dom_parse_options(&opts, NULL, options);
730 0 html5_dom_check_options(cv, &opts);
731
732 0 html5_dom_parser_t *self = html5_dom_parser_new(&opts);
733
734 0 self->myhtml = myhtml_create();
735
736 0 ▶ if (self->opts.threads <= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (self->opts.threads <= 1) { 0 0 0
737 0 status = myhtml_init(self->myhtml, MyHTML_OPTIONS_PARSE_MODE_SINGLE, 1, 0);
738 } else {
739 0 status = myhtml_init(self->myhtml, MyHTML_OPTIONS_DEFAULT, self->opts.threads, 0);
740 }
741
742 0 ▶ if (status) {
Branch: 1 branch
BranchTrueFalseTotal
if (status) { 0 0 0
743 0 self = html5_dom_parser_free(self);
744 0 ▶ sub_croak(cv, "myhtml_init failed: %d (%s)", status, modest_strerror(status));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "myhtml_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
745 }
746
747 0 RETVAL = self;
748 OUTPUT:
749 RETVAL
750  
751 # Init html chunk parser
752 SV *
753 parseChunkStart(HTML5::DOM self, HV *options = NULL)
754 CODE:
755 mystatus_t status;
756
757 0 html5_dom_parse_options(&self->chunk_opts, &self->opts, options);
758 0 html5_dom_check_options(cv, &self->chunk_opts);
759
760 0 ▶ if (self->tree) {
Branch: 1 branch
BranchTrueFalseTotal
if (self->tree) { 0 0 0
761 0 myhtml_tree_destroy(self->tree);
762 0 self->tree = NULL;
763 }
764
765 0 self->tree = myhtml_tree_create();
766 0 status = myhtml_tree_init(self->tree, self->myhtml);
767 0 ▶ if (status) {
Branch: 1 branch
BranchTrueFalseTotal
if (status) { 0 0 0
768 0 myhtml_tree_destroy(self->tree);
769 0 ▶ sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
770 }
771
772 0 self->chunks = 0;
773 0 ▶ myhtml_encoding_set(self->tree, self->chunk_opts.encoding == MyENCODING_AUTO ? self->chunk_opts.default_encoding : self->chunk_opts.encoding);
Branch: 1 branch
BranchTrueFalseTotal
myhtml_encoding_set(self->tree, self->chunk_opts.encoding == MyENCODING_AUTO ? self->chunk_opts.default_encoding : self->chunk_opts.encoding); 0 0 0
774
775 0 RETVAL = SvREFCNT_inc(ST(0));
776 OUTPUT:
777 RETVAL
778  
779 # Parse html chunk
780 SV *
781 parseChunk(HTML5::DOM self, SV *html, HV *options = NULL)
782 CODE:
783 mystatus_t status;
784
785 0 html = sv_stringify(html);
786
787 0 ▶ if (!self->tree) {
Branch: 1 branch
BranchTrueFalseTotal
if (!self->tree) { 0 0 0
788 0 self->tree = myhtml_tree_create();
789 0 status = myhtml_tree_init(self->tree, self->myhtml);
790 0 ▶ if (status) {
Branch: 1 branch
BranchTrueFalseTotal
if (status) { 0 0 0
791 0 myhtml_tree_destroy(self->tree);
792 0 ▶ sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
793 }
794 0 memcpy(&self->opts, &self->chunk_opts, sizeof(html5_dom_options_t));
795 0 ▶ myhtml_encoding_set(self->tree, self->chunk_opts.encoding == MyENCODING_AUTO ? self->chunk_opts.default_encoding : self->chunk_opts.encoding);
Branch: 1 branch
BranchTrueFalseTotal
myhtml_encoding_set(self->tree, self->chunk_opts.encoding == MyENCODING_AUTO ? self->chunk_opts.default_encoding : self->chunk_opts.encoding); 0 0 0
796 0 self->chunks = 0;
797 }
798
799 STRLEN html_length;
800 0 const char *html_str = SvPV_const(html, html_length);
801
802 // Try detect encoding only in first chunk
803 0 ▶ if (!self->chunks) {
Branch: 1 branch
BranchTrueFalseTotal
if (!self->chunks) { 0 0 0
804 0 myhtml_encoding_set(self->tree, html5_dom_auto_encoding(&self->chunk_opts, &html_str, &html_length));
805 0 html5_dom_apply_tree_options(self->tree, &self->chunk_opts);
806 }
807
808 0 ++self->chunks;
809
810 0 status = myhtml_parse_chunk(self->tree, html_str, html_length);
811 0 ▶ if (status) {
Branch: 1 branch
BranchTrueFalseTotal
if (status) { 0 0 0
812 0 myhtml_tree_destroy(self->tree);
813 0 ▶ sub_croak(cv, "myhtml_parse_chunk failed: %d (%s)", status, modest_strerror(status));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "myhtml_parse_chunk failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed: %d (%s)", status, modest_strerror(status)); 0 0 0
814 }
815
816 0 RETVAL = SvREFCNT_inc(ST(0));
817 OUTPUT:
818 RETVAL
819  
820 # End of parse chunks (return Tree)
821 SV *
822 parseChunkEnd(HTML5::DOM self)
823 CODE:
824 mystatus_t status;
825
826 0 ▶ if (!self->tree)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->tree) 0 0 0
827 0 ▶ sub_croak(cv, "call parseChunk first");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "call parseChunk first"); 0 0 0
sub_croak(cv, "call parseChunk first"); 0 0 0
sub_croak(cv, "call parseChunk first"); 0 0 0
sub_croak(cv, "call parseChunk first"); 0 0 0
sub_croak(cv, "call parseChunk first"); 0 0 0
sub_croak(cv, "call parseChunk first"); 0 0 0
sub_croak(cv, "call parseChunk first"); 0 0 0
sub_croak(cv, "call parseChunk first"); 0 0 0
sub_croak(cv, "call parseChunk first"); 0 0 0
sub_croak(cv, "call parseChunk first"); 0 0 0
sub_croak(cv, "call parseChunk first"); 0 0 0
828
829 0 status = myhtml_parse_chunk_end(self->tree);
830 0 ▶ if (status) {
Branch: 1 branch
BranchTrueFalseTotal
if (status) { 0 0 0
831 0 myhtml_tree_destroy(self->tree);
832 0 ▶ sub_croak(cv, "myhtml_parse_chunk failed:%d (%s)", status, modest_strerror(status));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "myhtml_parse_chunk failed:%d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed:%d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed:%d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed:%d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed:%d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed:%d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed:%d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed:%d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed:%d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed:%d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_chunk failed:%d (%s)", status, modest_strerror(status)); 0 0 0
833 }
834
835 0 RETVAL = create_tree_object(self->tree, SvRV(ST(0)), self);
836 0 self->tree = NULL;
837 OUTPUT:
838 RETVAL
839  
840 # Parse full html
841 SV *
842 parse(HTML5::DOM self, SV *html, HV *options = NULL)
843 CODE:
844 mystatus_t status;
845 0 html5_dom_options_t opts = {0};
846
847 0 html5_dom_parse_options(&opts, &self->opts, options);
848 0 html5_dom_check_options(cv, &opts);
849
850 0 html = sv_stringify(html);
851
852 0 myhtml_tree_t *tree = myhtml_tree_create();
853 0 status = myhtml_tree_init(tree, self->myhtml);
854 0 ▶ if (status) {
Branch: 1 branch
BranchTrueFalseTotal
if (status) { 0 0 0
855 0 myhtml_tree_destroy(tree);
856 0 ▶ sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_tree_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
857 }
858
859 STRLEN html_length;
860 0 const char *html_str = SvPV_const(html, html_length);
861
862 0 myencoding_t encoding = html5_dom_auto_encoding(&opts, &html_str, &html_length);
863 0 html5_dom_apply_tree_options(tree, &opts);
864
865 0 status = myhtml_parse(tree, encoding, html_str, html_length);
866 0 ▶ if (status) {
Branch: 1 branch
BranchTrueFalseTotal
if (status) { 0 0 0
867 0 myhtml_tree_destroy(tree);
868 0 ▶ sub_croak(cv, "myhtml_parse failed: %d (%s)", status, modest_strerror(status));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "myhtml_parse failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse failed: %d (%s)", status, modest_strerror(status)); 0 0 0
869 }
870
871 0 RETVAL = create_tree_object(tree, SvRV(ST(0)), self);
872 OUTPUT:
873 RETVAL
874  
875 # Parse full html (in background)
876 HTML5::DOM::AsyncResult
877 _parseAsync(HTML5::DOM self, SV *html, HV *options = NULL, int ev_fd = -1)
878 CODE:
879 DOM_GC_TRACE("DOM::AsyncResult::new");
880 0 html = sv_stringify(html);
881 0 RETVAL = html5_dom_async_parse_init(cv, self, html, options, ev_fd);
882 OUTPUT:
883 RETVAL
884  
885 void
886 DESTROY(HTML5::DOM self)
887 CODE:
888 DOM_GC_TRACE("DOM::DESTROY (refs=%d)", SvREFCNT(SvRV(ST(0))));
889 0 html5_dom_parser_free(self);
890  
891  
892  
893 #################################################################
894 # HTML5::DOM::AsyncResult
895 #################################################################
896 MODULE = HTML5::DOM PACKAGE = HTML5::DOM::AsyncResult
897  
898 # Wait for parsing done and return HTML5::DOM::Tree
899 SV *
900 wait(HTML5::DOM::AsyncResult self)
901 CODE:
902 0 RETVAL = html5_dom_async_parse_done(cv, self, true);
903 OUTPUT:
904 RETVAL
905  
906 # True if parsing done
907 int
908 parsed(HTML5::DOM::AsyncResult self)
909 CODE:
910 0 ▶ RETVAL = self->done ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->done ? 1 : 0; 0 0 0
911 OUTPUT:
912 RETVAL
913  
914 # Return HTML5::DOM::Tree if parsing done
915 SV *
916 tree(HTML5::DOM::AsyncResult self)
917 CODE:
918 0 RETVAL = html5_dom_async_parse_done(cv, self, false);
919 OUTPUT:
920 RETVAL
921  
922 void
923 DESTROY(HTML5::DOM::AsyncResult self)
924 CODE:
925 DOM_GC_TRACE("DOM::AsyncResult::DESTROY (refs=%d)", SvREFCNT(SvRV(ST(0))));
926 0 ▶ if (self->thread)
Branch: 1 branch
BranchTrueFalseTotal
if (self->thread) 0 0 0
927 0 self->thread = mythread_destroy(self->thread, NULL, NULL, true);
928
929 0 ▶ if (self->tree) {
Branch: 1 branch
BranchTrueFalseTotal
if (self->tree) { 0 0 0
930 0 self->tree = myhtml_tree_destroy(self->tree);
931
932 0 ▶ if (self->parser)
Branch: 1 branch
BranchTrueFalseTotal
if (self->parser) 0 0 0
933 0 self->parser = html5_dom_parser_free(self->parser);
934 }
935
936 0 ▶ if (self->tree_sv)
Branch: 1 branch
BranchTrueFalseTotal
if (self->tree_sv) 0 0 0
937 0 SvREFCNT_dec((SV *) self->tree_sv);
938
939 0 ▶ if (self->html)
Branch: 1 branch
BranchTrueFalseTotal
if (self->html) 0 0 0
940 0 safefree(self->html);
941
942 0 safefree(self);
943  
944 #################################################################
945 # HTML5::DOM::Tree
946 #################################################################
947 MODULE = HTML5::DOM PACKAGE = HTML5::DOM::Tree
948  
949 SV *
950 body(HTML5::DOM::Tree self)
951 CODE:
952 0 RETVAL = node_to_sv(myhtml_tree_get_node_body(self->tree));
953 OUTPUT:
954 RETVAL
955  
956 SV *
957 createElement(HTML5::DOM::Tree self, SV *tag, SV *ns_name = NULL)
958 CODE:
959 // Get namespace id by name
960 0 myhtml_namespace_t ns = MyHTML_NAMESPACE_HTML;
961 0 ▶ if (ns_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (ns_name) { 0 0 0
962 0 ns_name = sv_stringify(ns_name);
963 STRLEN ns_name_len;
964 0 const char *ns_name_str = SvPV_const(ns_name, ns_name_len);
965 0 ▶ if (!myhtml_namespace_id_by_name(ns_name_str, ns_name_len, &ns))
Branch: 1 branch
BranchTrueFalseTotal
if (!myhtml_namespace_id_by_name(ns_name_str, ns_name_len, &ns)) 0 0 0
966 0 ▶ sub_croak(cv, "unknown namespace: %s", ns_name_str);
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "unknown namespace: %s", ns_name_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_name_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_name_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_name_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_name_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_name_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_name_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_name_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_name_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_name_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_name_str); 0 0 0
967 }
968
969 // Get tag id by name
970 0 tag = sv_stringify(tag);
971 STRLEN tag_len;
972 0 const char *tag_str = SvPV_const(tag, tag_len);
973 0 myhtml_tag_id_t tag_id = html5_dom_tag_id_by_name(self->tree, tag_str, tag_len, true);
974
975 // create new node
976 0 myhtml_tree_node_t *node = myhtml_node_create(self->tree, tag_id, ns);
977
978 // if void - mark self-closed
979 0 ▶ if (myhtml_node_is_void_element(node)) {
Branch: 1 branch
BranchTrueFalseTotal
if (myhtml_node_is_void_element(node)) { 0 0 0
980 0 ▶ if (!node->token) {
Branch: 1 branch
BranchTrueFalseTotal
if (!node->token) { 0 0 0
981 0 node->token = myhtml_token_node_create(node->tree->token, self->tree->mcasync_rules_token_id);
982 0 ▶ if (!node->token) {
Branch: 1 branch
BranchTrueFalseTotal
if (!node->token) { 0 0 0
983 0 myhtml_tree_node_delete(node);
984 0 ▶ sub_croak(cv, "myhtml_token_node_create failed");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
985 }
986 }
987 0 node->token->type |= MyHTML_TOKEN_TYPE_CLOSE_SELF | MyHTML_TOKEN_TYPE_DONE;
988 }
989
990 0 RETVAL = node_to_sv(node);
991 OUTPUT:
992 RETVAL
993  
994 SV *
995 createComment(HTML5::DOM::Tree self, SV *text)
996 CODE:
997 0 text = sv_stringify(text);
998 STRLEN text_len;
999 0 const char *text_str = SvPV_const(text, text_len);
1000 0 myhtml_tree_node_t *node = myhtml_node_create(self->tree, MyHTML_TAG__COMMENT, MyHTML_NAMESPACE_HTML);
1001 0 myhtml_node_text_set(node, text_str, text_len, MyENCODING_DEFAULT);
1002 0 RETVAL = node_to_sv(node);
1003 OUTPUT:
1004 RETVAL
1005  
1006 SV *
1007 createTextNode(HTML5::DOM::Tree self, SV *text)
1008 CODE:
1009 0 text = sv_stringify(text);
1010 STRLEN text_len;
1011 0 const char *text_str = SvPV_const(text, text_len);
1012 0 myhtml_tree_node_t *node = myhtml_node_create(self->tree, MyHTML_TAG__TEXT, MyHTML_NAMESPACE_HTML);
1013 0 myhtml_node_text_set(node, text_str, text_len, MyENCODING_DEFAULT);
1014 0 RETVAL = node_to_sv(node);
1015 OUTPUT:
1016 RETVAL
1017  
1018 # Parse fragment
1019 SV *parseFragment(HTML5::DOM::Tree self, SV *text, SV *tag = NULL, SV *ns = NULL, HV *options = NULL)
1020 CODE:
1021 0 text = sv_stringify(text);
1022 STRLEN text_len;
1023 0 const char *text_str = SvPV_const(text, text_len);
1024
1025 mystatus_t status;
1026 0 myhtml_namespace_t ns_id = MyHTML_NAMESPACE_HTML;
1027 0 myhtml_tag_id_t tag_id = MyHTML_TAG_DIV;
1028
1029 0 ▶ if (ns) {
Branch: 1 branch
BranchTrueFalseTotal
if (ns) { 0 0 0
1030 0 ns = sv_stringify(ns);
1031 STRLEN ns_len;
1032 0 const char *ns_str = SvPV_const(ns, ns_len);
1033
1034 0 ▶ if (!myhtml_namespace_id_by_name(ns_str, ns_len, &ns_id))
Branch: 1 branch
BranchTrueFalseTotal
if (!myhtml_namespace_id_by_name(ns_str, ns_len, &ns_id)) 0 0 0
1035 0 ▶ sub_croak(cv, "unknown namespace: %s", ns_str);
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "unknown namespace: %s", ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", ns_str); 0 0 0
1036 }
1037
1038 0 ▶ if (tag) {
Branch: 1 branch
BranchTrueFalseTotal
if (tag) { 0 0 0
1039 0 tag = sv_stringify(tag);
1040 STRLEN tag_len;
1041 0 const char *tag_str = SvPV_const(tag, tag_len);
1042 0 tag_id = html5_dom_tag_id_by_name(self->tree, tag_str, tag_len, true);
1043 }
1044
1045 0 html5_dom_options_t opts = {0};
1046 0 html5_dom_parse_options(&opts, &self->parser->opts, options);
1047 0 html5_dom_check_options(cv, &opts);
1048
1049 0 myhtml_tree_node_t *node = html5_dom_parse_fragment(&opts, self->tree, tag_id, ns_id, text_str, text_len, NULL, &status);
1050 0 ▶ if (status)
Branch: 1 branch
BranchTrueFalseTotal
if (status) 0 0 0
1051 0 ▶ sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
1052
1053 0 RETVAL = node_to_sv(node);
1054 OUTPUT:
1055 RETVAL
1056  
1057 SV *
1058 head(HTML5::DOM::Tree self)
1059 CODE:
1060 0 RETVAL = node_to_sv(myhtml_tree_get_node_head(self->tree));
1061 OUTPUT:
1062 RETVAL
1063  
1064 SV *
1065 root(HTML5::DOM::Tree self)
1066 CODE:
1067 0 RETVAL = node_to_sv(myhtml_tree_get_node_html(self->tree));
1068 OUTPUT:
1069 RETVAL
1070  
1071 SV *
1072 document(HTML5::DOM::Tree self)
1073 CODE:
1074 0 RETVAL = node_to_sv(myhtml_tree_get_document(self->tree));
1075 OUTPUT:
1076 RETVAL
1077  
1078 SV *
1079 find(HTML5::DOM::Tree self, SV *query, SV *combinator = NULL)
1080 ALIAS:
1081 at = 1
1082 querySelector = 2
1083 querySelectorAll = 3
1084 CODE:
1085 0 myhtml_tree_node_t *scope = myhtml_tree_get_document(self->tree);
1086 0 ▶ if (scope) {
Branch: 1 branch
BranchTrueFalseTotal
if (scope) { 0 0 0
1087 0 ▶ RETVAL = html5_node_find(cv, self->parser, scope, query, combinator, ix == 1 || ix == 2);
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = html5_node_find(cv, self->parser, scope, query, combinator, ix == 1 || ix == 2); 0 0 0
RETVAL = html5_node_find(cv, self->parser, scope, query, combinator, ix == 1 || ix == 2); 0 0 0
1088 } else {
1089 0 RETVAL = &PL_sv_undef;
1090 }
1091 OUTPUT:
1092 RETVAL
1093  
1094 # Wait for parsing done (when async mode) - removed
1095 SV *
1096 wait(HTML5::DOM::Tree self)
1097 CODE:
1098 0 RETVAL = SvREFCNT_inc(ST(0));
1099 OUTPUT:
1100 RETVAL
1101  
1102 # True if parsing done (when async mode) - removed
1103 int
1104 parsed(HTML5::DOM::Tree self)
1105 CODE:
1106 0 ▶ RETVAL = 1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 1; 0 0 0
1107 OUTPUT:
1108 RETVAL
1109  
1110 # findTag(val), getElementsByTagName(val) - get nodes by tag name
1111 # findClass(val), getElementsByClassName(val) - get nodes by class name
1112 # findId(val), getElementById(val) - get node by id
1113 # findAttr(key), getElementByAttribute(key) - get nodes by attribute key
1114 # findAttr(key, val, case, cmp), getElementByAttribute(key, val, case, cmp) - get nodes by attribute value
1115 SV *
1116 findTag(HTML5::DOM::Tree self, SV *key, SV *val = NULL, bool icase = false, SV *cmp = NULL)
1117 ALIAS:
1118 getElementsByTagName = 1
1119 findClass = 2
1120 getElementsByClassName = 3
1121 findId = 4
1122 getElementById = 5
1123 findAttr = 6
1124 getElementByAttribute = 7
1125 CODE:
1126 0 RETVAL = html5_node_simple_find(cv, myhtml_tree_get_document(self->tree), key, val, cmp, icase, ix);
1127 OUTPUT:
1128 RETVAL
1129  
1130 # Get compat node
1131 SV *
1132 compatMode(HTML5::DOM::Tree self)
1133 CODE:
1134 0 ▶ if (self->tree->compat_mode == MyHTML_TREE_COMPAT_MODE_QUIRKS) {
Branch: 1 branch
BranchTrueFalseTotal
if (self->tree->compat_mode == MyHTML_TREE_COMPAT_MODE_QUIRKS) { 0 0 0
1135 // if the document is in quirks mode.
1136 0 RETVAL = newSVpv("BackCompat", 10);
1137 } else {
1138 // if the document is in no-quirks (also known as "standards") mode or limited-quirks (also known as "almost standards") mode.
1139 0 RETVAL = newSVpv("CSS1Compat", 10);
1140 }
1141 OUTPUT:
1142 RETVAL
1143  
1144 # Get current tree encoding name
1145 SV *
1146 encoding(HTML5::DOM::Tree self)
1147 CODE:
1148 0 size_t length = 0;
1149 0 const char *name = myencoding_name_by_id(self->tree->encoding, &length);
1150 0 ▶ RETVAL = newSVpv(name ? name : "", length);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = newSVpv(name ? name : "", length); 0 0 0
1151 OUTPUT:
1152 RETVAL
1153  
1154 # Get current tree encoding id
1155 SV *
1156 encodingId(HTML5::DOM::Tree self)
1157 CODE:
1158 0 RETVAL = newSViv(self->tree->encoding);
1159 OUTPUT:
1160 RETVAL
1161  
1162 # Tag id by tag name
1163 SV *
1164 tag2id(HTML5::DOM::Tree self, SV *tag)
1165 CODE:
1166 0 tag = sv_stringify(tag);
1167 STRLEN tag_len;
1168 0 const char *tag_str = SvPV_const(tag, tag_len);
1169 0 RETVAL = newSViv(html5_dom_tag_id_by_name(self->tree, tag_str, tag_len, false));
1170 OUTPUT:
1171 RETVAL
1172  
1173 # Tag name by tag id
1174 SV *
1175 id2tag(HTML5::DOM::Tree self, int tag_id)
1176 CODE:
1177 0 RETVAL = &PL_sv_undef;
1178 0 const myhtml_tag_context_t *tag_ctx = myhtml_tag_get_by_id(self->tree->tags, tag_id);
1179 0 ▶ if (tag_ctx)
Branch: 1 branch
BranchTrueFalseTotal
if (tag_ctx) 0 0 0
1180 0 ▶ RETVAL = newSVpv(tag_ctx->name ? tag_ctx->name : "", tag_ctx->name_length);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = newSVpv(tag_ctx->name ? tag_ctx->name : "", tag_ctx->name_length); 0 0 0
1181 OUTPUT:
1182 RETVAL
1183  
1184 # Namespace id by namepsace name
1185 SV *
1186 namespace2id(HTML5::DOM::Tree self, SV *ns)
1187 CODE:
1188 0 ns = sv_stringify(ns);
1189 STRLEN ns_len;
1190 0 const char *ns_str = SvPV_const(ns, ns_len);
1191
1192 myhtml_namespace_t ns_id;
1193 0 ▶ if (!myhtml_namespace_id_by_name(ns_str, ns_len, &ns_id))
Branch: 1 branch
BranchTrueFalseTotal
if (!myhtml_namespace_id_by_name(ns_str, ns_len, &ns_id)) 0 0 0
1194 0 ns_id = MyHTML_NAMESPACE_UNDEF;
1195
1196 0 RETVAL = newSViv(ns_id);
1197 OUTPUT:
1198 RETVAL
1199  
1200 # Namespace name by namepsace id
1201 SV *
1202 id2namespace(HTML5::DOM::Tree self, int ns_id)
1203 CODE:
1204 0 size_t ns_len = 0;
1205 0 const char *ns_name = myhtml_namespace_name_by_id(ns_id, &ns_len);
1206 0 ▶ RETVAL = ns_name ? newSVpv(ns_name, ns_len) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ns_name ? newSVpv(ns_name, ns_len) : &PL_sv_undef; 0 0 0
1207 OUTPUT:
1208 RETVAL
1209  
1210 # Return tree parent parser
1211 SV *
1212 parser(HTML5::DOM::Tree self)
1213 CODE:
1214 0 RETVAL = myhtml_to_sv(self->tree);
1215 OUTPUT:
1216 RETVAL
1217  
1218 # Some bad idea to get "uniq id"
1219 SV *
1220 hash(HTML5::DOM::Node self)
1221 CODE:
1222 0 RETVAL = newSViv(PTR2IV(self));
1223 OUTPUT:
1224 RETVAL
1225  
1226 # Compare tree reference
1227 bool
1228 isSameTree(HTML5::DOM::Tree self, SV *other_tree)
1229 CODE:
1230 0 RETVAL = false;
1231 0 ▶ if (sv_derived_from(other_tree, "HTML5::DOM::Tree")) {
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(other_tree, "HTML5::DOM::Tree")) { 0 0 0
1232 0 html5_dom_tree_t *tree = INT2PTR(html5_dom_tree_t *, SvIV((SV*)SvRV(other_tree)));
1233 0 ▶ if (tree == self)
Branch: 1 branch
BranchTrueFalseTotal
if (tree == self) 0 0 0
1234 0 RETVAL = true;
1235 }
1236 OUTPUT:
1237 RETVAL
1238  
1239 void
1240 DESTROY(HTML5::DOM::Tree self)
1241 CODE:
1242 DOM_GC_TRACE("DOM::Tree::DESTROY (refs=%d)", SvREFCNT(SvRV(ST(0))));
1243 0 void *context = self->tree->context;
1244 0 myhtml_tree_destroy(self->tree);
1245 0 SvREFCNT_dec(self->parent);
1246 0 safefree(context);
1247  
1248  
1249  
1250 #################################################################
1251 # HTML5::DOM::Node
1252 #################################################################
1253 MODULE = HTML5::DOM PACKAGE = HTML5::DOM::Node
1254 # Tag id
1255 SV *
1256 tagId(HTML5::DOM::Node self, SV *new_tag_id = NULL)
1257 CODE:
1258 0 ▶ if (new_tag_id) {
Branch: 1 branch
BranchTrueFalseTotal
if (new_tag_id) { 0 0 0
1259 0 const myhtml_tag_context_t *tag_ctx = myhtml_tag_get_by_id(self->tree->tags, SvIV(new_tag_id));
1260 0 ▶ if (tag_ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (tag_ctx) { 0 0 0
1261 0 self->tag_id = SvIV(new_tag_id);
1262 } else {
1263 0 ▶ sub_croak(cv, "unknown tag id %ld", SvIV(new_tag_id));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "unknown tag id %ld", SvIV(new_tag_id)); 0 0 0
sub_croak(cv, "unknown tag id %ld", SvIV(new_tag_id)); 0 0 0
sub_croak(cv, "unknown tag id %ld", SvIV(new_tag_id)); 0 0 0
sub_croak(cv, "unknown tag id %ld", SvIV(new_tag_id)); 0 0 0
sub_croak(cv, "unknown tag id %ld", SvIV(new_tag_id)); 0 0 0
sub_croak(cv, "unknown tag id %ld", SvIV(new_tag_id)); 0 0 0
sub_croak(cv, "unknown tag id %ld", SvIV(new_tag_id)); 0 0 0
sub_croak(cv, "unknown tag id %ld", SvIV(new_tag_id)); 0 0 0
sub_croak(cv, "unknown tag id %ld", SvIV(new_tag_id)); 0 0 0
sub_croak(cv, "unknown tag id %ld", SvIV(new_tag_id)); 0 0 0
sub_croak(cv, "unknown tag id %ld", SvIV(new_tag_id)); 0 0 0
1264 }
1265
1266 0 RETVAL = SvREFCNT_inc(ST(0));
1267 } else {
1268 0 RETVAL = newSViv(self->tag_id);
1269 }
1270 OUTPUT:
1271 RETVAL
1272  
1273 # Namespace id
1274 SV *
1275 namespaceId(HTML5::DOM::Node self, SV *new_ns_id = NULL)
1276 CODE:
1277 0 ▶ if (new_ns_id) {
Branch: 1 branch
BranchTrueFalseTotal
if (new_ns_id) { 0 0 0
1278 0 ▶ if (!myhtml_namespace_name_by_id(SvIV(new_ns_id), NULL)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!myhtml_namespace_name_by_id(SvIV(new_ns_id), NULL)) { 0 0 0
1279 0 ▶ sub_croak(cv, "unknown namespace id %ld", SvIV(new_ns_id));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "unknown namespace id %ld", SvIV(new_ns_id)); 0 0 0
sub_croak(cv, "unknown namespace id %ld", SvIV(new_ns_id)); 0 0 0
sub_croak(cv, "unknown namespace id %ld", SvIV(new_ns_id)); 0 0 0
sub_croak(cv, "unknown namespace id %ld", SvIV(new_ns_id)); 0 0 0
sub_croak(cv, "unknown namespace id %ld", SvIV(new_ns_id)); 0 0 0
sub_croak(cv, "unknown namespace id %ld", SvIV(new_ns_id)); 0 0 0
sub_croak(cv, "unknown namespace id %ld", SvIV(new_ns_id)); 0 0 0
sub_croak(cv, "unknown namespace id %ld", SvIV(new_ns_id)); 0 0 0
sub_croak(cv, "unknown namespace id %ld", SvIV(new_ns_id)); 0 0 0
sub_croak(cv, "unknown namespace id %ld", SvIV(new_ns_id)); 0 0 0
sub_croak(cv, "unknown namespace id %ld", SvIV(new_ns_id)); 0 0 0
1280 } else {
1281 0 myhtml_node_namespace_set(self, SvIV(new_ns_id));
1282 }
1283 0 RETVAL = SvREFCNT_inc(ST(0));
1284 } else {
1285 0 RETVAL = newSViv(myhtml_node_namespace(self));
1286 }
1287 OUTPUT:
1288 RETVAL
1289  
1290 # Tag name
1291 SV *
1292 tag(HTML5::DOM::Node self, SV *new_tag_name = NULL)
1293 ALIAS:
1294 nodeName = 1
1295 tagName = 2
1296 CODE:
1297 0 myhtml_tree_t *tree = self->tree;
1298
1299 // Set new tag name
1300 0 ▶ if (new_tag_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (new_tag_name) { 0 0 0
1301 0 new_tag_name = sv_stringify(new_tag_name);
1302 STRLEN new_tag_name_len;
1303 0 const char *new_tag_name_str = SvPV_const(new_tag_name, new_tag_name_len);
1304
1305 0 ▶ if (!new_tag_name_len)
Branch: 1 branch
BranchTrueFalseTotal
if (!new_tag_name_len) 0 0 0
1306 0 ▶ sub_croak(cv, "empty tag name not allowed.");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "empty tag name not allowed."); 0 0 0
sub_croak(cv, "empty tag name not allowed."); 0 0 0
sub_croak(cv, "empty tag name not allowed."); 0 0 0
sub_croak(cv, "empty tag name not allowed."); 0 0 0
sub_croak(cv, "empty tag name not allowed."); 0 0 0
sub_croak(cv, "empty tag name not allowed."); 0 0 0
sub_croak(cv, "empty tag name not allowed."); 0 0 0
sub_croak(cv, "empty tag name not allowed."); 0 0 0
sub_croak(cv, "empty tag name not allowed."); 0 0 0
sub_croak(cv, "empty tag name not allowed."); 0 0 0
sub_croak(cv, "empty tag name not allowed."); 0 0 0
1307
1308 0 myhtml_tag_id_t tag_id = html5_dom_tag_id_by_name(self->tree, new_tag_name_str, new_tag_name_len, true);
1309 0 self->tag_id = tag_id;
1310
1311 0 RETVAL = SvREFCNT_inc(ST(0));
1312 }
1313 // Get tag name
1314 else {
1315 0 RETVAL = &PL_sv_undef;
1316
1317 0 ▶ if (tree && tree->tags) {
Branch: 2 branches
BranchTrueFalseTotal
if (tree && tree->tags) { 0 0 0
if (tree && tree->tags) { 0 0 0
1318 0 const myhtml_tag_context_t *tag_ctx = myhtml_tag_get_by_id(tree->tags, self->tag_id);
1319 0 ▶ if (tag_ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (tag_ctx) { 0 0 0
1320 0 RETVAL = newSVpv(tag_ctx->name, tag_ctx->name_length);
1321 0 ▶ if (ix == 1 || ix == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if (ix == 1 || ix == 2) { 0 0 0
if (ix == 1 || ix == 2) { 0 0 0
1322 STRLEN value_len;
1323 0 char *value = SvPV(RETVAL, value_len);
1324 0 ▶ for (size_t i = 0; i < value_len; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (size_t i = 0; i < value_len; ++i) 0 0 0
1325 0 value[i] = toupper(value[i]);
1326 }
1327 }
1328 }
1329 }
1330 OUTPUT:
1331 RETVAL
1332  
1333 # Namespace name
1334 SV *
1335 namespace(HTML5::DOM::Node self, SV *new_ns = NULL)
1336 CODE:
1337 0 myhtml_tree_t *tree = self->tree;
1338
1339 // Set new tag namespace
1340 0 ▶ if (new_ns) {
Branch: 1 branch
BranchTrueFalseTotal
if (new_ns) { 0 0 0
1341 0 new_ns = sv_stringify(new_ns);
1342 STRLEN new_ns_len;
1343 0 const char *new_ns_str = SvPV_const(new_ns, new_ns_len);
1344
1345 myhtml_namespace_t ns;
1346 0 ▶ if (!myhtml_namespace_id_by_name(new_ns_str, new_ns_len, &ns))
Branch: 1 branch
BranchTrueFalseTotal
if (!myhtml_namespace_id_by_name(new_ns_str, new_ns_len, &ns)) 0 0 0
1347 0 ▶ sub_croak(cv, "unknown namespace: %s", new_ns_str);
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "unknown namespace: %s", new_ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", new_ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", new_ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", new_ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", new_ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", new_ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", new_ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", new_ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", new_ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", new_ns_str); 0 0 0
sub_croak(cv, "unknown namespace: %s", new_ns_str); 0 0 0
1348 0 myhtml_node_namespace_set(self, ns);
1349
1350 0 RETVAL = SvREFCNT_inc(ST(0));
1351 }
1352 // Get namespace name
1353 else {
1354 size_t ns_name_len;
1355 0 const char *ns_name = myhtml_namespace_name_by_id(myhtml_node_namespace(self), &ns_name_len);
1356 0 ▶ RETVAL = newSVpv(ns_name ? ns_name : "", ns_name_len);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = newSVpv(ns_name ? ns_name : "", ns_name_len); 0 0 0
1357 }
1358 OUTPUT:
1359 RETVAL
1360  
1361 # Return node parent tree
1362 SV *
1363 tree(HTML5::DOM::Node self)
1364 CODE:
1365 0 RETVAL = tree_to_sv(self->tree);
1366 OUTPUT:
1367 RETVAL
1368  
1369 # Non-recursive html serialization (example: <div id="some_id">)
1370 SV *
1371 nodeHtml(HTML5::DOM::Node self)
1372 CODE:
1373 0 RETVAL = newSVpv("", 0);
1374 0 myhtml_serialization_node_callback(self, sv_serialization_callback, RETVAL);
1375 OUTPUT:
1376 RETVAL
1377  
1378 # Return node type
1379 int
1380 nodeType(HTML5::DOM::Node self)
1381 CODE:
1382 0 html5_dom_tree_t *context = (html5_dom_tree_t *) self->tree->context;
1383 0 RETVAL = 0;
1384 0 ▶ if (self->tag_id != MyHTML_TAG__UNDEF) {
Branch: 1 branch
BranchTrueFalseTotal
if (self->tag_id != MyHTML_TAG__UNDEF) { 0 0 0
1385 0 ▶ if (self->tag_id == MyHTML_TAG__TEXT) {
Branch: 1 branch
BranchTrueFalseTotal
if (self->tag_id == MyHTML_TAG__TEXT) { 0 0 0
1386 0 RETVAL = TEXT_NODE;
1387 0 ▶ } else if (self->tag_id == MyHTML_TAG__COMMENT) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (self->tag_id == MyHTML_TAG__COMMENT) { 0 0 0
1388 0 RETVAL = COMMENT_NODE;
1389 0 ▶ } else if (self->tag_id == MyHTML_TAG__DOCTYPE) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (self->tag_id == MyHTML_TAG__DOCTYPE) { 0 0 0
1390 0 RETVAL = DOCUMENT_TYPE_NODE;
1391 0 ▶ } else if (context->fragment_tag_id && self->tag_id == context->fragment_tag_id) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (context->fragment_tag_id && self->tag_id == context->fragment_tag_id) { 0 0 0
} else if (context->fragment_tag_id && self->tag_id == context->fragment_tag_id) { 0 0 0
1392 0 RETVAL = DOCUMENT_FRAGMENT_NODE;
1393 } else {
1394 0 RETVAL = ELEMENT_NODE;
1395 }
1396 } else {
1397 // Modest myhtml bug - document node has tag_id == MyHTML_TAG__UNDEF
1398 0 ▶ if (node_is_document(self))
Branch: 2 branches
BranchTrueFalseTotal
if (node_is_document(self)) 0 0 0
if (node_is_document(self)) 0 0 0
1399 0 RETVAL = DOCUMENT_NODE;
1400 }
1401 OUTPUT:
1402 RETVAL
1403  
1404 # Node::html() - Serialize text/comment node to html
1405 # Node::html(text) - Same as Node::nodeValue(text)
1406 # Element::html(text) - Remove all children nodes and add parsed fragment, return self
1407 SV *
1408 html(HTML5::DOM::Node self, SV *text = NULL)
1409 ALIAS:
1410 innerHTML = 1
1411 outerHTML = 2
1412 CODE:
1413 0 ▶ if (text) {
Branch: 1 branch
BranchTrueFalseTotal
if (text) { 0 0 0
1414 0 ▶ if (ix == 2 && !myhtml_node_parent(self)) // outerHTML
Branch: 2 branches
BranchTrueFalseTotal
if (ix == 2 && !myhtml_node_parent(self)) // outerHTML 0 0 0
if (ix == 2 && !myhtml_node_parent(self)) // outerHTML 0 0 0
1415 0 ▶ sub_croak(cv, "This element has no parent node.");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "This element has no parent node."); 0 0 0
sub_croak(cv, "This element has no parent node."); 0 0 0
sub_croak(cv, "This element has no parent node."); 0 0 0
sub_croak(cv, "This element has no parent node."); 0 0 0
sub_croak(cv, "This element has no parent node."); 0 0 0
sub_croak(cv, "This element has no parent node."); 0 0 0
sub_croak(cv, "This element has no parent node."); 0 0 0
sub_croak(cv, "This element has no parent node."); 0 0 0
sub_croak(cv, "This element has no parent node."); 0 0 0
sub_croak(cv, "This element has no parent node."); 0 0 0
sub_croak(cv, "This element has no parent node."); 0 0 0
1416
1417 0 text = sv_stringify(text);
1418 STRLEN text_len;
1419 0 const char *text_str = SvPV_const(text, text_len);
1420
1421 0 ▶ if (node_is_element(self) || node_is_document(self)) { // parse fragment and replace all node childrens with it
Branch: 6 branches
BranchTrueFalseTotal
if (node_is_element(self) || node_is_document(self)) { // parse fragment and replace all node childrens with it 0 0 0
if (node_is_element(self) || node_is_document(self)) { // parse fragment and replace all node childrens with it 0 0 0
if (node_is_element(self) || node_is_document(self)) { // parse fragment and replace all node childrens with it 0 0 0
if (node_is_element(self) || node_is_document(self)) { // parse fragment and replace all node childrens with it 0 0 0
if (node_is_element(self) || node_is_document(self)) { // parse fragment and replace all node childrens with it 0 0 0
if (node_is_element(self) || node_is_document(self)) { // parse fragment and replace all node childrens with it 0 0 0
1422 // parse fragment
1423 mystatus_t status;
1424 0 html5_fragment_parts_t parts = {0};
1425 0 ▶ myhtml_tree_node_t *context_node = ix == 2 ? myhtml_node_parent(self) : self;
Branch: 1 branch
BranchTrueFalseTotal
myhtml_tree_node_t *context_node = ix == 2 ? myhtml_node_parent(self) : self; 0 0 0
1426 0 myhtml_tag_id_t context_tag_id = context_node->tag_id;
1427
1428 // hack for document node
1429 0 ▶ if (node_is_document(context_node))
Branch: 2 branches
BranchTrueFalseTotal
if (node_is_document(context_node)) 0 0 0
if (node_is_document(context_node)) 0 0 0
1430 0 context_tag_id = MyHTML_TAG_HTML;
1431
1432 0 html5_dom_tree_t *tree_context = (html5_dom_tree_t *) self->tree->context;
1433 0 html5_dom_options_t opts = {0};
1434 0 html5_dom_parse_options(&opts, &tree_context->parser->opts, NULL);
1435
1436 // force set encoding to UTF-8
1437 0 opts.encoding = MyENCODING_DEFAULT;
1438 0 opts.default_encoding = MyENCODING_DEFAULT;
1439
1440 0 myhtml_tree_node_t *fragment = html5_dom_parse_fragment(&opts, self->tree, context_tag_id, myhtml_node_namespace(context_node), text_str, text_len, &parts, &status);
1441 0 ▶ if (status)
Branch: 1 branch
BranchTrueFalseTotal
if (status) 0 0 0
1442 0 ▶ sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "myhtml_parse_fragment failed: %d (%s)", status, modest_strerror(status)); 0 0 0
1443
1444 // remove all child nodes
1445 0 myhtml_tree_node_t *node = myhtml_node_child(self);
1446 0 ▶ while (node) {
Branch: 1 branch
BranchTrueFalseTotal
while (node) { 0 0 0
1447 0 myhtml_tree_node_t *next = myhtml_node_next(node);
1448 0 myhtml_tree_node_remove(node);
1449 0 html5_tree_node_delete_recursive(node);
1450 0 node = next;
1451 }
1452
1453 // cleanup references in tree
1454 0 ▶ if (node_is_root(self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (node_is_root(self)) { 0 0 0
if (node_is_root(self)) { 0 0 0
1455 0 self->tree->node_body = parts.node_body;
1456 0 self->tree->node_head = parts.node_head;
1457 0 ▶ } else if (node_is_document(self)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (node_is_document(self)) { 0 0 0
} else if (node_is_document(self)) { 0 0 0
1458 0 self->tree->node_html = parts.node_html;
1459 0 self->tree->node_body = parts.node_body;
1460 0 self->tree->node_head = parts.node_head;
1461 }
1462
1463 0 ▶ if (fragment != self->tree->node_html) {
Branch: 1 branch
BranchTrueFalseTotal
if (fragment != self->tree->node_html) { 0 0 0
1464 // add fragment
1465 0 node = myhtml_node_child(fragment);
1466 0 ▶ while (node) {
Branch: 1 branch
BranchTrueFalseTotal
while (node) { 0 0 0
1467 0 myhtml_tree_node_t *next = myhtml_node_next(node);
1468 0 myhtml_tree_node_remove(node);
1469 0 ▶ if (ix == 2) { // outerHTML
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 2) { // outerHTML 0 0 0
1470 0 myhtml_tree_node_insert_before(self, node);
1471 } else { // innerHTML
1472 0 myhtml_tree_node_add_child(self, node);
1473 }
1474 0 node = next;
1475 }
1476
1477 // remove self if outerHTML
1478 0 ▶ if (ix == 2)
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 2) 0 0 0
1479 0 myhtml_tree_node_remove(self);
1480
1481 // free fragment
1482 0 html5_tree_node_delete_recursive(fragment);
1483 } else {
1484 // fragment now is html node, why not?
1485 0 fragment->tag_id = MyHTML_TAG_HTML;
1486 0 myhtml_tree_node_remove(fragment);
1487 0 myhtml_tree_node_add_child(self, fragment);
1488 }
1489 } else { // same as nodeValue, for user friendly API
1490 0 myhtml_node_text_set(self, text_str, text_len, MyENCODING_DEFAULT);
1491 }
1492 0 RETVAL = SvREFCNT_inc(ST(0));
1493 } else {
1494 0 RETVAL = newSVpv("", 0);
1495 0 ▶ if (self->tag_id == MyHTML_TAG__UNDEF || ix == 1 || html5_dom_is_fragment(self)) { // innerHTML
Branch: 3 branches
BranchTrueFalseTotal
if (self->tag_id == MyHTML_TAG__UNDEF || ix == 1 || html5_dom_is_fragment(self)) { // innerHTML 0 0 0
if (self->tag_id == MyHTML_TAG__UNDEF || ix == 1 || html5_dom_is_fragment(self)) { // innerHTML 0 0 0
if (self->tag_id == MyHTML_TAG__UNDEF || ix == 1 || html5_dom_is_fragment(self)) { // innerHTML 0 0 0
1496 0 myhtml_tree_node_t *node = myhtml_node_child(self);
1497 0 ▶ while (node) {
Branch: 1 branch
BranchTrueFalseTotal
while (node) { 0 0 0
1498 0 myhtml_serialization_tree_callback(node, sv_serialization_callback, RETVAL);
1499 0 node = myhtml_node_next(node);
1500 }
1501 } else { // outerHTML
1502 0 myhtml_serialization_tree_callback(self, sv_serialization_callback, RETVAL);
1503 }
1504 }
1505 OUTPUT:
1506 RETVAL
1507  
1508 # Node::text() - Serialize tree to text
1509 # Node::text(text) - Set node value, return self
1510 # Element::text(text) - Remove all children nodes and add text node, return self
1511 SV *
1512 text(HTML5::DOM::Node self, SV *text = NULL)
1513 ALIAS:
1514 nodeValue = 1
1515 innerText = 2
1516 textContent = 3
1517 data = 4
1518 outerText = 5
1519 CODE:
1520 static const char names[][16] = {
1521 "text", "nodeValue", "innerText", "textContent", "data", "outerText"
1522 };
1523
1524 0 myhtml_tree_t *tree = self->tree;
1525 0 ▶ if (!node_is_element(self)) {
Branch: 4 branches
BranchTrueFalseTotal
if (!node_is_element(self)) { 0 0 0
if (!node_is_element(self)) { 0 0 0
if (!node_is_element(self)) { 0 0 0
if (!node_is_element(self)) { 0 0 0
1526 0 ▶ if (ix == 2 || ix == 3 || ix == 5) {
Branch: 3 branches
BranchTrueFalseTotal
if (ix == 2 || ix == 3 || ix == 5) { 0 0 0
if (ix == 2 || ix == 3 || ix == 5) { 0 0 0
if (ix == 2 || ix == 3 || ix == 5) { 0 0 0
1527 0 ▶ if (text) {
Branch: 1 branch
BranchTrueFalseTotal
if (text) { 0 0 0
1528 0 ▶ sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
1529 } else {
1530 0 RETVAL = &PL_sv_undef;
1531 }
1532 0 ▶ } else if (text) { // set node value
Branch: 1 branch
BranchTrueFalseTotal
} else if (text) { // set node value 0 0 0
1533 0 text = sv_stringify(text);
1534 STRLEN text_len;
1535 0 const char *text_str = SvPV_const(text, text_len);
1536
1537 0 myhtml_node_text_set(self, text_str, text_len, MyENCODING_DEFAULT);
1538 0 RETVAL = SvREFCNT_inc(ST(0));
1539 } else { // get node value
1540 0 size_t text_len = 0;
1541 0 const char *text = myhtml_node_text(self, &text_len);
1542 0 ▶ RETVAL = newSVpv(text ? text : "", text_len);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = newSVpv(text ? text : "", text_len); 0 0 0
1543 }
1544 } else {
1545 0 ▶ if (ix == 1 || ix == 4) {
Branch: 2 branches
BranchTrueFalseTotal
if (ix == 1 || ix == 4) { 0 0 0
if (ix == 1 || ix == 4) { 0 0 0
1546 0 ▶ if (text) {
Branch: 1 branch
BranchTrueFalseTotal
if (text) { 0 0 0
1547 0 ▶ sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
sub_croak(cv, "%s unsupported in %s", names[ix], get_node_class(self)); 0 0 0
1548 } else {
1549 0 RETVAL = &PL_sv_undef;
1550 }
1551 0 ▶ } else if (text) { // remove all childrens and add text node
Branch: 1 branch
BranchTrueFalseTotal
} else if (text) { // remove all childrens and add text node 0 0 0
1552 0 text = sv_stringify(text);
1553 STRLEN text_len;
1554 0 const char *text_str = SvPV_const(text, text_len);
1555
1556 // remove all children nodes
1557 0 myhtml_tree_node_t *node = myhtml_node_child(self);
1558 0 ▶ while (node) {
Branch: 1 branch
BranchTrueFalseTotal
while (node) { 0 0 0
1559 0 myhtml_tree_node_t *next = myhtml_node_next(node);
1560 0 myhtml_tree_node_remove(node);
1561 0 html5_tree_node_delete_recursive(node);
1562 0 node = next;
1563 }
1564
1565 // cleanup references in tree
1566 0 ▶ if (node_is_root(self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (node_is_root(self)) { 0 0 0
if (node_is_root(self)) { 0 0 0
1567 0 self->tree->node_body = NULL;
1568 0 self->tree->node_head = NULL;
1569 0 ▶ } else if (node_is_document(self)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (node_is_document(self)) { 0 0 0
} else if (node_is_document(self)) { 0 0 0
1570 0 self->tree->node_html = NULL;
1571 0 self->tree->node_body = NULL;
1572 0 self->tree->node_head = NULL;
1573 }
1574
1575 // innerText, outerText
1576 0 ▶ if (ix == 2 || ix == 5) {
Branch: 2 branches
BranchTrueFalseTotal
if (ix == 2 || ix == 5) { 0 0 0
if (ix == 2 || ix == 5) { 0 0 0
1577 0 size_t last_pos = 0;
1578 0 ▶ for (size_t i = 0; i < text_len; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (size_t i = 0; i < text_len; ++i) { 0 0 0
1579 0 bool is_end = (i >= text_len - 1);
1580 0 ▶ bool is_new_line = (text_str[i] == '\n' || text_str[i] == '\r');
Branch: 2 branches
BranchTrueFalseTotal
bool is_new_line = (text_str[i] == '\n' || text_str[i] == '\r'); 0 0 0
bool is_new_line = (text_str[i] == '\n' || text_str[i] == '\r'); 0 0 0
1581 0 ▶ if (is_end || is_new_line) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_end || is_new_line) { 0 0 0
if (is_end || is_new_line) { 0 0 0
1582 0 ▶ if (is_end && !is_new_line)
Branch: 2 branches
BranchTrueFalseTotal
if (is_end && !is_new_line) 0 0 0
if (is_end && !is_new_line) 0 0 0
1583 0 ++i;
1584
1585 // insert new text node
1586 0 ▶ if (i - last_pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (i - last_pos) { 0 0 0
1587 0 myhtml_tree_node_t *text_node = myhtml_node_create(self->tree, MyHTML_TAG__TEXT, myhtml_node_namespace(self));
1588 0 myhtml_node_text_set(text_node, &text_str[last_pos], i - last_pos, MyENCODING_DEFAULT);
1589 0 ▶ if (ix == 5) { // outerText
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 5) { // outerText 0 0 0
1590 0 myhtml_tree_node_insert_before(self, text_node);
1591 } else { // innerText
1592 0 myhtml_tree_node_add_child(self, text_node);
1593 }
1594 }
1595
1596 // insert new br
1597 0 ▶ if (is_new_line) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_new_line) { 0 0 0
1598 0 myhtml_tree_node_t *text_node = myhtml_node_create(self->tree, MyHTML_TAG_BR, myhtml_node_namespace(self));
1599 0 ▶ if (!text_node->token) {
Branch: 1 branch
BranchTrueFalseTotal
if (!text_node->token) { 0 0 0
1600 0 text_node->token = myhtml_token_node_create(self->tree->token, self->tree->mcasync_rules_token_id);
1601 0 ▶ if (!text_node->token) {
Branch: 1 branch
BranchTrueFalseTotal
if (!text_node->token) { 0 0 0
1602 0 myhtml_tree_node_delete(text_node);
1603 0 ▶ sub_croak(cv, "myhtml_token_node_create failed");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
sub_croak(cv, "myhtml_token_node_create failed"); 0 0 0
1604 }
1605 0 text_node->token->type |= MyHTML_TOKEN_TYPE_CLOSE_SELF | MyHTML_TOKEN_TYPE_DONE;
1606 }
1607
1608 0 ▶ if (ix == 5) { // outerText
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 5) { // outerText 0 0 0
1609 0 myhtml_tree_node_insert_before(self, text_node);
1610 } else { // innerText
1611 0 myhtml_tree_node_add_child(self, text_node);
1612 }
1613 }
1614
1615 0 ▶ if (!is_end) {
Branch: 1 branch
BranchTrueFalseTotal
if (!is_end) { 0 0 0
1616 0 ▶ if (text_str[i] == '\r' && text_str[i + 1] == '\n')
Branch: 2 branches
BranchTrueFalseTotal
if (text_str[i] == '\r' && text_str[i + 1] == '\n') 0 0 0
if (text_str[i] == '\r' && text_str[i + 1] == '\n') 0 0 0
1617 0 ++i;
1618 0 last_pos = i + 1;
1619 }
1620 }
1621 }
1622 }
1623 // text, textContent
1624 else {
1625 0 myhtml_tree_node_t *text_node = myhtml_node_create(self->tree, MyHTML_TAG__TEXT, myhtml_node_namespace(self));
1626 0 myhtml_node_text_set(text_node, text_str, text_len, MyENCODING_DEFAULT);
1627 0 myhtml_tree_node_add_child(self, text_node);
1628 }
1629
1630 0 RETVAL = SvREFCNT_inc(ST(0));
1631
1632 0 ▶ if (ix == 5) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 5) { 0 0 0
1633 // remove self, if outerText
1634 0 myhtml_tree_node_remove(self);
1635 }
1636 } else { // recursive serialize node to text
1637 // innerText, outerText
1638 0 ▶ if (ix == 2 || ix == 5) {
Branch: 2 branches
BranchTrueFalseTotal
if (ix == 2 || ix == 5) { 0 0 0
if (ix == 2 || ix == 5) { 0 0 0
1639 0 html5_dom_inner_text_state_t state = {0};
1640 0 state.last_br = true;
1641 0 state.new_line = true;
1642
1643 0 mycore_string_init(self->tree->mchar, self->tree->mchar_node_id, &state.value, 1);
1644
1645 0 myhtml_tree_node_t *next = myhtml_node_child(self);
1646 0 ▶ while (next) {
Branch: 1 branch
BranchTrueFalseTotal
while (next) { 0 0 0
1647 0 html5_dom_recursive_node_inner_text(next, &state);
1648 0 next = myhtml_node_next(next);
1649 }
1650 0 html5_dom_rtrim_mystring(&state.value, ' ');
1651
1652 0 ▶ RETVAL = newSVpv(state.value.data ? state.value.data : "", state.value.length);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = newSVpv(state.value.data ? state.value.data : "", state.value.length); 0 0 0
1653 0 mycore_string_destroy(&state.value, 0);
1654 }
1655 // text, textContent
1656 else {
1657 0 RETVAL = newSVpv("", 0);
1658 0 html5_dom_recursive_node_text(self, RETVAL);
1659 }
1660 }
1661 }
1662 OUTPUT:
1663 RETVAL
1664  
1665 # Wait for node parsing done (when async mode) - removed
1666 SV *
1667 wait(HTML5::DOM::Node self, bool deep = false)
1668 CODE:
1669 0 RETVAL = SvREFCNT_inc(ST(0));
1670 OUTPUT:
1671 RETVAL
1672  
1673 # True if node parsing done (when async mode) - removed
1674 int
1675 parsed(HTML5::DOM::Node self, bool deep = false)
1676 CODE:
1677 0 ▶ RETVAL = 1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 1; 0 0 0
1678 OUTPUT:
1679 RETVAL
1680  
1681 # Next element
1682 SV *
1683 next(HTML5::DOM::Node self)
1684 ALIAS:
1685 nextElementSibling = 1
1686 CODE:
1687 0 myhtml_tree_node_t *node = myhtml_node_next(self);
1688 0 ▶ while (node && !node_is_element(node))
Branch: 5 branches
BranchTrueFalseTotal
while (node && !node_is_element(node)) 0 0 0
while (node && !node_is_element(node)) 0 0 0
while (node && !node_is_element(node)) 0 0 0
while (node && !node_is_element(node)) 0 0 0
while (node && !node_is_element(node)) 0 0 0
1689 0 node = myhtml_node_next(node);
1690 0 RETVAL = node_to_sv(node);
1691 OUTPUT:
1692 RETVAL
1693  
1694 # Next node
1695 SV *
1696 nextNode(HTML5::DOM::Node self)
1697 ALIAS:
1698 nextSibling = 1
1699 CODE:
1700 0 RETVAL = node_to_sv(myhtml_node_next(self));
1701 OUTPUT:
1702 RETVAL
1703  
1704 # Prev element
1705 SV *
1706 prev(HTML5::DOM::Node self)
1707 ALIAS:
1708 previousElementSibling = 1
1709 CODE:
1710 0 myhtml_tree_node_t *node = myhtml_node_prev(self);
1711 0 ▶ while (node && !node_is_element(node))
Branch: 5 branches
BranchTrueFalseTotal
while (node && !node_is_element(node)) 0 0 0
while (node && !node_is_element(node)) 0 0 0
while (node && !node_is_element(node)) 0 0 0
while (node && !node_is_element(node)) 0 0 0
while (node && !node_is_element(node)) 0 0 0
1712 0 node = myhtml_node_prev(node);
1713 0 RETVAL = node_to_sv(node);
1714 OUTPUT:
1715 RETVAL
1716  
1717 # Prev node
1718 SV *
1719 prevNode(HTML5::DOM::Node self)
1720 ALIAS:
1721 previousSibling = 1
1722 CODE:
1723 0 RETVAL = node_to_sv(myhtml_node_prev(self));
1724 OUTPUT:
1725 RETVAL
1726  
1727 # Parent node
1728 SV *
1729 parent(HTML5::DOM::Node self)
1730 ALIAS:
1731 isConnected = 1
1732 parentNode = 2
1733 parentElement = 3
1734 CODE:
1735 0 ▶ RETVAL = ix == 1 ? newSViv(myhtml_node_parent(self) ? 1 : 0) : node_to_sv(myhtml_node_parent(self));
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ix == 1 ? newSViv(myhtml_node_parent(self) ? 1 : 0) : node_to_sv(myhtml_node_parent(self)); 0 0 0
1736 OUTPUT:
1737 RETVAL
1738  
1739 # Owner document
1740 SV *
1741 document(HTML5::DOM::Node self)
1742 ALIAS:
1743 ownerDocument = 1
1744 CODE:
1745 0 RETVAL = node_to_sv(myhtml_tree_get_document(self->tree));
1746 OUTPUT:
1747 RETVAL
1748  
1749 # Remove node from tree
1750 SV *
1751 remove(HTML5::DOM::Node self, HTML5::DOM::Node node = NULL)
1752 ALIAS:
1753 removeChild = 1
1754 CODE:
1755 0 ▶ if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) { 0 0 0
1756 0 ▶ if (!node)
Branch: 1 branch
BranchTrueFalseTotal
if (!node) 0 0 0
1757 0 ▶ sub_croak(cv, "%s is not of type %s", "node", "HTML5::DOM::Node");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "%s is not of type %s", "node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "node", "HTML5::DOM::Node"); 0 0 0
1758 0 ▶ if (node->parent != self)
Branch: 1 branch
BranchTrueFalseTotal
if (node->parent != self) 0 0 0
1759 0 ▶ sub_croak(cv, "The node to be removed is not a child of this node.");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "The node to be removed is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be removed is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be removed is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be removed is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be removed is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be removed is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be removed is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be removed is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be removed is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be removed is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be removed is not a child of this node."); 0 0 0
1760 0 RETVAL = node_to_sv(myhtml_tree_node_remove(node));
1761 } else {
1762 0 RETVAL = node_to_sv(myhtml_tree_node_remove(self));
1763 }
1764 OUTPUT:
1765 RETVAL
1766  
1767 # Append child to parent before current node
1768 SV *
1769 before(HTML5::DOM::Node self, HTML5::DOM::Node a, HTML5::DOM::Node b = NULL)
1770 ALIAS:
1771 insertBefore = 1
1772 CODE:
1773 myhtml_tree_node_t *reference_node, *new_node;
1774
1775 0 ▶ if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) { 0 0 0
1776 0 new_node = a;
1777 0 reference_node = b;
1778
1779 0 ▶ if (!reference_node)
Branch: 1 branch
BranchTrueFalseTotal
if (!reference_node) 0 0 0
1780 0 ▶ sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
1781 0 ▶ if (reference_node->parent != self)
Branch: 1 branch
BranchTrueFalseTotal
if (reference_node->parent != self) 0 0 0
1782 0 ▶ sub_croak(cv, "The node before which the new node is to be inserted is not a child of this node.");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "The node before which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node before which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node before which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node before which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node before which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node before which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node before which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node before which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node before which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node before which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node before which the new node is to be inserted is not a child of this node."); 0 0 0
1783 } else {
1784 0 new_node = a;
1785 0 reference_node = self;
1786 }
1787
1788 0 ▶ if (!myhtml_node_parent(reference_node))
Branch: 1 branch
BranchTrueFalseTotal
if (!myhtml_node_parent(reference_node)) 0 0 0
1789 0 ▶ sub_croak(cv, "can't insert before detached node");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
1790
1791 0 ▶ if (reference_node->tree != new_node->tree) {
Branch: 1 branch
BranchTrueFalseTotal
if (reference_node->tree != new_node->tree) { 0 0 0
1792 0 myhtml_tree_node_remove(new_node);
1793 0 new_node = html5_dom_recursive_clone_node(reference_node->tree, new_node, NULL);
1794 0 ▶ if (!new_node)
Branch: 1 branch
BranchTrueFalseTotal
if (!new_node) 0 0 0
1795 0 ▶ sub_croak(cv, "node copying internal error");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
1796 }
1797
1798 0 ▶ if (html5_dom_is_fragment(new_node)) {
Branch: 1 branch
BranchTrueFalseTotal
if (html5_dom_is_fragment(new_node)) { 0 0 0
1799 0 myhtml_tree_node_t *fragment_child = myhtml_node_child(new_node);
1800 0 ▶ while (fragment_child) {
Branch: 1 branch
BranchTrueFalseTotal
while (fragment_child) { 0 0 0
1801 0 myhtml_tree_node_t *next = myhtml_node_next(fragment_child);
1802 0 myhtml_tree_node_remove(fragment_child);
1803 0 myhtml_tree_node_insert_before(reference_node, fragment_child);
1804 0 fragment_child = next;
1805 }
1806 } else {
1807 0 myhtml_tree_node_remove(new_node);
1808 0 myhtml_tree_node_insert_before(reference_node, new_node);
1809 }
1810
1811 0 ▶ if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) { 0 0 0
1812 0 RETVAL = node_to_sv(new_node);
1813 } else {
1814 0 RETVAL = SvREFCNT_inc(ST(0));
1815 }
1816 OUTPUT:
1817 RETVAL
1818  
1819 # Append child to parent after current node
1820 SV *
1821 after(HTML5::DOM::Node self, HTML5::DOM::Node a, HTML5::DOM::Node b = NULL)
1822 ALIAS:
1823 insertAfter = 1
1824 CODE:
1825 myhtml_tree_node_t *reference_node, *new_node;
1826
1827 0 ▶ if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) { 0 0 0
1828 0 new_node = a;
1829 0 reference_node = b;
1830
1831 0 ▶ if (!reference_node)
Branch: 1 branch
BranchTrueFalseTotal
if (!reference_node) 0 0 0
1832 0 ▶ sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "reference_node", "HTML5::DOM::Node"); 0 0 0
1833 0 ▶ if (reference_node->parent != self)
Branch: 1 branch
BranchTrueFalseTotal
if (reference_node->parent != self) 0 0 0
1834 0 ▶ sub_croak(cv, "The node after which the new node is to be inserted is not a child of this node.");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "The node after which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node after which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node after which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node after which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node after which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node after which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node after which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node after which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node after which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node after which the new node is to be inserted is not a child of this node."); 0 0 0
sub_croak(cv, "The node after which the new node is to be inserted is not a child of this node."); 0 0 0
1835 } else {
1836 0 new_node = a;
1837 0 reference_node = self;
1838 }
1839
1840 0 ▶ if (!myhtml_node_parent(reference_node))
Branch: 1 branch
BranchTrueFalseTotal
if (!myhtml_node_parent(reference_node)) 0 0 0
1841 0 ▶ sub_croak(cv, "can't insert before detached node");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
sub_croak(cv, "can't insert before detached node"); 0 0 0
1842
1843 0 ▶ if (reference_node->tree != new_node->tree) {
Branch: 1 branch
BranchTrueFalseTotal
if (reference_node->tree != new_node->tree) { 0 0 0
1844 0 myhtml_tree_node_remove(new_node);
1845 0 new_node = html5_dom_recursive_clone_node(reference_node->tree, new_node, NULL);
1846 0 ▶ if (!new_node)
Branch: 1 branch
BranchTrueFalseTotal
if (!new_node) 0 0 0
1847 0 ▶ sub_croak(cv, "node copying internal error");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
1848 }
1849
1850 0 ▶ if (html5_dom_is_fragment(new_node)) {
Branch: 1 branch
BranchTrueFalseTotal
if (html5_dom_is_fragment(new_node)) { 0 0 0
1851 0 myhtml_tree_node_t *fragment_child = myhtml_node_last_child(new_node);
1852 0 ▶ while (fragment_child) {
Branch: 1 branch
BranchTrueFalseTotal
while (fragment_child) { 0 0 0
1853 0 myhtml_tree_node_t *next = myhtml_node_prev(fragment_child);
1854 0 myhtml_tree_node_remove(fragment_child);
1855 0 myhtml_tree_node_insert_after(reference_node, fragment_child);
1856 0 fragment_child = next;
1857 }
1858 } else {
1859 0 myhtml_tree_node_remove(new_node);
1860 0 myhtml_tree_node_insert_after(reference_node, new_node);
1861 }
1862
1863 0 ▶ if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) { 0 0 0
1864 0 RETVAL = node_to_sv(new_node);
1865 } else {
1866 0 RETVAL = SvREFCNT_inc(ST(0));
1867 }
1868 OUTPUT:
1869 RETVAL
1870  
1871 # Append node child
1872 SV *
1873 append(HTML5::DOM::Node self, HTML5::DOM::Node child)
1874 ALIAS:
1875 appendChild = 1
1876 CODE:
1877 0 ▶ if (!node_is_element(self))
Branch: 4 branches
BranchTrueFalseTotal
if (!node_is_element(self)) 0 0 0
if (!node_is_element(self)) 0 0 0
if (!node_is_element(self)) 0 0 0
if (!node_is_element(self)) 0 0 0
1878 0 ▶ sub_croak(cv, "can't append children to non-element node");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "can't append children to non-element node"); 0 0 0
sub_croak(cv, "can't append children to non-element node"); 0 0 0
sub_croak(cv, "can't append children to non-element node"); 0 0 0
sub_croak(cv, "can't append children to non-element node"); 0 0 0
sub_croak(cv, "can't append children to non-element node"); 0 0 0
sub_croak(cv, "can't append children to non-element node"); 0 0 0
sub_croak(cv, "can't append children to non-element node"); 0 0 0
sub_croak(cv, "can't append children to non-element node"); 0 0 0
sub_croak(cv, "can't append children to non-element node"); 0 0 0
sub_croak(cv, "can't append children to non-element node"); 0 0 0
sub_croak(cv, "can't append children to non-element node"); 0 0 0
1879
1880 0 ▶ if (self->tree != child->tree) {
Branch: 1 branch
BranchTrueFalseTotal
if (self->tree != child->tree) { 0 0 0
1881 0 myhtml_tree_node_remove(child);
1882 0 child = html5_dom_recursive_clone_node(self->tree, child, NULL);
1883 0 ▶ if (!child)
Branch: 1 branch
BranchTrueFalseTotal
if (!child) 0 0 0
1884 0 ▶ sub_croak(cv, "node copying internal error");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
1885 }
1886
1887 0 ▶ if (html5_dom_is_fragment(child)) {
Branch: 1 branch
BranchTrueFalseTotal
if (html5_dom_is_fragment(child)) { 0 0 0
1888 0 myhtml_tree_node_t *fragment_child = myhtml_node_child(child);
1889 0 ▶ while (fragment_child) {
Branch: 1 branch
BranchTrueFalseTotal
while (fragment_child) { 0 0 0
1890 0 myhtml_tree_node_t *next = myhtml_node_next(fragment_child);
1891 0 myhtml_tree_node_remove(fragment_child);
1892 0 myhtml_tree_node_add_child(self, fragment_child);
1893 0 fragment_child = next;
1894 }
1895 } else {
1896 0 myhtml_tree_node_remove(child);
1897 0 myhtml_tree_node_add_child(self, child);
1898 }
1899
1900 0 ▶ if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) { 0 0 0
1901 0 RETVAL = node_to_sv(child);
1902 } else {
1903 0 RETVAL = SvREFCNT_inc(ST(0));
1904 }
1905 OUTPUT:
1906 RETVAL
1907  
1908 # Prepend node child
1909 SV *
1910 prepend(HTML5::DOM::Node self, HTML5::DOM::Node child)
1911 ALIAS:
1912 prependChild = 1
1913 CODE:
1914 0 ▶ if (!node_is_element(self))
Branch: 4 branches
BranchTrueFalseTotal
if (!node_is_element(self)) 0 0 0
if (!node_is_element(self)) 0 0 0
if (!node_is_element(self)) 0 0 0
if (!node_is_element(self)) 0 0 0
1915 0 ▶ sub_croak(cv, "can't prepend children to non-element node");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "can't prepend children to non-element node"); 0 0 0
sub_croak(cv, "can't prepend children to non-element node"); 0 0 0
sub_croak(cv, "can't prepend children to non-element node"); 0 0 0
sub_croak(cv, "can't prepend children to non-element node"); 0 0 0
sub_croak(cv, "can't prepend children to non-element node"); 0 0 0
sub_croak(cv, "can't prepend children to non-element node"); 0 0 0
sub_croak(cv, "can't prepend children to non-element node"); 0 0 0
sub_croak(cv, "can't prepend children to non-element node"); 0 0 0
sub_croak(cv, "can't prepend children to non-element node"); 0 0 0
sub_croak(cv, "can't prepend children to non-element node"); 0 0 0
sub_croak(cv, "can't prepend children to non-element node"); 0 0 0
1916
1917 0 ▶ if (self->tree != child->tree) {
Branch: 1 branch
BranchTrueFalseTotal
if (self->tree != child->tree) { 0 0 0
1918 0 myhtml_tree_node_remove(child);
1919 0 child = html5_dom_recursive_clone_node(self->tree, child, NULL);
1920 0 ▶ if (!child)
Branch: 1 branch
BranchTrueFalseTotal
if (!child) 0 0 0
1921 0 ▶ sub_croak(cv, "node copying internal error");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
1922 }
1923
1924 0 myhtml_tree_node_t *first_node = myhtml_node_child(self);
1925 0 ▶ if (html5_dom_is_fragment(child)) {
Branch: 1 branch
BranchTrueFalseTotal
if (html5_dom_is_fragment(child)) { 0 0 0
1926 0 myhtml_tree_node_t *fragment_child = myhtml_node_child(child);
1927 0 ▶ while (fragment_child) {
Branch: 1 branch
BranchTrueFalseTotal
while (fragment_child) { 0 0 0
1928 0 myhtml_tree_node_t *next = myhtml_node_next(fragment_child);
1929 0 myhtml_tree_node_remove(fragment_child);
1930 0 ▶ if (first_node) {
Branch: 1 branch
BranchTrueFalseTotal
if (first_node) { 0 0 0
1931 0 myhtml_tree_node_insert_before(first_node, fragment_child);
1932 } else {
1933 0 myhtml_tree_node_add_child(self, fragment_child);
1934 }
1935 0 fragment_child = next;
1936 }
1937 } else {
1938 0 myhtml_tree_node_remove(child);
1939 0 ▶ if (first_node) {
Branch: 1 branch
BranchTrueFalseTotal
if (first_node) { 0 0 0
1940 0 myhtml_tree_node_insert_before(first_node, child);
1941 } else {
1942 0 myhtml_tree_node_add_child(self, child);
1943 }
1944 }
1945
1946 0 ▶ if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) { 0 0 0
1947 0 RETVAL = node_to_sv(child);
1948 } else {
1949 0 RETVAL = SvREFCNT_inc(ST(0));
1950 }
1951 OUTPUT:
1952 RETVAL
1953  
1954 # Replace node with child
1955 SV *
1956 replace(HTML5::DOM::Node self, HTML5::DOM::Node a, HTML5::DOM::Node b = NULL)
1957 ALIAS:
1958 replaceChild = 1
1959 CODE:
1960 myhtml_tree_node_t *old_node, *new_node;
1961
1962 0 ▶ if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) { 0 0 0
1963 0 new_node = a;
1964 0 old_node = b;
1965
1966 0 ▶ if (!old_node)
Branch: 1 branch
BranchTrueFalseTotal
if (!old_node) 0 0 0
1967 0 ▶ sub_croak(cv, "%s is not of type %s", "old_node", "HTML5::DOM::Node");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "%s is not of type %s", "old_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "old_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "old_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "old_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "old_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "old_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "old_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "old_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "old_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "old_node", "HTML5::DOM::Node"); 0 0 0
sub_croak(cv, "%s is not of type %s", "old_node", "HTML5::DOM::Node"); 0 0 0
1968 0 ▶ if (old_node->parent != self)
Branch: 1 branch
BranchTrueFalseTotal
if (old_node->parent != self) 0 0 0
1969 0 ▶ sub_croak(cv, "The node to be replaced is not a child of this node.");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "The node to be replaced is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be replaced is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be replaced is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be replaced is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be replaced is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be replaced is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be replaced is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be replaced is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be replaced is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be replaced is not a child of this node."); 0 0 0
sub_croak(cv, "The node to be replaced is not a child of this node."); 0 0 0
1970 } else {
1971 0 new_node = a;
1972 0 old_node = self;
1973 }
1974
1975 0 ▶ if (old_node->tree != new_node->tree) {
Branch: 1 branch
BranchTrueFalseTotal
if (old_node->tree != new_node->tree) { 0 0 0
1976 0 myhtml_tree_node_remove(new_node);
1977 0 new_node = html5_dom_recursive_clone_node(old_node->tree, new_node, NULL);
1978 0 ▶ if (!new_node)
Branch: 1 branch
BranchTrueFalseTotal
if (!new_node) 0 0 0
1979 0 ▶ sub_croak(cv, "node copying internal error");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
sub_croak(cv, "node copying internal error"); 0 0 0
1980 }
1981
1982 0 ▶ if (html5_dom_is_fragment(new_node)) {
Branch: 1 branch
BranchTrueFalseTotal
if (html5_dom_is_fragment(new_node)) { 0 0 0
1983 0 myhtml_tree_node_t *fragment_child = myhtml_node_child(new_node);
1984 0 ▶ while (fragment_child) {
Branch: 1 branch
BranchTrueFalseTotal
while (fragment_child) { 0 0 0
1985 0 myhtml_tree_node_t *fragment_child = myhtml_node_child(new_node);
1986 0 ▶ while (fragment_child) {
Branch: 1 branch
BranchTrueFalseTotal
while (fragment_child) { 0 0 0
1987 0 myhtml_tree_node_t *next = myhtml_node_next(fragment_child);
1988 0 myhtml_tree_node_remove(fragment_child);
1989 0 myhtml_tree_node_insert_before(old_node, fragment_child);
1990 0 fragment_child = next;
1991 }
1992 }
1993 } else {
1994 0 myhtml_tree_node_remove(new_node);
1995 0 myhtml_tree_node_insert_before(old_node, new_node);
1996 }
1997
1998 0 myhtml_tree_node_remove(old_node);
1999
2000 0 ▶ RETVAL = (ix == 1 ? node_to_sv(old_node) : SvREFCNT_inc(ST(0)));
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (ix == 1 ? node_to_sv(old_node) : SvREFCNT_inc(ST(0))); 0 0 0
2001 OUTPUT:
2002 RETVAL
2003  
2004 # Clone node
2005 SV *
2006 clone(HTML5::DOM::Node self, bool deep = false, HTML5::DOM::Tree new_tree = NULL)
2007 ALIAS:
2008 cloneNode = 1
2009 CODE:
2010 0 ▶ myhtml_tree_t *tree = new_tree ? new_tree->tree : self->tree;
Branch: 1 branch
BranchTrueFalseTotal
myhtml_tree_t *tree = new_tree ? new_tree->tree : self->tree; 0 0 0
2011 0 ▶ if (deep) {
Branch: 1 branch
BranchTrueFalseTotal
if (deep) { 0 0 0
2012 0 RETVAL = node_to_sv(html5_dom_recursive_clone_node(tree, self, NULL));
2013 } else {
2014 0 RETVAL = node_to_sv(html5_dom_copy_foreign_node(tree, self));
2015 }
2016 OUTPUT:
2017 RETVAL
2018  
2019 # True if node is void
2020 bool
2021 void(HTML5::DOM::Node self)
2022 CODE:
2023 0 RETVAL = myhtml_node_is_void_element(self);
2024 OUTPUT:
2025 RETVAL
2026  
2027 # True if node is self-closed
2028 bool
2029 selfClosed(HTML5::DOM::Node self)
2030 CODE:
2031 0 RETVAL = myhtml_node_is_close_self(self);
2032 OUTPUT:
2033 RETVAL
2034  
2035 # Node position in text input
2036 SV *
2037 position(HTML5::DOM::Node self)
2038 CODE:
2039 0 HV *hash = newHV();
2040 0 ▶ hv_store_ent(hash, sv_2mortal(newSVpv("raw_begin", 9)), newSViv(self->token ? self->token->raw_begin : 0), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store_ent(hash, sv_2mortal(newSVpv("raw_begin", 9)), newSViv(self->token ? self->token->raw_begin : 0), 0); 0 0 0
2041 0 ▶ hv_store_ent(hash, sv_2mortal(newSVpv("raw_length", 10)), newSViv(self->token ? self->token->raw_length : 0), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store_ent(hash, sv_2mortal(newSVpv("raw_length", 10)), newSViv(self->token ? self->token->raw_length : 0), 0); 0 0 0
2042 0 ▶ hv_store_ent(hash, sv_2mortal(newSVpv("element_begin", 13)), newSViv(self->token ? self->token->element_begin : 0), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store_ent(hash, sv_2mortal(newSVpv("element_begin", 13)), newSViv(self->token ? self->token->element_begin : 0), 0); 0 0 0
2043 0 ▶ hv_store_ent(hash, sv_2mortal(newSVpv("element_length", 14)), newSViv(self->token ? self->token->element_length : 0), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store_ent(hash, sv_2mortal(newSVpv("element_length", 14)), newSViv(self->token ? self->token->element_length : 0), 0); 0 0 0
2044 0 RETVAL = newRV_noinc((SV *) hash);
2045 OUTPUT:
2046 RETVAL
2047  
2048 # Some bad idea to get "uniq id"
2049 SV *
2050 hash(HTML5::DOM::Node self)
2051 CODE:
2052 0 RETVAL = newSViv(PTR2IV(self));
2053 OUTPUT:
2054 RETVAL
2055  
2056 # Compare node reference
2057 bool
2058 isSameNode(HTML5::DOM::Node self, SV *other_node)
2059 CODE:
2060 0 RETVAL = false;
2061 0 ▶ if (sv_derived_from(other_node, "HTML5::DOM::Node")) {
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(other_node, "HTML5::DOM::Node")) { 0 0 0
2062 0 myhtml_tree_node_t *node = INT2PTR(myhtml_tree_node_t *, SvIV((SV*)SvRV(other_node)));
2063 0 ▶ if (node == self)
Branch: 1 branch
BranchTrueFalseTotal
if (node == self) 0 0 0
2064 0 RETVAL = true;
2065 }
2066 OUTPUT:
2067 RETVAL
2068  
2069 void
2070 DESTROY(HTML5::DOM::Node self)
2071 CODE:
2072 0 SV *sv = (SV *) myhtml_node_get_data(self);
2073
2074 DOM_GC_TRACE("DOM::Node::DESTROY (refcnt=%d)", sv ? SvREFCNT(sv) : -666);
2075
2076 0 ▶ if (sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (sv) { 0 0 0
2077 0 html5_dom_tree_t *tree = (html5_dom_tree_t *) self->tree->context;
2078 0 myhtml_node_set_data(self, NULL);
2079 // detached node, can be deleted
2080 0 ▶ if (!myhtml_node_parent(self) && self != myhtml_tree_get_document(self->tree)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!myhtml_node_parent(self) && self != myhtml_tree_get_document(self->tree)) { 0 0 0
if (!myhtml_node_parent(self) && self != myhtml_tree_get_document(self->tree)) { 0 0 0
2081 0 ▶ if (self == self->tree->node_html) {
Branch: 1 branch
BranchTrueFalseTotal
if (self == self->tree->node_html) { 0 0 0
2082 0 self->tree->node_html = NULL;
2083 0 ▶ } else if (self == self->tree->node_body) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (self == self->tree->node_body) { 0 0 0
2084 0 self->tree->node_body = NULL;
2085 0 ▶ } else if (self == self->tree->node_head) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (self == self->tree->node_head) { 0 0 0
2086 0 self->tree->node_head = NULL;
2087 0 ▶ } else if (self == self->tree->node_form) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (self == self->tree->node_form) { 0 0 0
2088 0 self->tree->node_form = NULL;
2089 0 ▶ } else if (self == self->tree->fragment) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (self == self->tree->fragment) { 0 0 0
2090 0 self->tree->fragment = NULL;
2091 0 ▶ } else if (self == self->tree->document) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (self == self->tree->document) { 0 0 0
2092 0 self->tree->document = NULL;
2093 }
2094 DOM_GC_TRACE("=> DOM::Node::FREE");
2095 0 html5_tree_node_delete_recursive(self);
2096 }
2097 0 SvREFCNT_dec(tree->sv);
2098 }
2099  
2100 #################################################################
2101 # HTML5::DOM::Element (extends Node)
2102 #################################################################
2103 MODULE = HTML5::DOM PACKAGE = HTML5::DOM::Element
2104 # Find by css query
2105 SV *
2106 find(HTML5::DOM::Element self, SV *query, SV *combinator = NULL)
2107 ALIAS:
2108 at = 1
2109 querySelector = 2
2110 querySelectorAll = 3
2111 CODE:
2112 0 html5_dom_tree_t *tree_context = (html5_dom_tree_t *) self->tree->context;
2113 0 ▶ RETVAL = html5_node_find(cv, tree_context->parser, self, query, combinator, ix == 1 || ix == 2);
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = html5_node_find(cv, tree_context->parser, self, query, combinator, ix == 1 || ix == 2); 0 0 0
RETVAL = html5_node_find(cv, tree_context->parser, self, query, combinator, ix == 1 || ix == 2); 0 0 0
2114 OUTPUT:
2115 RETVAL
2116  
2117 # findTag(val), getElementsByTagName(val) - get nodes by tag name
2118 # findClass(val), getElementsByClassName(val) - get nodes by class name
2119 # findId(val), getElementById(val) - get node by id
2120 # findAttr(key), getElementByAttribute(key) - get nodes by attribute key
2121 # findAttr(key, val, case, cmp), getElementByAttribute(key, val, case, cmp) - get nodes by attribute value
2122 SV *
2123 findTag(HTML5::DOM::Element self, SV *key, SV *val = NULL, bool icase = false, SV *cmp = NULL)
2124 ALIAS:
2125 getElementsByTagName = 1
2126 findClass = 2
2127 getElementsByClassName = 3
2128 findId = 4
2129 getElementById = 5
2130 findAttr = 6
2131 getElementByAttribute = 7
2132 CODE:
2133 0 RETVAL = html5_node_simple_find(cv, self, key, val, cmp, icase, ix);
2134 OUTPUT:
2135 RETVAL
2136  
2137 # First child element
2138 SV *
2139 first(HTML5::DOM::Element self)
2140 ALIAS:
2141 firstElementChild = 1
2142 CODE:
2143 0 myhtml_tree_node_t *node = myhtml_node_child(self);
2144 0 ▶ while (node && !node_is_element(node))
Branch: 5 branches
BranchTrueFalseTotal
while (node && !node_is_element(node)) 0 0 0
while (node && !node_is_element(node)) 0 0 0
while (node && !node_is_element(node)) 0 0 0
while (node && !node_is_element(node)) 0 0 0
while (node && !node_is_element(node)) 0 0 0
2145 0 node = myhtml_node_next(node);
2146 0 RETVAL = node_to_sv(node);
2147 OUTPUT:
2148 RETVAL
2149  
2150 # First child node
2151 SV *
2152 firstNode(HTML5::DOM::Element self)
2153 ALIAS:
2154 firstChild = 1
2155 CODE:
2156 0 RETVAL = node_to_sv(myhtml_node_child(self));
2157 OUTPUT:
2158 RETVAL
2159  
2160 # Last child element
2161 SV *
2162 last(HTML5::DOM::Element self)
2163 ALIAS:
2164 lastElementChild = 1
2165 CODE:
2166 0 myhtml_tree_node_t *node = myhtml_node_last_child(self);
2167 0 ▶ while (node && !node_is_element(node))
Branch: 5 branches
BranchTrueFalseTotal
while (node && !node_is_element(node)) 0 0 0
while (node && !node_is_element(node)) 0 0 0
while (node && !node_is_element(node)) 0 0 0
while (node && !node_is_element(node)) 0 0 0
while (node && !node_is_element(node)) 0 0 0
2168 0 node = myhtml_node_prev(node);
2169 0 RETVAL = node_to_sv(node);
2170 OUTPUT:
2171 RETVAL
2172  
2173 # Last child node
2174 SV *
2175 lastNode(HTML5::DOM::Element self)
2176 ALIAS:
2177 lastChild = 1
2178 CODE:
2179 0 RETVAL = node_to_sv(myhtml_node_last_child(self));
2180 OUTPUT:
2181 RETVAL
2182  
2183 # return all attributes in a array
2184 SV *
2185 attrArray(HTML5::DOM::Element self)
2186 CODE:
2187 0 AV *array = newAV();
2188
2189 0 myhtml_tree_attr_t *attr = myhtml_node_attribute_first(self);
2190 0 ▶ while (attr) {
Branch: 1 branch
BranchTrueFalseTotal
while (attr) { 0 0 0
2191 0 HV *hash = newHV();
2192
2193 0 size_t attr_key_len = 0;
2194 0 const char *attr_key = myhtml_attribute_key(attr, &attr_key_len);
2195
2196 0 size_t attr_val_len = 0;
2197 0 const char *attr_val = myhtml_attribute_value(attr, &attr_val_len);
2198
2199 0 size_t ns_len = 0;
2200 0 const char *ns_name = myhtml_namespace_name_by_id(myhtml_attribute_namespace(attr), &ns_len);
2201
2202 0 ▶ hv_store_ent(hash, sv_2mortal(newSVpv("name", 4)), newSVpv(attr_key ? attr_key : "", attr_key_len), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store_ent(hash, sv_2mortal(newSVpv("name", 4)), newSVpv(attr_key ? attr_key : "", attr_key_len), 0); 0 0 0
2203 0 ▶ hv_store_ent(hash, sv_2mortal(newSVpv("value", 5)), newSVpv(attr_val ? attr_val : "", attr_val_len), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store_ent(hash, sv_2mortal(newSVpv("value", 5)), newSVpv(attr_val ? attr_val : "", attr_val_len), 0); 0 0 0
2204 0 ▶ hv_store_ent(hash, sv_2mortal(newSVpv("namespace", 9)), newSVpv(ns_name ? ns_name : "", ns_len), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store_ent(hash, sv_2mortal(newSVpv("namespace", 9)), newSVpv(ns_name ? ns_name : "", ns_len), 0); 0 0 0
2205
2206 0 av_push(array, newRV_noinc((SV *) hash));
2207
2208 0 attr = myhtml_attribute_next(attr);
2209 }
2210
2211 0 RETVAL = newRV_noinc((SV *) array);
2212 OUTPUT:
2213 RETVAL
2214  
2215 # attr() - return all attributes in a hash
2216 # attr("key") - return value of attribute "key" (undef is not exists)
2217 # attr("key", "value") - set value for attribute "key" (return this)
2218 # attr({"key" => "value"}) - bulk set value for attribute "key" (return this)
2219 SV *
2220 attr(HTML5::DOM::Element self, SV *key = NULL, SV *value = NULL)
2221 ALIAS:
2222 setAttribute = 1
2223 getAttribute = 2
2224 CODE:
2225 0 RETVAL = &PL_sv_undef;
2226
2227 0 ▶ if (ix == 1) { // setAttribute
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) { // setAttribute 0 0 0
2228 0 ▶ if (!key)
Branch: 1 branch
BranchTrueFalseTotal
if (!key) 0 0 0
2229 0 ▶ sub_croak(cv, "attribute key required for setAttribute");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "attribute key required for setAttribute"); 0 0 0
sub_croak(cv, "attribute key required for setAttribute"); 0 0 0
sub_croak(cv, "attribute key required for setAttribute"); 0 0 0
sub_croak(cv, "attribute key required for setAttribute"); 0 0 0
sub_croak(cv, "attribute key required for setAttribute"); 0 0 0
sub_croak(cv, "attribute key required for setAttribute"); 0 0 0
sub_croak(cv, "attribute key required for setAttribute"); 0 0 0
sub_croak(cv, "attribute key required for setAttribute"); 0 0 0
sub_croak(cv, "attribute key required for setAttribute"); 0 0 0
sub_croak(cv, "attribute key required for setAttribute"); 0 0 0
sub_croak(cv, "attribute key required for setAttribute"); 0 0 0
2230
2231 0 ▶ if (!value)
Branch: 1 branch
BranchTrueFalseTotal
if (!value) 0 0 0
2232 0 ▶ sub_croak(cv, "attribute value required for setAttribute");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "attribute value required for setAttribute"); 0 0 0
sub_croak(cv, "attribute value required for setAttribute"); 0 0 0
sub_croak(cv, "attribute value required for setAttribute"); 0 0 0
sub_croak(cv, "attribute value required for setAttribute"); 0 0 0
sub_croak(cv, "attribute value required for setAttribute"); 0 0 0
sub_croak(cv, "attribute value required for setAttribute"); 0 0 0
sub_croak(cv, "attribute value required for setAttribute"); 0 0 0
sub_croak(cv, "attribute value required for setAttribute"); 0 0 0
sub_croak(cv, "attribute value required for setAttribute"); 0 0 0
sub_croak(cv, "attribute value required for setAttribute"); 0 0 0
sub_croak(cv, "attribute value required for setAttribute"); 0 0 0
2233 0 ▶ } else if (ix == 2) { // getAttribute
Branch: 1 branch
BranchTrueFalseTotal
} else if (ix == 2) { // getAttribute 0 0 0
2234 0 ▶ if (!key)
Branch: 1 branch
BranchTrueFalseTotal
if (!key) 0 0 0
2235 0 ▶ sub_croak(cv, "attribute key required for getAttribute");
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "attribute key required for getAttribute"); 0 0 0
sub_croak(cv, "attribute key required for getAttribute"); 0 0 0
sub_croak(cv, "attribute key required for getAttribute"); 0 0 0
sub_croak(cv, "attribute key required for getAttribute"); 0 0 0
sub_croak(cv, "attribute key required for getAttribute"); 0 0 0
sub_croak(cv, "attribute key required for getAttribute"); 0 0 0
sub_croak(cv, "attribute key required for getAttribute"); 0 0 0
sub_croak(cv, "attribute key required for getAttribute"); 0 0 0
sub_croak(cv, "attribute key required for getAttribute"); 0 0 0
sub_croak(cv, "attribute key required for getAttribute"); 0 0 0
sub_croak(cv, "attribute key required for getAttribute"); 0 0 0
2236
2237 0 key = sv_stringify(key);
2238 0 value = NULL;
2239 }
2240
2241 0 ▶ if (key && value) { // Set value by key or delete by key
Branch: 2 branches
BranchTrueFalseTotal
if (key && value) { // Set value by key or delete by key 0 0 0
if (key && value) { // Set value by key or delete by key 0 0 0
2242 0 key = sv_stringify(key);
2243 0 value = sv_stringify(value);
2244
2245 0 STRLEN key_len = 0;
2246 0 const char *key_str = SvPV_const(key, key_len);
2247
2248 0 ▶ if (key_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (key_len) { 0 0 0
2249 // if value is undef - only remove attribute
2250 0 ▶ if (SvTYPE(value) != SVt_NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(value) != SVt_NULL) { 0 0 0
2251 0 STRLEN val_len = 0;
2252 0 const char *val_str = SvPV_const(value, val_len);
2253 0 html5_dom_replace_attr_value(self, key_str, key_len, val_str, val_len, MyENCODING_DEFAULT);
2254 } else {
2255 0 myhtml_attribute_remove_by_key(self, key_str, key_len);
2256 }
2257 }
2258
2259 // return self
2260 0 RETVAL = SvREFCNT_inc(ST(0));
2261 0 ▶ } else if (key && !value) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (key && !value) { 0 0 0
} else if (key && !value) { 0 0 0
2262 // Bulk attr set
2263 0 ▶ if (SvROK(key) && SvTYPE(SvRV(key)) == SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(key) && SvTYPE(SvRV(key)) == SVt_PVHV) { 0 0 0
if (SvROK(key) && SvTYPE(SvRV(key)) == SVt_PVHV) { 0 0 0
2264 HE *entry;
2265 0 HV *hash = (HV *) SvRV(key);
2266
2267 0 ▶ while ((entry = hv_iternext(hash)) != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
while ((entry = hv_iternext(hash)) != NULL) { 0 0 0
2268 0 SV *value = hv_iterval(hash, entry);
2269 I32 key_len;
2270 0 const char *key_name = hv_iterkey(entry, &key_len);
2271 0 ▶ if (value && key_len) {
Branch: 2 branches
BranchTrueFalseTotal
if (value && key_len) { 0 0 0
if (value && key_len) { 0 0 0
2272 0 value = sv_stringify(value);
2273
2274 // if value is undef - only remove attribute
2275 0 ▶ if (SvTYPE(value) != SVt_NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(value) != SVt_NULL) { 0 0 0
2276 0 STRLEN val_len = 0;
2277 0 const char *val_str = SvPV_const(value, val_len);
2278 0 html5_dom_replace_attr_value(self, key_name, key_len, val_str, val_len, MyENCODING_DEFAULT);
2279 } else {
2280 0 myhtml_attribute_remove_by_key(self, key_name, key_len);
2281 }
2282 }
2283 }
2284
2285 0 RETVAL = SvREFCNT_inc(ST(0));
2286 }
2287 // Get attribute by key
2288 else {
2289 0 key = sv_stringify(key);
2290
2291 0 STRLEN key_len = 0;
2292 0 const char *key_str = SvPV_const(key, key_len);
2293
2294 0 ▶ if (key_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (key_len) { 0 0 0
2295 0 myhtml_tree_attr_t *attr = myhtml_attribute_by_key(self, key_str, key_len);
2296 0 ▶ if (attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (attr) { 0 0 0
2297 0 size_t attr_val_len = 0;
2298 0 const char *attr_val = myhtml_attribute_value(attr, &attr_val_len);
2299 0 ▶ RETVAL = newSVpv(attr_val ? attr_val : "", attr_val_len);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = newSVpv(attr_val ? attr_val : "", attr_val_len); 0 0 0
2300 }
2301 }
2302 }
2303 } else { // Return all attributes in hash
2304 0 HV *hash = newHV();
2305
2306 0 myhtml_tree_attr_t *attr = myhtml_node_attribute_first(self);
2307 0 ▶ while (attr) {
Branch: 1 branch
BranchTrueFalseTotal
while (attr) { 0 0 0
2308 0 size_t attr_key_len = 0;
2309 0 const char *attr_key = myhtml_attribute_key(attr, &attr_key_len);
2310
2311 0 size_t attr_val_len = 0;
2312 0 const char *attr_val = myhtml_attribute_value(attr, &attr_val_len);
2313
2314 0 ▶ hv_store_ent(hash, sv_2mortal(newSVpv(attr_key ? attr_key : "", attr_key_len)), newSVpv(attr_val ? attr_val : "", attr_val_len), 0);
Branch: 2 branches
BranchTrueFalseTotal
hv_store_ent(hash, sv_2mortal(newSVpv(attr_key ? attr_key : "", attr_key_len)), newSVpv(attr_val ? attr_val : "", attr_val_len), 0); 0 0 0
hv_store_ent(hash, sv_2mortal(newSVpv(attr_key ? attr_key : "", attr_key_len)), newSVpv(attr_val ? attr_val : "", attr_val_len), 0); 0 0 0
2315
2316 0 attr = myhtml_attribute_next(attr);
2317 }
2318
2319 0 RETVAL = newRV_noinc((SV *) hash);
2320 }
2321 OUTPUT:
2322 RETVAL
2323  
2324 # Remove attribute by key
2325 SV *
2326 removeAttr(HTML5::DOM::Element self, SV *key = NULL)
2327 ALIAS:
2328 removeAttribute = 1
2329 CODE:
2330 0 key = sv_stringify(key);
2331
2332 0 STRLEN key_len = 0;
2333 0 const char *key_str = SvPV_const(key, key_len);
2334
2335 0 ▶ if (key_len)
Branch: 1 branch
BranchTrueFalseTotal
if (key_len) 0 0 0
2336 0 myhtml_attribute_remove_by_key(self, key_str, key_len);
2337
2338 0 RETVAL = SvREFCNT_inc(ST(0));
2339 OUTPUT:
2340 RETVAL
2341  
2342 # Return collection with children elements
2343 SV *
2344 children(HTML5::DOM::Element self)
2345 CODE:
2346 0 myhtml_tree_node_t *child = myhtml_node_child(self);
2347 0 AV *arr = newAV();
2348
2349 0 ▶ while (child) {
Branch: 1 branch
BranchTrueFalseTotal
while (child) { 0 0 0
2350 0 ▶ if (node_is_element(child))
Branch: 4 branches
BranchTrueFalseTotal
if (node_is_element(child)) 0 0 0
if (node_is_element(child)) 0 0 0
if (node_is_element(child)) 0 0 0
if (node_is_element(child)) 0 0 0
2351 0 av_push(arr, node_to_sv(child));
2352 0 child = myhtml_node_next(child);
2353 }
2354
2355 0 RETVAL = sv_bless(newRV_noinc((SV *) arr), gv_stashpv("HTML5::DOM::Collection", 0));
2356 OUTPUT:
2357 RETVAL
2358  
2359 # Return collection with children nodes
2360 SV *
2361 childrenNode(HTML5::DOM::Element self)
2362 ALIAS:
2363 childNodes = 1
2364 CODE:
2365 0 myhtml_tree_node_t *child = myhtml_node_child(self);
2366 0 AV *arr = newAV();
2367
2368 0 ▶ while (child) {
Branch: 1 branch
BranchTrueFalseTotal
while (child) { 0 0 0
2369 0 av_push(arr, node_to_sv(child));
2370 0 child = myhtml_node_next(child);
2371 }
2372
2373 0 RETVAL = sv_bless(newRV_noinc((SV *) arr), gv_stashpv("HTML5::DOM::Collection", 0));
2374 OUTPUT:
2375 RETVAL
2376  
2377 # Return default display property for tag
2378 SV *
2379 getDefaultBoxType(HTML5::DOM::Element self)
2380 CODE:
2381 0 const char *ret = NULL;
2382 0 switch (html5_dom_get_ua_display_prop(self)) {
2383 0 case TAG_UA_STYLE_NONE:
2384 0 ret = "none";
2385 0 break;
2386 0 case TAG_UA_STYLE_INLINE:
2387 0 ret = "inline";
2388 0 break;
2389 0 case TAG_UA_STYLE_BLOCK:
2390 0 ret = "block";
2391 0 break;
2392 0 case TAG_UA_STYLE_INLINE_BLOCK:
2393 0 ret = "inline-block";
2394 0 break;
2395 0 case TAG_UA_STYLE_LIST_ITEM:
2396 0 ret = "list-item";
2397 0 break;
2398 0 case TAG_UA_STYLE_TABLE:
2399 0 ret = "table";
2400 0 break;
2401 0 case TAG_UA_STYLE_TABLE_CAPTION:
2402 0 ret = "table-caption";
2403 0 break;
2404 0 case TAG_UA_STYLE_TABLE_CELL:
2405 0 ret = "table-cell";
2406 0 break;
2407 0 case TAG_UA_STYLE_TABLE_COLUMN:
2408 0 ret = "table-column";
2409 0 break;
2410 0 case TAG_UA_STYLE_TABLE_COLUMN_GROUP:
2411 0 ret = "table-column-group";
2412 0 break;
2413 0 case TAG_UA_STYLE_TABLE_HEADER_GROUP:
2414 0 ret = "table-header-group";
2415 0 break;
2416 0 case TAG_UA_STYLE_TABLE_FOOTER_GROUP:
2417 0 ret = "table-footer-group";
2418 0 break;
2419 0 case TAG_UA_STYLE_TABLE_ROW:
2420 0 ret = "table-row";
2421 0 break;
2422 0 case TAG_UA_STYLE_TABLE_ROW_GROUP:
2423 0 ret = "table-row-group";
2424 0 break;
2425 0 case TAG_UA_STYLE_RUBY:
2426 0 ret = "ruby";
2427 0 break;
2428 0 case TAG_UA_STYLE_RUBY_BASE:
2429 0 ret = "ruby-base";
2430 0 break;
2431 0 case TAG_UA_STYLE_RUBY_TEXT:
2432 0 ret = "ruby-text";
2433 0 break;
2434 0 case TAG_UA_STYLE_RUBY_TEXT_CONTAINER:
2435 0 ret = "ruby-text-container";
2436 0 break;
2437 }
2438
2439 0 ▶ RETVAL = ret ? newSVpv(ret, strlen(ret)) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ret ? newSVpv(ret, strlen(ret)) : &PL_sv_undef; 0 0 0
2440 OUTPUT:
2441 RETVAL
2442  
2443 #################################################################
2444 # HTML5::DOM::DocType (extends Node)
2445 #################################################################
2446 MODULE = HTML5::DOM PACKAGE = HTML5::DOM::DocType
2447 SV *name(HTML5::DOM::DocType self, SV *value = NULL)
2448 ALIAS:
2449 publicId = 1
2450 systemId = 2
2451 CODE:
2452 static const char *TYPE_SYSTEM = "SYSTEM";
2453 static const char *TYPE_PUBLIC = "PUBLIC";
2454
2455 0 ▶ myhtml_tree_attr_t *root_name = self->token ? self->token->attr_first : NULL;
Branch: 1 branch
BranchTrueFalseTotal
myhtml_tree_attr_t *root_name = self->token ? self->token->attr_first : NULL; 0 0 0
2456 0 ▶ myhtml_tree_attr_t *restrict_type = root_name ? root_name->next : NULL;
Branch: 1 branch
BranchTrueFalseTotal
myhtml_tree_attr_t *restrict_type = root_name ? root_name->next : NULL; 0 0 0
2457 0 ▶ myhtml_tree_attr_t *public_id = restrict_type ? restrict_type->next : NULL;
Branch: 1 branch
BranchTrueFalseTotal
myhtml_tree_attr_t *public_id = restrict_type ? restrict_type->next : NULL; 0 0 0
2458 0 ▶ myhtml_tree_attr_t *system_id = public_id ? public_id->next : NULL;
Branch: 1 branch
BranchTrueFalseTotal
myhtml_tree_attr_t *system_id = public_id ? public_id->next : NULL; 0 0 0
2459
2460 0 ▶ if (restrict_type && restrict_type->value.length == 6) {
Branch: 2 branches
BranchTrueFalseTotal
if (restrict_type && restrict_type->value.length == 6) { 0 0 0
if (restrict_type && restrict_type->value.length == 6) { 0 0 0
2461 0 ▶ if (mycore_strcasecmp(restrict_type->value.data, "SYSTEM") == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (mycore_strcasecmp(restrict_type->value.data, "SYSTEM") == 0) { 0 0 0
2462 0 system_id = public_id;
2463 0 public_id = NULL;
2464 }
2465 }
2466
2467 0 ▶ if (value) {
Branch: 1 branch
BranchTrueFalseTotal
if (value) { 0 0 0
2468 0 value = sv_stringify(value);
2469
2470 0 ▶ myhtml_tree_attr_t *attr_first = self->token ? self->token->attr_first : NULL;
Branch: 1 branch
BranchTrueFalseTotal
myhtml_tree_attr_t *attr_first = self->token ? self->token->attr_first : NULL; 0 0 0
2471 0 ▶ myhtml_tree_attr_t *attr_last = self->token ? self->token->attr_last : NULL;
Branch: 1 branch
BranchTrueFalseTotal
myhtml_tree_attr_t *attr_last = self->token ? self->token->attr_last : NULL; 0 0 0
2472
2473 0 STRLEN val_len = 0;
2474 0 const char *val_str = SvPV_const(value, val_len);
2475
2476 // root element name
2477 0 ▶ if (ix == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 0) { 0 0 0
2478 0 myhtml_attribute_add(self, val_str, val_len, "", 0, MyENCODING_DEFAULT);
2479 } else {
2480 0 ▶ myhtml_attribute_add(self, root_name && root_name->key.data ? root_name->key.data : "", root_name ? root_name->key.length : 0, "", 0, MyENCODING_DEFAULT);
Branch: 3 branches
BranchTrueFalseTotal
myhtml_attribute_add(self, root_name && root_name->key.data ? root_name->key.data : "", root_name ? root_name->key.length : 0, "", 0, MyENCODING_DEFAULT); 0 0 0
myhtml_attribute_add(self, root_name && root_name->key.data ? root_name->key.data : "", root_name ? root_name->key.length : 0, "", 0, MyENCODING_DEFAULT); 0 0 0
myhtml_attribute_add(self, root_name && root_name->key.data ? root_name->key.data : "", root_name ? root_name->key.length : 0, "", 0, MyENCODING_DEFAULT); 0 0 0
2481 }
2482
2483 0 const char *restrict_type_str = NULL;
2484
2485 0 ▶ if ((ix == 2 && val_len) || (system_id && system_id->value.length))
Branch: 4 branches
BranchTrueFalseTotal
if ((ix == 2 && val_len) || (system_id && system_id->value.length)) 0 0 0
if ((ix == 2 && val_len) || (system_id && system_id->value.length)) 0 0 0
if ((ix == 2 && val_len) || (system_id && system_id->value.length)) 0 0 0
if ((ix == 2 && val_len) || (system_id && system_id->value.length)) 0 0 0
2486 0 restrict_type_str = TYPE_SYSTEM;
2487
2488 0 ▶ if ((ix == 1 && val_len) || (public_id && public_id->value.length))
Branch: 4 branches
BranchTrueFalseTotal
if ((ix == 1 && val_len) || (public_id && public_id->value.length)) 0 0 0
if ((ix == 1 && val_len) || (public_id && public_id->value.length)) 0 0 0
if ((ix == 1 && val_len) || (public_id && public_id->value.length)) 0 0 0
if ((ix == 1 && val_len) || (public_id && public_id->value.length)) 0 0 0
2489 0 restrict_type_str = TYPE_PUBLIC;
2490
2491 0 ▶ if (restrict_type_str) {
Branch: 1 branch
BranchTrueFalseTotal
if (restrict_type_str) { 0 0 0
2492 // SYSTEM or PUBLIC
2493 0 myhtml_attribute_add(self, "", 0, restrict_type_str, 6, MyENCODING_DEFAULT);
2494
2495 0 ▶ if (restrict_type_str == TYPE_PUBLIC) {
Branch: 1 branch
BranchTrueFalseTotal
if (restrict_type_str == TYPE_PUBLIC) { 0 0 0
2496 // publicId
2497 0 ▶ if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) { 0 0 0
2498 0 myhtml_attribute_add(self, "", 0, val_str, val_len, MyENCODING_DEFAULT);
2499 } else {
2500 0 ▶ myhtml_attribute_add(self, "", 0, public_id && public_id->value.data ? public_id->value.data : "", public_id ? public_id->value.length : 0, MyENCODING_DEFAULT);
Branch: 3 branches
BranchTrueFalseTotal
myhtml_attribute_add(self, "", 0, public_id && public_id->value.data ? public_id->value.data : "", public_id ? public_id->value.length : 0, MyENCODING_DEFAULT); 0 0 0
myhtml_attribute_add(self, "", 0, public_id && public_id->value.data ? public_id->value.data : "", public_id ? public_id->value.length : 0, MyENCODING_DEFAULT); 0 0 0
myhtml_attribute_add(self, "", 0, public_id && public_id->value.data ? public_id->value.data : "", public_id ? public_id->value.length : 0, MyENCODING_DEFAULT); 0 0 0
2501 }
2502 }
2503
2504 // systemId
2505 0 ▶ if (ix == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 2) { 0 0 0
2506 0 myhtml_attribute_add(self, "", 0, val_str, val_len, MyENCODING_DEFAULT);
2507 } else {
2508 0 ▶ myhtml_attribute_add(self, "", 0, system_id && system_id->value.data ? system_id->value.data : "", system_id ? system_id->value.length : 0, MyENCODING_DEFAULT);
Branch: 3 branches
BranchTrueFalseTotal
myhtml_attribute_add(self, "", 0, system_id && system_id->value.data ? system_id->value.data : "", system_id ? system_id->value.length : 0, MyENCODING_DEFAULT); 0 0 0
myhtml_attribute_add(self, "", 0, system_id && system_id->value.data ? system_id->value.data : "", system_id ? system_id->value.length : 0, MyENCODING_DEFAULT); 0 0 0
myhtml_attribute_add(self, "", 0, system_id && system_id->value.data ? system_id->value.data : "", system_id ? system_id->value.length : 0, MyENCODING_DEFAULT); 0 0 0
2509 }
2510 }
2511
2512 // remove old
2513 0 ▶ while (attr_last && attr_first) {
Branch: 2 branches
BranchTrueFalseTotal
while (attr_last && attr_first) { 0 0 0
while (attr_last && attr_first) { 0 0 0
2514 0 myhtml_tree_attr_t *next = attr_first->next;
2515 0 myhtml_attribute_delete(self->tree, self, attr_first);
2516
2517 0 ▶ if (attr_first == attr_last)
Branch: 1 branch
BranchTrueFalseTotal
if (attr_first == attr_last) 0 0 0
2518 0 break;
2519
2520 0 attr_first = next;
2521 }
2522
2523 0 RETVAL = SvREFCNT_inc(ST(0));
2524 } else {
2525 0 RETVAL = &PL_sv_undef;
2526
2527 0 switch (ix) {
2528 0 case 0: /* name */
2529 0 ▶ RETVAL = newSVpv(root_name && root_name->key.data ? root_name->key.data : "", root_name ? root_name->key.length : 0);
Branch: 3 branches
BranchTrueFalseTotal
RETVAL = newSVpv(root_name && root_name->key.data ? root_name->key.data : "", root_name ? root_name->key.length : 0); 0 0 0
RETVAL = newSVpv(root_name && root_name->key.data ? root_name->key.data : "", root_name ? root_name->key.length : 0); 0 0 0
RETVAL = newSVpv(root_name && root_name->key.data ? root_name->key.data : "", root_name ? root_name->key.length : 0); 0 0 0
2530 0 break;
2531
2532 0 case 1: /* publicId */
2533 0 ▶ RETVAL = newSVpv(public_id && public_id->value.data ? public_id->value.data : "", public_id ? public_id->value.length : 0);
Branch: 3 branches
BranchTrueFalseTotal
RETVAL = newSVpv(public_id && public_id->value.data ? public_id->value.data : "", public_id ? public_id->value.length : 0); 0 0 0
RETVAL = newSVpv(public_id && public_id->value.data ? public_id->value.data : "", public_id ? public_id->value.length : 0); 0 0 0
RETVAL = newSVpv(public_id && public_id->value.data ? public_id->value.data : "", public_id ? public_id->value.length : 0); 0 0 0
2534 0 break;
2535
2536 0 case 2: /* systemId */
2537 0 ▶ RETVAL = newSVpv(system_id && system_id->value.data ? system_id->value.data : "", system_id ? system_id->value.length : 0);
Branch: 3 branches
BranchTrueFalseTotal
RETVAL = newSVpv(system_id && system_id->value.data ? system_id->value.data : "", system_id ? system_id->value.length : 0); 0 0 0
RETVAL = newSVpv(system_id && system_id->value.data ? system_id->value.data : "", system_id ? system_id->value.length : 0); 0 0 0
RETVAL = newSVpv(system_id && system_id->value.data ? system_id->value.data : "", system_id ? system_id->value.length : 0); 0 0 0
2538 0 break;
2539 }
2540 }
2541 OUTPUT:
2542 RETVAL
2543  
2544 #################################################################
2545 # HTML5::DOM::CSS (Parser)
2546 #################################################################
2547 MODULE = HTML5::DOM PACKAGE = HTML5::DOM::CSS
2548 HTML5::DOM::CSS
2549 new(SV *CLASS)
2550 CODE:
2551 DOM_GC_TRACE("DOM::CSS::new");
2552 mystatus_t status;
2553
2554 0 mycss_t *mycss = mycss_create();
2555 0 status = mycss_init(mycss);
2556 0 ▶ if (status) {
Branch: 1 branch
BranchTrueFalseTotal
if (status) { 0 0 0
2557 0 mycss_destroy(mycss, 1);
2558 0 ▶ sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
2559 }
2560
2561 0 mycss_entry_t *entry = mycss_entry_create();
2562 0 status = mycss_entry_init(mycss, entry);
2563 0 ▶ if (status) {
Branch: 1 branch
BranchTrueFalseTotal
if (status) { 0 0 0
2564 0 mycss_destroy(mycss, 1);
2565 0 mycss_entry_destroy(entry, 1);
2566 0 ▶ sub_croak(cv, "mycss_entry_init failed: %d (%s)", status, modest_strerror(status));
Branch: 11 branches
BranchTrueFalseTotal
sub_croak(cv, "mycss_entry_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_entry_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_entry_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_entry_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_entry_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_entry_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_entry_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_entry_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_entry_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_entry_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
sub_croak(cv, "mycss_entry_init failed: %d (%s)", status, modest_strerror(status)); 0 0 0
2567 }
2568
2569 0 html5_css_parser_t *self = (html5_css_parser_t *) safemalloc(sizeof(html5_css_parser_t));
2570 0 self->mycss = mycss;
2571 0 self->entry = entry;
2572 0 self->encoding = MyENCODING_UTF_8;
2573 0 RETVAL = self;
2574 OUTPUT:
2575 RETVAL
2576  
2577 # Parse css selector
2578 SV *
2579 parseSelector(HTML5::DOM::CSS self, SV *query)
2580 CODE:
2581 mystatus_t status;
2582
2583 0 query = sv_stringify(query);
2584
2585 STRLEN query_len;
2586 0 const char *query_str = SvPV_const(query, query_len);
2587
2588 0 mycss_selectors_list_t *list = mycss_selectors_parse(mycss_entry_selectors(self->entry), MyENCODING_UTF_8, query_str, query_len, &status);
2589
2590 DOM_GC_TRACE("DOM::CSS::Selector::NEW");
2591 0 html5_css_selector_t *selector = (html5_css_selector_t *) safemalloc(sizeof(html5_css_selector_t));
2592 0 selector->parent = SvRV(ST(0));
2593 0 selector->list = list;
2594 0 selector->parser = self;
2595 0 SvREFCNT_inc(selector->parent);
2596 0 RETVAL = pack_pointer("HTML5::DOM::CSS::Selector", selector);
2597 OUTPUT:
2598 RETVAL
2599  
2600 void
2601 DESTROY(HTML5::DOM::CSS self)
2602 CODE:
2603 DOM_GC_TRACE("DOM::CSS::DESTROY (refs=%d)", SvREFCNT(SvRV(ST(0))));
2604 0 mycss_entry_destroy(self->entry, 1);
2605 0 mycss_destroy(self->mycss, 1);
2606 0 safefree(self);
2607  
2608  
2609 #################################################################
2610 # HTML5::DOM::CSS::Selector
2611 #################################################################
2612 MODULE = HTML5::DOM PACKAGE = HTML5::DOM::CSS::Selector
2613  
2614 # Serialize selector to text
2615 SV *
2616 text(HTML5::DOM::CSS::Selector self)
2617 CODE:
2618 0 RETVAL = newSVpv("", 0);
2619 0 ▶ if (self->list)
Branch: 1 branch
BranchTrueFalseTotal
if (self->list) 0 0 0
2620 0 mycss_selectors_serialization_list(mycss_entry_selectors(self->parser->entry), self->list, sv_serialization_callback, RETVAL);
2621 OUTPUT:
2622 RETVAL
2623  
2624 # True, if selector is valid
2625 bool
2626 valid(HTML5::DOM::CSS::Selector self)
2627 CODE:
2628 0 ▶ RETVAL = self->list ? !(self->list->flags & MyCSS_SELECTORS_FLAGS_SELECTOR_BAD) : 0;
Branch: 3 branches
BranchTrueFalseTotal
RETVAL = self->list ? !(self->list->flags & MyCSS_SELECTORS_FLAGS_SELECTOR_BAD) : 0; 0 0 0
RETVAL = self->list ? !(self->list->flags & MyCSS_SELECTORS_FLAGS_SELECTOR_BAD) : 0; 0 0 0
RETVAL = self->list ? !(self->list->flags & MyCSS_SELECTORS_FLAGS_SELECTOR_BAD) : 0; 0 0 0
2629 OUTPUT:
2630 RETVAL
2631  
2632 # Return AST tree
2633 SV *
2634 ast(HTML5::DOM::CSS::Selector self)
2635 CODE:
2636 0 AV *result = newAV();
2637 0 ▶ if (self->list)
Branch: 1 branch
BranchTrueFalseTotal
if (self->list) 0 0 0
2638 0 html5_dom_css_serialize_selector(self->list, result);
2639 0 RETVAL = newRV_noinc((SV *) result);
2640 OUTPUT:
2641 RETVAL
2642  
2643 # Get count of selector entries
2644 int
2645 length(HTML5::DOM::CSS::Selector self)
2646 CODE:
2647 0 ▶ RETVAL = self->list ? self->list->entries_list_length : 0;
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = self->list ? self->list->entries_list_length : 0; 0 0 0
RETVAL = self->list ? self->list->entries_list_length : 0; 0 0 0
2648 OUTPUT:
2649 RETVAL
2650  
2651 # Get selector entry by index
2652 SV *
2653 entry(HTML5::DOM::CSS::Selector self, int index)
2654 CODE:
2655 0 ▶ if (!self->list || index < 0 || index >= self->list->entries_list_length) {
Branch: 3 branches
BranchTrueFalseTotal
if (!self->list || index < 0 || index >= self->list->entries_list_length) { 0 0 0
if (!self->list || index < 0 || index >= self->list->entries_list_length) { 0 0 0
if (!self->list || index < 0 || index >= self->list->entries_list_length) { 0 0 0
2656 0 RETVAL = &PL_sv_undef;
2657 } else {
2658 DOM_GC_TRACE("DOM::CSS::Selector::Entry::NEW");
2659 0 html5_css_selector_entry_t *entry = (html5_css_selector_entry_t *) safemalloc(sizeof(html5_css_selector_entry_t));
2660 0 entry->parent = SvRV(ST(0));
2661 0 entry->selector = self;
2662 0 entry->list = &self->list->entries_list[index];
2663 0 SvREFCNT_inc(entry->parent);
2664 0 RETVAL = pack_pointer("HTML5::DOM::CSS::Selector::Entry", entry);
2665 }
2666 OUTPUT:
2667 RETVAL
2668  
2669 void
2670 DESTROY(HTML5::DOM::CSS::Selector self)
2671 CODE:
2672 DOM_GC_TRACE("DOM::CSS::Selector::DESTROY (refs=%d)", SvREFCNT(SvRV(ST(0))));
2673 0 ▶ if (self->list)
Branch: 1 branch
BranchTrueFalseTotal
if (self->list) 0 0 0
2674 0 mycss_selectors_list_destroy(mycss_entry_selectors(self->parser->entry), self->list, true);
2675 0 SvREFCNT_dec(self->parent);
2676 0 safefree(self);
2677  
2678  
2679 #################################################################
2680 # HTML5::DOM::CSS::Selector::Entry
2681 #################################################################
2682 MODULE = HTML5::DOM PACKAGE = HTML5::DOM::CSS::Selector::Entry
2683  
2684 # Serialize selector to text
2685 SV *
2686 text(HTML5::DOM::CSS::Selector::Entry self)
2687 CODE:
2688 0 RETVAL = newSVpv("", 0);
2689 0 mycss_selectors_serialization_chain(mycss_entry_selectors(self->selector->parser->entry), self->list->entry, sv_serialization_callback, RETVAL);
2690 OUTPUT:
2691 RETVAL
2692  
2693 # Return AST tree
2694 SV *
2695 ast(HTML5::DOM::CSS::Selector::Entry self)
2696 CODE:
2697 0 AV *result = newAV();
2698 0 html5_dom_css_serialize_entry(self->selector->list, self->list->entry, result);
2699 0 RETVAL = newRV_noinc((SV *) result);
2700 OUTPUT:
2701 RETVAL
2702  
2703 # Return pseudo-element name
2704 SV *
2705 pseudoElement(HTML5::DOM::CSS::Selector::Entry self)
2706 CODE:
2707 0 mycss_selectors_entry_t *entry = self->list->entry;
2708 0 RETVAL = &PL_sv_undef;
2709 0 ▶ while (entry) {
Branch: 1 branch
BranchTrueFalseTotal
while (entry) { 0 0 0
2710 0 ▶ if (entry->type == MyCSS_SELECTORS_TYPE_PSEUDO_ELEMENT) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry->type == MyCSS_SELECTORS_TYPE_PSEUDO_ELEMENT) { 0 0 0
2711 0 ▶ RETVAL = newSVpv(entry->key->data ? entry->key->data : "", entry->key->length);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = newSVpv(entry->key->data ? entry->key->data : "", entry->key->length); 0 0 0
2712 0 break;
2713 }
2714 0 entry = entry->next;
2715 }
2716 OUTPUT:
2717 RETVAL
2718  
2719 # True, if selector is valid
2720 bool
2721 valid(HTML5::DOM::CSS::Selector::Entry self)
2722 CODE:
2723 0 ▶ RETVAL = !(self->selector->list->flags & MyCSS_SELECTORS_FLAGS_SELECTOR_BAD);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = !(self->selector->list->flags & MyCSS_SELECTORS_FLAGS_SELECTOR_BAD); 0 0 0
2724 OUTPUT:
2725 RETVAL
2726  
2727 # Return selector specificity in hash {a, b, c}
2728 SV *
2729 specificity(HTML5::DOM::CSS::Selector::Entry self)
2730 CODE:
2731 0 HV *hash = newHV();
2732 0 hv_store_ent(hash, sv_2mortal(newSVpv("a", 1)), newSViv(self->list->specificity.a), 0);
2733 0 hv_store_ent(hash, sv_2mortal(newSVpv("b", 1)), newSViv(self->list->specificity.b), 0);
2734 0 hv_store_ent(hash, sv_2mortal(newSVpv("c", 1)), newSViv(self->list->specificity.c), 0);
2735 0 RETVAL = newRV_noinc((SV *) hash);
2736 OUTPUT:
2737 RETVAL
2738  
2739 # Return selector specificity in array [a, b, c]
2740 SV *
2741 specificityArray(HTML5::DOM::CSS::Selector::Entry self)
2742 CODE:
2743 0 AV *arr = newAV();
2744 0 av_push(arr, newSViv(self->list->specificity.a));
2745 0 av_push(arr, newSViv(self->list->specificity.b));
2746 0 av_push(arr, newSViv(self->list->specificity.c));
2747 0 RETVAL = newRV_noinc((SV *) arr);
2748 OUTPUT:
2749 RETVAL
2750  
2751 void
2752 DESTROY(HTML5::DOM::CSS::Selector::Entry self)
2753 CODE:
2754 DOM_GC_TRACE("DOM::CSS::Selector::Entry::DESTROY (refs=%d)", SvREFCNT(SvRV(ST(0))));
2755 0 SvREFCNT_dec(self->parent);
2756 0 safefree(self);
2757  
2758 #################################################################
2759 # HTML5::DOM::Encoding
2760 #################################################################
2761 MODULE = HTML5::DOM PACKAGE = HTML5::DOM::Encoding
2762  
2763 SV *
2764 id2name(int id)
2765 CODE:
2766 0 size_t len = 0;
2767 0 const char *name = myencoding_name_by_id(id, &len);
2768 0 ▶ RETVAL = name ? newSVpv(name, len) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = name ? newSVpv(name, len) : &PL_sv_undef; 0 0 0
2769 OUTPUT:
2770 RETVAL
2771  
2772 SV *
2773 name2id(SV *text)
2774 CODE:
2775 0 text = sv_stringify(text);
2776
2777 STRLEN text_len;
2778 0 const char *text_str = SvPV_const(text, text_len);
2779
2780 0 myencoding_t encoding = MyENCODING_NOT_DETERMINED;
2781 0 myencoding_by_name(text_str, text_len, &encoding);
2782 0 ▶ RETVAL = encoding != MyENCODING_NOT_DETERMINED ? newSViv(encoding) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = encoding != MyENCODING_NOT_DETERMINED ? newSViv(encoding) : &PL_sv_undef; 0 0 0
2783 OUTPUT:
2784 RETVAL
2785  
2786 int
2787 detect(SV *text, long max_len = 0)
2788 ALIAS:
2789 detectByPrescanStream = 1
2790 detectRussian = 2
2791 detectUnicode = 3
2792 detectBom = 4
2793 detectByCharset = 5
2794 CODE:
2795 0 text = sv_stringify(text);
2796
2797 STRLEN text_len;
2798 0 const char *text_str = SvPV_const(text, text_len);
2799
2800 0 ▶ if (max_len > 0 && max_len < text_len)
Branch: 2 branches
BranchTrueFalseTotal
if (max_len > 0 && max_len < text_len) 0 0 0
if (max_len > 0 && max_len < text_len) 0 0 0
2801 0 text_len = max_len;
2802
2803 myencoding_t encoding;
2804
2805 0 switch (ix) {
2806 0 case 0:
2807 0 ▶ if (!myencoding_detect(text_str, text_len, &encoding))
Branch: 1 branch
BranchTrueFalseTotal
if (!myencoding_detect(text_str, text_len, &encoding)) 0 0 0
2808 0 encoding = MyENCODING_NOT_DETERMINED;
2809 0 break;
2810 0 case 1:
2811 0 encoding = myencoding_prescan_stream_to_determine_encoding(text_str, text_len);
2812 0 break;
2813 0 case 2:
2814 0 ▶ if (!myencoding_detect_russian(text_str, text_len, &encoding))
Branch: 1 branch
BranchTrueFalseTotal
if (!myencoding_detect_russian(text_str, text_len, &encoding)) 0 0 0
2815 0 encoding = MyENCODING_NOT_DETERMINED;
2816 0 break;
2817 0 case 3:
2818 0 ▶ if (!myencoding_detect_unicode(text_str, text_len, &encoding))
Branch: 1 branch
BranchTrueFalseTotal
if (!myencoding_detect_unicode(text_str, text_len, &encoding)) 0 0 0
2819 0 encoding = MyENCODING_NOT_DETERMINED;
2820 0 break;
2821 0 case 4:
2822 0 ▶ if (!myencoding_detect_bom(text_str, text_len, &encoding))
Branch: 1 branch
BranchTrueFalseTotal
if (!myencoding_detect_bom(text_str, text_len, &encoding)) 0 0 0
2823 0 encoding = MyENCODING_NOT_DETERMINED;
2824 0 break;
2825 0 case 5:
2826 0 ▶ if (!myencoding_extracting_character_encoding_from_charset(text_str, text_len, &encoding))
Branch: 1 branch
BranchTrueFalseTotal
if (!myencoding_extracting_character_encoding_from_charset(text_str, text_len, &encoding)) 0 0 0
2827 0 encoding = MyENCODING_NOT_DETERMINED;
2828 0 break;
2829 }
2830
2831 0 ▶ RETVAL = encoding;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = encoding; 0 0 0
2832 OUTPUT:
2833 RETVAL
2834  
2835 void
2836 detectBomAndCut(SV *text, long max_len = 0)
2837 CODE:
2838 0 text = sv_stringify(text);
2839
2840 STRLEN text_len;
2841 0 const char *text_str = SvPV_const(text, text_len);
2842
2843 0 ▶ if (max_len > 0 && max_len < text_len)
Branch: 2 branches
BranchTrueFalseTotal
if (max_len > 0 && max_len < text_len) 0 0 0
if (max_len > 0 && max_len < text_len) 0 0 0
2844 0 text_len = max_len;
2845
2846 myencoding_t encoding;
2847
2848 0 ▶ if (!myencoding_detect_and_cut_bom(text_str, text_len, &encoding, &text_str, &text_len))
Branch: 1 branch
BranchTrueFalseTotal
if (!myencoding_detect_and_cut_bom(text_str, text_len, &encoding, &text_str, &text_len)) 0 0 0
2849 0 encoding = MyENCODING_NOT_DETERMINED;
2850  
2851 0 ST(0) = newSViv(encoding);
2852 0 ST(1) = newSVpv(text_str, text_len);
2853
2854 0 sv_2mortal(ST(0));
2855 0 sv_2mortal(ST(1));
2856
2857 0 XSRETURN(2);
2858  
2859 void
2860 detectAuto(SV *text, long max_len = 0, HV *options = NULL)
2861 CODE:
2862 0 text = sv_stringify(text);
2863
2864 STRLEN text_len;
2865 0 const char *text_str = SvPV_const(text, text_len);
2866
2867 0 ▶ if (max_len > 0 && max_len < text_len)
Branch: 2 branches
BranchTrueFalseTotal
if (max_len > 0 && max_len < text_len) 0 0 0
if (max_len > 0 && max_len < text_len) 0 0 0
2868 0 text_len = max_len;
2869
2870 0 html5_dom_options_t opts = {0};
2871 0 html5_dom_parse_options(&opts, NULL, options);
2872
2873 0 opts.encoding = MyENCODING_AUTO;
2874 0 opts.default_encoding = MyENCODING_NOT_DETERMINED;
2875 0 opts.encoding_prescan_limit = text_len;
2876
2877 0 myencoding_t encoding = html5_dom_auto_encoding(&opts, &text_str, &text_len);
2878
2879 0 ST(0) = newSViv(encoding);
2880 0 ST(1) = newSVpv(text_str, text_len);
2881
2882 0 sv_2mortal(ST(0));
2883 0 sv_2mortal(ST(1));
2884
2885 0 XSRETURN(2);
« blib/lib/HTML5/DOM.pm ↑ Summary gen/modest_errors.c »