source/myhtml/token.c

filter: Statementstmt 7.2% 33 / 453 Branchbran 1.6% 4 / 244 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 5.3% 37 / 697 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« MyHTML.xs ↑ Summary xs/tree.xs »
1 /*
2 Copyright 2015-2016 Alexander Borisov
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 Author: lex.borisov@gmail.com (Alexander Borisov)
17 */
18  
19 #include "myhtml/token.h"
20  
21 // all key size == value size
22 static const myhtml_token_replacement_entry_t myhtml_token_attr_svg_replacement[] = {
23 {"attributename", 13, "attributeName", 13},
24 {"attributetype", 13, "attributeType", 13},
25 {"basefrequency", 13, "baseFrequency", 13},
26 {"baseprofile", 11, "baseProfile", 11},
27 {"calcmode", 8, "calcMode", 8},
28 {"clippathunits", 13, "clipPathUnits", 13},
29 {"diffuseconstant", 15, "diffuseConstant", 15},
30 {"edgemode", 8, "edgeMode", 8},
31 {"filterunits", 11, "filterUnits", 11},
32 {"glyphref", 8, "glyphRef", 8},
33 {"gradienttransform", 17, "gradientTransform", 17},
34 {"gradientunits", 13, "gradientUnits", 13},
35 {"kernelmatrix", 12, "kernelMatrix", 12},
36 {"kernelunitlength", 16, "kernelUnitLength", 16},
37 {"keypoints", 9, "keyPoints", 9},
38 {"keysplines", 10, "keySplines", 10},
39 {"keytimes", 8, "keyTimes", 8},
40 {"lengthadjust", 12, "lengthAdjust", 12},
41 {"limitingconeangle", 17, "limitingConeAngle", 17},
42 {"markerheight", 12, "markerHeight", 12},
43 {"markerunits", 11, "markerUnits", 11},
44 {"markerwidth", 11, "markerWidth", 11},
45 {"maskcontentunits", 16, "maskContentUnits", 16},
46 {"maskunits", 9, "maskUnits", 9},
47 {"numoctaves", 10, "numOctaves", 10},
48 {"pathlength", 10, "pathLength", 10},
49 {"patterncontentunits", 19, "patternContentUnits", 19},
50 {"patterntransform", 16, "patternTransform", 16},
51 {"patternunits", 12, "patternUnits", 12},
52 {"pointsatx", 9, "pointsAtX", 9},
53 {"pointsaty", 9, "pointsAtY", 9},
54 {"pointsatz", 9, "pointsAtZ", 9},
55 {"preservealpha", 13, "preserveAlpha", 13},
56 {"preserveaspectratio", 19, "preserveAspectRatio", 19},
57 {"primitiveunits", 14, "primitiveUnits", 14},
58 {"refx", 4, "refX", 4},
59 {"refy", 4, "refY", 4},
60 {"repeatcount", 11, "repeatCount", 11},
61 {"repeatdur", 9, "repeatDur", 9},
62 {"requiredextensions", 18, "requiredExtensions", 18},
63 {"requiredfeatures", 16, "requiredFeatures", 16},
64 {"specularconstant", 16, "specularConstant", 16},
65 {"specularexponent", 16, "specularExponent", 16},
66 {"spreadmethod", 12, "spreadMethod", 12},
67 {"startoffset", 11, "startOffset", 11},
68 {"stddeviation", 12, "stdDeviation", 12},
69 {"stitchtiles", 11, "stitchTiles", 11},
70 {"surfacescale", 12, "surfaceScale", 12},
71 {"systemlanguage", 14, "systemLanguage", 14},
72 {"tablevalues", 11, "tableValues", 11},
73 {"targetx", 7, "targetX", 7},
74 {"targety", 7, "targetY", 7},
75 {"textlength", 10, "textLength", 10},
76 {"viewbox", 7, "viewBox", 7},
77 {"viewtarget", 10, "viewTarget", 10},
78 {"xchannelselector", 16, "xChannelSelector", 16},
79 {"ychannelselector", 16, "yChannelSelector", 16},
80 {"zoomandpan", 10, "zoomAndPan", 10}
81 };
82  
83 // all key size > value size
84 static const myhtml_token_namespace_replacement_t myhtml_token_attr_namespace_replacement[] = {
85 {"xlink:actuate", 13, "actuate", 7, MyHTML_NAMESPACE_XLINK},
86 {"xlink:arcrole", 13, "arcrole", 7, MyHTML_NAMESPACE_XLINK},
87 {"xlink:href", 10, "href", 4, MyHTML_NAMESPACE_XLINK},
88 {"xlink:role", 10, "role", 4, MyHTML_NAMESPACE_XLINK},
89 {"xlink:show", 10, "show", 4, MyHTML_NAMESPACE_XLINK},
90 {"xlink:title", 11, "title", 5, MyHTML_NAMESPACE_XLINK},
91 {"xlink:type", 10, "type", 4, MyHTML_NAMESPACE_XLINK},
92 {"xml:lang", 8, "lang", 4, MyHTML_NAMESPACE_XML},
93 {"xml:space", 9, "space", 5, MyHTML_NAMESPACE_XML},
94 {"xmlns", 5, "xmlns", 5, MyHTML_NAMESPACE_XMLNS},
95 {"xmlns:xlink", 11, "xlink", 5, MyHTML_NAMESPACE_XMLNS}
96 };
97  
98 1 myhtml_token_t * myhtml_token_create(myhtml_tree_t* tree, size_t size)
99 {
100 1 ▶ if(size == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(size == 0) 0 1 1
101 0 size = 4096;
102
103 1 myhtml_token_t* token = (myhtml_token_t*)mymalloc(sizeof(myhtml_token_t));
104
105 1 token->nodes_obj = mcobject_async_create();
106 1 token->attr_obj = mcobject_async_create();
107
108 1 mcobject_async_init(token->nodes_obj, 128, size, sizeof(myhtml_token_node_t));
109 1 mcobject_async_init(token->attr_obj, 128, size, sizeof(myhtml_token_attr_t));
110
111 1 token->mcasync_token_id = mcobject_async_node_add(token->nodes_obj, NULL);
112 1 token->mcasync_attr_id = mcobject_async_node_add(token->attr_obj, NULL);
113
114 1 token->tree = tree;
115
116 1 return token;
117 }
118  
119 1 void myhtml_token_clean(myhtml_token_t* token)
120 {
121 1 mcobject_async_node_clean(token->nodes_obj, token->mcasync_token_id);
122 1 mcobject_async_node_clean(token->attr_obj, token->mcasync_attr_id);
123 1 }
124  
125 0 void myhtml_token_clean_all(myhtml_token_t* token)
126 {
127 0 mcobject_async_clean(token->nodes_obj);
128 0 mcobject_async_clean(token->attr_obj);
129 0 }
130  
131 1 myhtml_token_t * myhtml_token_destroy(myhtml_token_t* token)
132 {
133 1 ▶ if(token == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(token == NULL) 0 1 1
134 0 return NULL;
135
136 1 ▶ if(token->nodes_obj)
Branch: 1 branch
BranchTrueFalseTotal
if(token->nodes_obj) 1 0 1
137 1 token->nodes_obj = mcobject_async_destroy(token->nodes_obj, 1);
138
139 1 ▶ if(token->attr_obj)
Branch: 1 branch
BranchTrueFalseTotal
if(token->attr_obj) 1 0 1
140 1 token->attr_obj = mcobject_async_destroy(token->attr_obj, 1);
141
142 1 free(token);
143
144 1 return NULL;
145 }
146  
147 0 void myhtml_token_node_clean(myhtml_token_node_t* node)
148 {
149 0 node->tag_ctx_idx = MyHTML_TAG__UNDEF;
150 0 node->type = MyHTML_TOKEN_TYPE_OPEN|MyHTML_TOKEN_TYPE_WHITESPACE;
151 0 node->attr_first = NULL;
152 0 node->attr_last = NULL;
153 0 node->begin = 0;
154 0 node->length = 0;
155
156 0 myhtml_string_clean_all(&node->my_str_tm);
157 0 }
158  
159 1 void myhtml_token_attr_clean(myhtml_token_attr_t* attr)
160 {
161 1 attr->next = 0;
162 1 attr->prev = 0;
163 1 attr->name_begin = 0;
164 1 attr->name_length = 0;
165 1 attr->value_begin = 0;
166 1 attr->value_length = 0;
167 1 attr->my_namespace = MyHTML_NAMESPACE_UNDEF;
168
169 1 myhtml_string_clean_all(&attr->entry);
170 1 }
171  
172 0 void myhtml_token_node_wait_for_done(myhtml_token_node_t* node)
173 {
174 #ifndef MyHTML_BUILD_WITHOUT_THREADS
175
176 0 const struct timespec timeout = {0, 0};
177 0 ▶ while((node->type & MyHTML_TOKEN_TYPE_DONE) == 0) {myhtml_thread_nanosleep(&timeout);}
Branch: 1 branch
BranchTrueFalseTotal
while((node->type & MyHTML_TOKEN_TYPE_DONE) == 0) {myhtml_thread_nanosleep(&timeout);} 0 0 0
178
179 #endif
180 0 }
181  
182 0 myhtml_token_node_t * myhtml_token_node_clone(myhtml_token_t* token, myhtml_token_node_t* node, size_t token_thread_idx, size_t attr_thread_idx)
183 {
184 0 ▶ if(node == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(node == NULL) 0 0 0
185 0 return NULL;
186
187 0 myhtml_tree_t* tree = token->tree;
188
189 0 myhtml_token_node_t* new_node = mcobject_async_malloc(token->nodes_obj, token_thread_idx, NULL);
190
191 0 new_node->tag_ctx_idx = node->tag_ctx_idx;
192 0 new_node->type = node->type;
193 0 new_node->attr_first = NULL;
194 0 new_node->attr_last = NULL;
195 0 new_node->begin = node->begin;
196 0 new_node->length = node->length;
197
198 0 myhtml_string_init(tree->mchar, tree->mchar_node_id, &new_node->my_str_tm, node->my_str_tm.size);
199 0 myhtml_token_node_attr_copy(token, node, new_node, attr_thread_idx);
200
201 0 return new_node;
202 }
203  
204 0 void myhtml_token_node_text_append(myhtml_token_t* token, myhtml_token_node_t* dest, const char* text, size_t text_len)
205 {
206 0 myhtml_string_init(token->tree->mchar, token->tree->mchar_node_id, &dest->my_str_tm, (text_len + 32));
207
208 0 myhtml_string_t* string = &dest->my_str_tm;
209
210 0 dest->begin = string->length;
211 0 dest->length = text_len;
212
213 0 myhtml_string_append(string, text, text_len);
214 0 }
215  
216 0 myhtml_token_attr_t * myhtml_token_node_attr_append(myhtml_token_t* token, myhtml_token_node_t* dest,
217 const char* key, size_t key_len,
218 const char* value, size_t value_len, size_t thread_idx)
219 {
220 0 myhtml_token_attr_t* new_attr = mcobject_async_malloc(token->attr_obj, thread_idx, NULL);
221 0 new_attr->next = 0;
222
223 0 myhtml_string_init(token->tree->mchar, token->tree->mchar_node_id, &new_attr->entry, (key_len + value_len + 16));
224
225 0 ▶ if(key_len)
Branch: 1 branch
BranchTrueFalseTotal
if(key_len) 0 0 0
226 {
227 0 new_attr->name_begin = new_attr->entry.length;
228 0 new_attr->name_length = key_len;
229
230 0 myhtml_string_append_lowercase(&new_attr->entry,
231 key, key_len);
232 }
233 else {
234 0 new_attr->name_begin = 0;
235 0 new_attr->name_length = 0;
236 }
237
238 0 ▶ if(value_len)
Branch: 1 branch
BranchTrueFalseTotal
if(value_len) 0 0 0
239 {
240 0 new_attr->value_begin = new_attr->entry.length;
241 0 new_attr->value_length = value_len;
242
243 0 myhtml_string_append(&new_attr->entry,
244 value, value_len);
245 }
246 else {
247 0 new_attr->value_begin = 0;
248 0 new_attr->value_length = 0;
249 }
250
251 0 ▶ if(dest->attr_first == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(dest->attr_first == NULL) { 0 0 0
252 0 new_attr->prev = 0;
253
254 0 dest->attr_first = new_attr;
255 0 dest->attr_last = new_attr;
256 }
257 else {
258 0 dest->attr_last->next = new_attr;
259 0 new_attr->prev = dest->attr_last;
260
261 0 dest->attr_last = new_attr;
262 }
263
264 0 return new_attr;
265 }
266  
267 0 myhtml_token_attr_t * myhtml_token_node_attr_append_with_convert_encoding(myhtml_token_t* token, myhtml_token_node_t* dest,
268 const char* key, size_t key_len,
269 const char* value, size_t value_len,
270 size_t thread_idx, myhtml_encoding_t encoding)
271 {
272 0 myhtml_token_attr_t* new_attr = mcobject_async_malloc(token->attr_obj, thread_idx, NULL);
273 0 new_attr->next = 0;
274
275 0 myhtml_string_init(token->tree->mchar, token->tree->mchar_node_id, &new_attr->entry, (key_len + value_len + 16));
276
277 0 ▶ if(key_len)
Branch: 1 branch
BranchTrueFalseTotal
if(key_len) 0 0 0
278 {
279 0 new_attr->name_begin = new_attr->entry.length;
280 0 new_attr->name_length = key_len;
281
282 0 ▶ if(encoding == MyHTML_ENCODING_UTF_8)
Branch: 1 branch
BranchTrueFalseTotal
if(encoding == MyHTML_ENCODING_UTF_8) 0 0 0
283 0 myhtml_string_append_lowercase(&new_attr->entry, key, key_len);
284 else
285 0 myhtml_string_append_lowercase_ascii_with_convert_encoding(&new_attr->entry,
286 key, key_len, encoding);
287 }
288 else {
289 0 new_attr->name_begin = 0;
290 0 new_attr->name_length = 0;
291 }
292
293 0 ▶ if(value_len)
Branch: 1 branch
BranchTrueFalseTotal
if(value_len) 0 0 0
294 {
295 0 new_attr->value_begin = new_attr->entry.length;
296 0 new_attr->value_length = value_len;
297
298 0 ▶ if(encoding == MyHTML_ENCODING_UTF_8)
Branch: 1 branch
BranchTrueFalseTotal
if(encoding == MyHTML_ENCODING_UTF_8) 0 0 0
299 0 myhtml_string_append(&new_attr->entry, value, value_len);
300 else
301 0 myhtml_string_append_with_convert_encoding(&new_attr->entry,
302 value, value_len, encoding);
303 }
304 else {
305 0 new_attr->value_begin = 0;
306 0 new_attr->value_length = 0;
307 }
308
309 0 ▶ if(dest->attr_first == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(dest->attr_first == NULL) { 0 0 0
310 0 new_attr->prev = 0;
311
312 0 dest->attr_first = new_attr;
313 0 dest->attr_last = new_attr;
314 }
315 else {
316 0 dest->attr_last->next = new_attr;
317 0 new_attr->prev = dest->attr_last;
318
319 0 dest->attr_last = new_attr;
320 }
321
322 0 new_attr->my_namespace = MyHTML_NAMESPACE_HTML;
323
324 0 return new_attr;
325 }
326  
327 // TODO: use tree for this
328 0 void myhtml_token_node_attr_copy_with_check(myhtml_token_t* token, myhtml_token_node_t* target, myhtml_token_node_t* dest, size_t thread_idx)
329 {
330 0 myhtml_token_attr_t* attr = target->attr_first;
331
332 0 ▶ while (attr)
Branch: 1 branch
BranchTrueFalseTotal
while (attr) 0 0 0
333 {
334 0 ▶ if(attr->name_length && myhtml_token_attr_by_name(dest, &attr->entry.data[ attr->name_begin ], attr->name_length) == NULL) {
Branch: 2 branches
BranchTrueFalseTotal
if(attr->name_length && myhtml_token_attr_by_name(dest, &attr->entry.data[ attr->name_begin ], attr->name_length) == NULL) { 0 0 0
if(attr->name_length && myhtml_token_attr_by_name(dest, &attr->entry.data[ attr->name_begin ], attr->name_length) == NULL) { 0 0 0
335 0 myhtml_token_attr_copy(token, attr, dest, thread_idx);
336 }
337
338 0 attr = attr->next;
339 }
340 0 }
341  
342 0 void myhtml_token_node_attr_copy(myhtml_token_t* token, myhtml_token_node_t* target, myhtml_token_node_t* dest, size_t thread_idx)
343 {
344 0 myhtml_token_attr_t* attr = target->attr_first;
345
346 0 ▶ while (attr)
Branch: 1 branch
BranchTrueFalseTotal
while (attr) 0 0 0
347 {
348 0 myhtml_token_attr_copy(token, attr, dest, thread_idx);
349 0 attr = attr->next;
350 }
351 0 }
352  
353 0 bool myhtml_token_attr_copy(myhtml_token_t* token, myhtml_token_attr_t* attr, myhtml_token_node_t* dest, size_t thread_idx)
354 {
355 0 myhtml_token_attr_t* new_attr = mcobject_async_malloc(token->attr_obj, thread_idx, NULL);
356 0 new_attr->next = 0;
357
358 0 myhtml_string_init(token->tree->mchar, token->tree->mchar_node_id, &new_attr->entry, (attr->name_length + attr->value_begin + 16));
359
360 0 ▶ if(attr->name_length)
Branch: 1 branch
BranchTrueFalseTotal
if(attr->name_length) 0 0 0
361 {
362 0 new_attr->name_begin = new_attr->entry.length;
363 0 new_attr->name_length = attr->name_length;
364
365 0 myhtml_string_append_lowercase(&new_attr->entry,
366 0 &attr->entry.data[attr->name_begin],
367 attr->name_length);
368 }
369 else {
370 0 new_attr->name_begin = 0;
371 0 new_attr->name_length = 0;
372 }
373
374 0 ▶ if(attr->value_length)
Branch: 1 branch
BranchTrueFalseTotal
if(attr->value_length) 0 0 0
375 {
376 0 new_attr->value_begin = new_attr->entry.length;
377 0 new_attr->value_length = attr->value_length;
378
379 0 myhtml_string_append(&new_attr->entry,
380 0 &attr->entry.data[attr->value_begin],
381 attr->value_length);
382 }
383 else {
384 0 new_attr->value_begin = 0;
385 0 new_attr->value_length = 0;
386 }
387
388 0 ▶ if(dest->attr_first == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(dest->attr_first == NULL) { 0 0 0
389 0 new_attr->prev = 0;
390
391 0 dest->attr_first = new_attr;
392 0 dest->attr_last = new_attr;
393 }
394 else {
395 0 dest->attr_last->next = new_attr;
396 0 new_attr->prev = dest->attr_last;
397
398 0 dest->attr_last = new_attr;
399 }
400
401 0 return true;
402 }
403  
404 0 myhtml_token_attr_t * myhtml_token_attr_match(myhtml_token_t* token, myhtml_token_node_t* target,
405 const char* key, size_t key_size, const char* value, size_t value_size)
406 {
407 0 myhtml_token_attr_t* attr = target->attr_first;
408
409 0 ▶ while (attr)
Branch: 1 branch
BranchTrueFalseTotal
while (attr) 0 0 0
410 {
411 0 ▶ if(attr->name_length == key_size && attr->value_length == value_size)
Branch: 2 branches
BranchTrueFalseTotal
if(attr->name_length == key_size && attr->value_length == value_size) 0 0 0
if(attr->name_length == key_size && attr->value_length == value_size) 0 0 0
412 {
413 0 ▶ if((strncmp(key, &attr->entry.data[attr->name_begin], key_size) == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if((strncmp(key, &attr->entry.data[attr->name_begin], key_size) == 0)) { 0 0 0
414 0 ▶ if((strncmp(value, &attr->entry.data[attr->value_begin], value_size) == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if((strncmp(value, &attr->entry.data[attr->value_begin], value_size) == 0)) { 0 0 0
415 0 return attr;
416 }
417 else {
418 0 return NULL;
419 }
420 }
421 }
422
423 0 attr = attr->next;
424 }
425
426 0 return NULL;
427 }
428  
429 // TODO: copy/past but...
430 0 myhtml_token_attr_t * myhtml_token_attr_match_case(myhtml_token_t* token, myhtml_token_node_t* target,
431 const char* key, size_t key_size, const char* value, size_t value_size)
432 {
433 0 myhtml_token_attr_t* attr = target->attr_first;
434
435 0 ▶ while (attr)
Branch: 1 branch
BranchTrueFalseTotal
while (attr) 0 0 0
436 {
437 0 ▶ if(attr->name_length == key_size && attr->value_length == value_size)
Branch: 2 branches
BranchTrueFalseTotal
if(attr->name_length == key_size && attr->value_length == value_size) 0 0 0
if(attr->name_length == key_size && attr->value_length == value_size) 0 0 0
438 {
439 0 ▶ if((strncmp(key, &attr->entry.data[attr->name_begin], key_size) == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if((strncmp(key, &attr->entry.data[attr->name_begin], key_size) == 0)) { 0 0 0
440 0 ▶ if((myhtml_strncasecmp(value, &attr->entry.data[attr->value_begin], value_size) == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if((myhtml_strncasecmp(value, &attr->entry.data[attr->value_begin], value_size) == 0)) { 0 0 0
441 0 return attr;
442 }
443 else {
444 0 return NULL;
445 }
446 }
447 }
448
449 0 attr = attr->next;
450 }
451
452 0 return NULL;
453 }
454  
455 0 void myhtml_token_adjust_mathml_attributes(myhtml_token_node_t* target)
456 {
457 0 myhtml_token_attr_t* attr = myhtml_token_attr_by_name(target, "definitionurl", 13);
458
459 0 ▶ if(attr) {
Branch: 1 branch
BranchTrueFalseTotal
if(attr) { 0 0 0
460 0 memcpy(&attr->entry.data[attr->name_begin], "definitionURL", 13);
461 }
462 0 }
463  
464 // TODO: init mchar_async
465 0 void _myhtml_token_create_copy_srt(myhtml_token_t* token, const char* from, size_t from_size, char** to)
466 {
467 0 *to = mchar_async_malloc(token->tree->mchar, token->tree->mchar_node_id, (from_size + 2));
468 0 myhtml_string_raw_copy(*to, from, from_size);
469 0 }
470  
471 0 void myhtml_token_strict_doctype_by_token(myhtml_token_t* token, myhtml_token_node_t* target, myhtml_tree_doctype_t* return_doctype)
472 {
473 0 myhtml_token_attr_t* attr = target->attr_first;
474
475 const char* data;
476
477 0 ▶ if(attr && attr->name_length) {
Branch: 2 branches
BranchTrueFalseTotal
if(attr && attr->name_length) { 0 0 0
if(attr && attr->name_length) { 0 0 0
478 0 data = attr->entry.data;
479
480 0 _myhtml_token_create_copy_srt(token, &data[attr->name_begin], attr->name_length, &return_doctype->attr_name);
481
482 0 ▶ if(strcmp("html", return_doctype->attr_name))
Branch: 1 branch
BranchTrueFalseTotal
if(strcmp("html", return_doctype->attr_name)) 0 0 0
483 0 return_doctype->is_html = false;
484 else
485 0 return_doctype->is_html = true;
486 }
487 else {
488 0 return_doctype->is_html = false;
489
490 // if(return_doctype->attr_name)
491 // myfree(return_doctype->attr_name);
492 // return_doctype->attr_name = NULL;
493
494 0 _myhtml_token_create_copy_srt(token, "\0", 1, &return_doctype->attr_name);
495
496 0 ▶ if(return_doctype->attr_public)
Branch: 1 branch
BranchTrueFalseTotal
if(return_doctype->attr_public) 0 0 0
497 0 myfree(return_doctype->attr_public);
498 0 return_doctype->attr_public = NULL;
499
500 0 ▶ if(return_doctype->attr_system)
Branch: 1 branch
BranchTrueFalseTotal
if(return_doctype->attr_system) 0 0 0
501 0 myfree(return_doctype->attr_system);
502 0 return_doctype->attr_system = NULL;
503
504 0 return;
505 }
506
507 0 attr = attr->next;
508
509 0 ▶ if(attr && attr->value_length)
Branch: 2 branches
BranchTrueFalseTotal
if(attr && attr->value_length) 0 0 0
if(attr && attr->value_length) 0 0 0
510 {
511 0 data = attr->entry.data;
512
513 0 ▶ if(myhtml_strncasecmp(&data[attr->value_begin], "PUBLIC", attr->value_length) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml_strncasecmp(&data[attr->value_begin], "PUBLIC", attr->value_length) == 0) 0 0 0
514 {
515 // try see public
516 0 attr = attr->next;
517
518 0 ▶ if(attr && attr->value_length) {
Branch: 2 branches
BranchTrueFalseTotal
if(attr && attr->value_length) { 0 0 0
if(attr && attr->value_length) { 0 0 0
519 0 data = attr->entry.data;
520
521 0 _myhtml_token_create_copy_srt(token, &data[attr->value_begin], attr->value_length, &return_doctype->attr_public);
522
523 // try see system
524 0 attr = attr->next;
525
526 0 ▶ if(attr && attr->value_length) {
Branch: 2 branches
BranchTrueFalseTotal
if(attr && attr->value_length) { 0 0 0
if(attr && attr->value_length) { 0 0 0
527 0 data = attr->entry.data;
528 0 _myhtml_token_create_copy_srt(token, &data[attr->value_begin], attr->value_length, &return_doctype->attr_system);
529 }
530 else {
531 0 ▶ if(return_doctype->attr_system)
Branch: 1 branch
BranchTrueFalseTotal
if(return_doctype->attr_system) 0 0 0
532 0 myfree(return_doctype->attr_system);
533
534 0 _myhtml_token_create_copy_srt(token, "\0", 1, &return_doctype->attr_system);
535 //return_doctype->attr_system = NULL;
536 }
537 }
538 else {
539 0 ▶ if(return_doctype->attr_public)
Branch: 1 branch
BranchTrueFalseTotal
if(return_doctype->attr_public) 0 0 0
540 0 myfree(return_doctype->attr_public);
541 0 return_doctype->attr_public = NULL;
542
543 0 ▶ if(return_doctype->attr_system)
Branch: 1 branch
BranchTrueFalseTotal
if(return_doctype->attr_system) 0 0 0
544 0 myfree(return_doctype->attr_system);
545 0 return_doctype->attr_system = NULL;
546 }
547 }
548 0 ▶ else if(myhtml_strncasecmp(&data[attr->value_begin], "SYSTEM", attr->value_length) == 0)
Branch: 1 branch
BranchTrueFalseTotal
else if(myhtml_strncasecmp(&data[attr->value_begin], "SYSTEM", attr->value_length) == 0) 0 0 0
549 {
550 0 attr = attr->next;
551
552 0 ▶ if(attr && attr->value_length) {
Branch: 2 branches
BranchTrueFalseTotal
if(attr && attr->value_length) { 0 0 0
if(attr && attr->value_length) { 0 0 0
553 0 data = attr->entry.data;
554 0 _myhtml_token_create_copy_srt(token, "\0", 1, &return_doctype->attr_public);
555 0 _myhtml_token_create_copy_srt(token, &data[attr->value_begin], attr->value_length, &return_doctype->attr_system);
556 }
557 else {
558 0 ▶ if(return_doctype->attr_public)
Branch: 1 branch
BranchTrueFalseTotal
if(return_doctype->attr_public) 0 0 0
559 0 myfree(return_doctype->attr_public);
560 0 return_doctype->attr_public = NULL;
561
562 0 ▶ if(return_doctype->attr_system)
Branch: 1 branch
BranchTrueFalseTotal
if(return_doctype->attr_system) 0 0 0
563 0 myfree(return_doctype->attr_system);
564 0 return_doctype->attr_system = NULL;
565 }
566 }
567 else {
568 0 ▶ if(return_doctype->attr_public)
Branch: 1 branch
BranchTrueFalseTotal
if(return_doctype->attr_public) 0 0 0
569 0 myfree(return_doctype->attr_public);
570 0 return_doctype->attr_public = NULL;
571
572 0 ▶ if(return_doctype->attr_system)
Branch: 1 branch
BranchTrueFalseTotal
if(return_doctype->attr_system) 0 0 0
573 0 myfree(return_doctype->attr_system);
574 0 return_doctype->attr_system = NULL;
575 }
576 }
577 }
578  
579 0 bool myhtml_token_doctype_check_html_4_0(myhtml_tree_doctype_t* return_doctype)
580 {
581 0 ▶ return strcmp(return_doctype->attr_public, "-//W3C//DTD HTML 4.0//EN") &&
Branch: 1 branch
BranchTrueFalseTotal
return strcmp(return_doctype->attr_public, "-//W3C//DTD HTML 4.0//EN") && 0 0 0
582 0 ▶ (return_doctype->attr_system == NULL || strcmp(return_doctype->attr_system, "http://www.w3.org/TR/REC-html40/strict.dtd"));
Branch: 2 branches
BranchTrueFalseTotal
(return_doctype->attr_system == NULL || strcmp(return_doctype->attr_system, "http://www.w3.org/TR/REC-html40/strict.dtd")); 0 0 0
(return_doctype->attr_system == NULL || strcmp(return_doctype->attr_system, "http://www.w3.org/TR/REC-html40/strict.dtd")); 0 0 0
583 }
584  
585 0 bool myhtml_token_doctype_check_html_4_01(myhtml_tree_doctype_t* return_doctype)
586 {
587 0 ▶ return strcmp(return_doctype->attr_public, "-//W3C//DTD HTML 4.01//EN") &&
Branch: 1 branch
BranchTrueFalseTotal
return strcmp(return_doctype->attr_public, "-//W3C//DTD HTML 4.01//EN") && 0 0 0
588 0 ▶ (return_doctype->attr_system == NULL || strcmp(return_doctype->attr_system, "http://www.w3.org/TR/html4/strict.dtd"));
Branch: 2 branches
BranchTrueFalseTotal
(return_doctype->attr_system == NULL || strcmp(return_doctype->attr_system, "http://www.w3.org/TR/html4/strict.dtd")); 0 0 0
(return_doctype->attr_system == NULL || strcmp(return_doctype->attr_system, "http://www.w3.org/TR/html4/strict.dtd")); 0 0 0
589 }
590  
591 0 bool myhtml_token_doctype_check_xhtml_1_0(myhtml_tree_doctype_t* return_doctype)
592 {
593 0 ▶ if(return_doctype->attr_system == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(return_doctype->attr_system == NULL) 0 0 0
594 0 return true;
595
596 0 ▶ return strcmp(return_doctype->attr_public, "-//W3C//DTD XHTML 1.0 Strict//EN") &&
Branch: 1 branch
BranchTrueFalseTotal
return strcmp(return_doctype->attr_public, "-//W3C//DTD XHTML 1.0 Strict//EN") && 0 0 0
597 0 ▶ strcmp(return_doctype->attr_system, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd");
Branch: 1 branch
BranchTrueFalseTotal
strcmp(return_doctype->attr_system, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"); 0 0 0
598 }
599  
600 0 bool myhtml_token_doctype_check_xhtml_1_1(myhtml_tree_doctype_t* return_doctype)
601 {
602 0 ▶ if(return_doctype->attr_system == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(return_doctype->attr_system == NULL) 0 0 0
603 0 return true;
604
605 0 ▶ return strcmp(return_doctype->attr_public, "-//W3C//DTD XHTML 1.1//EN") &&
Branch: 1 branch
BranchTrueFalseTotal
return strcmp(return_doctype->attr_public, "-//W3C//DTD XHTML 1.1//EN") && 0 0 0
606 0 ▶ strcmp(return_doctype->attr_system, "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd");
Branch: 1 branch
BranchTrueFalseTotal
strcmp(return_doctype->attr_system, "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"); 0 0 0
607 }
608  
609 0 bool myhtml_token_release_and_check_doctype_attributes(myhtml_token_t* token, myhtml_token_node_t* target, myhtml_tree_doctype_t* return_doctype)
610 {
611 0 ▶ if(return_doctype == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(return_doctype == NULL) 0 0 0
612 0 return false;
613
614 0 myhtml_token_strict_doctype_by_token(token, target, return_doctype);
615
616 0 ▶ if(return_doctype->attr_name == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(return_doctype->attr_name == NULL) 0 0 0
617 0 return false;
618
619 0 ▶ if((return_doctype->is_html ||
Branch: 1 branch
BranchTrueFalseTotal
if((return_doctype->is_html || 0 0 0
620 0 ▶ return_doctype->attr_public ||
Branch: 1 branch
BranchTrueFalseTotal
return_doctype->attr_public || 0 0 0
621 0 ▶ (return_doctype->attr_system && strcmp(return_doctype->attr_system, "about:legacy-compat"))))
Branch: 2 branches
BranchTrueFalseTotal
(return_doctype->attr_system && strcmp(return_doctype->attr_system, "about:legacy-compat")))) 0 0 0
(return_doctype->attr_system && strcmp(return_doctype->attr_system, "about:legacy-compat")))) 0 0 0
622 {
623 0 ▶ if(return_doctype->attr_public == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(return_doctype->attr_public == NULL) 0 0 0
624 0 return false;
625
626 0 if(return_doctype->is_html &&
627 0 ▶ myhtml_token_doctype_check_html_4_0(return_doctype) &&
Branch: 1 branch
BranchTrueFalseTotal
myhtml_token_doctype_check_html_4_0(return_doctype) && 0 0 0
628 0 ▶ myhtml_token_doctype_check_html_4_01(return_doctype) &&
Branch: 1 branch
BranchTrueFalseTotal
myhtml_token_doctype_check_html_4_01(return_doctype) && 0 0 0
629 0 ▶ myhtml_token_doctype_check_xhtml_1_0(return_doctype) &&
Branch: 1 branch
BranchTrueFalseTotal
myhtml_token_doctype_check_xhtml_1_0(return_doctype) && 0 0 0
630 0 myhtml_token_doctype_check_xhtml_1_1(return_doctype))
631 {
632 0 return false;
633 }
634 }
635
636 0 return true;
637 }
638  
639 // oh
640 // TODO: see this code
641 0 void myhtml_token_adjust_svg_attributes(myhtml_token_node_t* target)
642 {
643 0 size_t count = sizeof(myhtml_token_attr_svg_replacement) / sizeof(myhtml_token_replacement_entry_t);
644
645 0 ▶ for (size_t i = 0; i < count; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (size_t i = 0; i < count; i++) 0 0 0
646 {
647 0 myhtml_token_attr_t* attr = myhtml_token_attr_by_name(target, myhtml_token_attr_svg_replacement[i].from,
648 0 myhtml_token_attr_svg_replacement[i].from_size);
649
650 0 ▶ if(attr) {
Branch: 1 branch
BranchTrueFalseTotal
if(attr) { 0 0 0
651 0 memcpy(&attr->entry.data[attr->name_begin],
652 0 myhtml_token_attr_svg_replacement[i].to,
653 0 myhtml_token_attr_svg_replacement[i].from_size);
654 // from_size == to_size, but use from_size for copy
655 }
656 }
657 0 }
658  
659 0 void myhtml_token_adjust_foreign_attributes(myhtml_token_node_t* target)
660 {
661 0 size_t count = sizeof(myhtml_token_attr_namespace_replacement) / sizeof(myhtml_token_namespace_replacement_t);
662
663 0 ▶ for (size_t i = 0; i < count; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (size_t i = 0; i < count; i++) 0 0 0
664 {
665 0 myhtml_token_attr_t* attr = myhtml_token_attr_by_name(target, myhtml_token_attr_namespace_replacement[i].from,
666 0 myhtml_token_attr_namespace_replacement[i].from_size);
667
668 0 ▶ if(attr) {
Branch: 1 branch
BranchTrueFalseTotal
if(attr) { 0 0 0
669 0 memcpy(&attr->entry.data[attr->name_begin],
670 0 myhtml_token_attr_namespace_replacement[i].to,
671 0 myhtml_token_attr_namespace_replacement[i].to_size);
672
673 0 attr->name_length = myhtml_token_attr_namespace_replacement[i].to_size;
674 0 attr->entry.data[attr->name_length] = '\0';
675
676 0 attr->my_namespace = myhtml_token_attr_namespace_replacement[i].my_namespace;
677 }
678 }
679 0 }
680  
681 0 bool myhtml_token_attr_compare(myhtml_token_node_t* target, myhtml_token_node_t* dest)
682 {
683 0 ▶ if(target == NULL || dest == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if(target == NULL || dest == NULL) 0 0 0
if(target == NULL || dest == NULL) 0 0 0
684 0 return false;
685
686 0 myhtml_token_attr_t* target_attr = target->attr_first;
687 0 myhtml_token_attr_t* dest_attr = dest->attr_first;
688
689 0 ▶ while (target_attr && dest_attr)
Branch: 2 branches
BranchTrueFalseTotal
while (target_attr && dest_attr) 0 0 0
while (target_attr && dest_attr) 0 0 0
690 {
691 0 ▶ if(target_attr->name_length == dest_attr->name_length &&
Branch: 1 branch
BranchTrueFalseTotal
if(target_attr->name_length == dest_attr->name_length && 0 0 0
692 0 ▶ target_attr->value_length == dest_attr->value_length)
Branch: 1 branch
BranchTrueFalseTotal
target_attr->value_length == dest_attr->value_length) 0 0 0
693 {
694 0 ▶ if(strcmp(&target_attr->entry.data[target_attr->name_begin], &dest_attr->entry.data[dest_attr->name_begin]) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if(strcmp(&target_attr->entry.data[target_attr->name_begin], &dest_attr->entry.data[dest_attr->name_begin]) != 0) 0 0 0
695 0 break;
696
697 0 ▶ if(myhtml_strcasecmp(&target_attr->entry.data[target_attr->value_begin], &dest_attr->entry.data[dest_attr->value_begin]) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml_strcasecmp(&target_attr->entry.data[target_attr->value_begin], &dest_attr->entry.data[dest_attr->value_begin]) != 0) 0 0 0
698 0 break;
699 }
700 else
701 break;
702
703 0 target_attr = target_attr->next;
704 0 dest_attr = dest_attr->next;
705 }
706
707 0 ▶ if(target_attr == NULL && dest_attr == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if(target_attr == NULL && dest_attr == NULL) 0 0 0
if(target_attr == NULL && dest_attr == NULL) 0 0 0
708 0 return true;
709
710 0 return false;
711 }
712  
713 0 myhtml_token_attr_t * myhtml_token_attr_by_name(myhtml_token_node_t* node, const char* name, size_t name_length)
714 {
715 0 myhtml_token_attr_t* attr = node->attr_first;
716
717 0 ▶ while (attr)
Branch: 1 branch
BranchTrueFalseTotal
while (attr) 0 0 0
718 {
719 0 ▶ if(name_length == attr->name_length) {
Branch: 1 branch
BranchTrueFalseTotal
if(name_length == attr->name_length) { 0 0 0
720 0 ▶ if(strncmp(name, &attr->entry.data[attr->name_begin], name_length) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(strncmp(name, &attr->entry.data[attr->name_begin], name_length) == 0) 0 0 0
721 0 break;
722 }
723
724 0 attr = attr->next;
725 }
726
727 0 return attr;
728 }
729  
730 0 void myhtml_token_delete(myhtml_token_t* token, myhtml_token_node_t* node)
731 {
732 0 ▶ if(node->my_str_tm.data && node->my_str_tm.mchar) {
Branch: 2 branches
BranchTrueFalseTotal
if(node->my_str_tm.data && node->my_str_tm.mchar) { 0 0 0
if(node->my_str_tm.data && node->my_str_tm.mchar) { 0 0 0
733 0 mchar_async_free(node->my_str_tm.mchar, node->my_str_tm.node_idx, node->my_str_tm.data);
734 }
735
736 0 mcobject_async_free(token->nodes_obj, node);
737 0 }
738  
739 0 void myhtml_token_attr_delete_all(myhtml_token_t* token, myhtml_token_node_t* node)
740 {
741 0 myhtml_token_attr_t* attr = node->attr_first;
742
743 0 ▶ while (attr)
Branch: 1 branch
BranchTrueFalseTotal
while (attr) 0 0 0
744 {
745 0 ▶ if(attr->entry.data && attr->entry.mchar) {
Branch: 2 branches
BranchTrueFalseTotal
if(attr->entry.data && attr->entry.mchar) { 0 0 0
if(attr->entry.data && attr->entry.mchar) { 0 0 0
746 0 mchar_async_free(attr->entry.mchar, attr->entry.node_idx, attr->entry.data);
747 }
748
749 0 attr = attr->next;
750 }
751 0 }
752  
753 0 myhtml_token_attr_t * myhtml_token_attr_remove(myhtml_token_node_t* node, myhtml_token_attr_t* attr)
754 {
755 0 ▶ if(attr)
Branch: 1 branch
BranchTrueFalseTotal
if(attr) 0 0 0
756 {
757 0 ▶ if(attr->prev) {
Branch: 1 branch
BranchTrueFalseTotal
if(attr->prev) { 0 0 0
758 0 attr->prev->next = attr->next;
759 }
760 else {
761 0 node->attr_first = attr->next;
762 }
763
764 0 ▶ if(attr->next) {
Branch: 1 branch
BranchTrueFalseTotal
if(attr->next) { 0 0 0
765 0 attr->next->prev = attr->prev;
766 }
767 else {
768 0 node->attr_last = attr->prev;
769 }
770
771 0 attr->next = NULL;
772 0 attr->prev = NULL;
773 }
774
775 0 return attr;
776 }
777  
778 0 myhtml_token_attr_t * myhtml_token_attr_remove_by_name(myhtml_token_node_t* node, const char* name, size_t name_length)
779 {
780 0 return myhtml_token_attr_remove(node, myhtml_token_attr_by_name(node, name, name_length));
781 }
782  
783 0 bool myhtml_token_is_whithspace(myhtml_tree_t* tree, myhtml_token_node_t* node)
784 {
785 0 const char* html = node->my_str_tm.data;
786
787 size_t i;
788 0 ▶ for (i = node->begin; i < node->length; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = node->begin; i < node->length; i++) 0 0 0
789 {
790 // TODO: see and use myhtml_whithspace
791 // U+0009 // U+000A // U+000C // U+000D // U+0020
792 0 ▶ if(html[i] != '\t' && html[i] != '\n' && html[i] != '\f' && html[i] != '\r' && html[i] != ' ') {
Branch: 5 branches
BranchTrueFalseTotal
if(html[i] != '\t' && html[i] != '\n' && html[i] != '\f' && html[i] != '\r' && html[i] != ' ') { 0 0 0
if(html[i] != '\t' && html[i] != '\n' && html[i] != '\f' && html[i] != '\r' && html[i] != ' ') { 0 0 0
if(html[i] != '\t' && html[i] != '\n' && html[i] != '\f' && html[i] != '\r' && html[i] != ' ') { 0 0 0
if(html[i] != '\t' && html[i] != '\n' && html[i] != '\f' && html[i] != '\r' && html[i] != ' ') { 0 0 0
if(html[i] != '\t' && html[i] != '\n' && html[i] != '\f' && html[i] != '\r' && html[i] != ' ') { 0 0 0
793 0 return false;
794 }
795 }
796
797 0 return true;
798 }
799  
800 0 myhtml_token_node_t * myhtml_token_merged_two_token_string(myhtml_tree_t* tree, myhtml_token_node_t* token_to, myhtml_token_node_t* token_from, bool cp_reverse)
801 {
802 0 myhtml_token_node_wait_for_done(token_to);
803 0 myhtml_token_node_wait_for_done(token_from);
804
805 0 myhtml_string_t *string1 = &token_to->my_str_tm;
806 0 myhtml_string_t *string2 = &token_from->my_str_tm;
807
808 0 ▶ if(token_to->my_str_tm.node_idx == tree->mchar_node_id)
Branch: 1 branch
BranchTrueFalseTotal
if(token_to->my_str_tm.node_idx == tree->mchar_node_id) 0 0 0
809 {
810 0 token_to->length = token_to->length + token_from->length;
811
812 0 ▶ if(cp_reverse) {
Branch: 1 branch
BranchTrueFalseTotal
if(cp_reverse) { 0 0 0
813 //myhtml_string_copy(string2, &string_base);
814 }
815 else {
816 0 myhtml_string_copy(string1, string2);
817 }
818
819 0 return token_to;
820 }
821 0 ▶ if(token_from->my_str_tm.node_idx == tree->mchar_node_id)
Branch: 1 branch
BranchTrueFalseTotal
if(token_from->my_str_tm.node_idx == tree->mchar_node_id) 0 0 0
822 {
823 0 token_from->length = token_to->length + token_from->length;
824
825 0 ▶ if(cp_reverse) {
Branch: 1 branch
BranchTrueFalseTotal
if(cp_reverse) { 0 0 0
826 0 myhtml_string_copy(string2, string1);
827 }
828 else {
829 0 myhtml_string_copy(string1, string2);
830 }
831
832 0 return token_from;
833 }
834 else {
835 myhtml_string_t string_base;
836 0 myhtml_string_init(tree->mchar, tree->mchar_node_id, &string_base, (token_to->length + 2));
837
838 0 token_to->length = token_to->length + token_from->length;
839
840 0 ▶ if(cp_reverse) {
Branch: 1 branch
BranchTrueFalseTotal
if(cp_reverse) { 0 0 0
841 0 myhtml_string_copy(&string_base, string2);
842 0 myhtml_string_copy(&string_base, string1);
843 }
844 else {
845 0 myhtml_string_copy(&string_base, string1);
846 0 myhtml_string_copy(&string_base, string2);
847 }
848
849 0 token_to->my_str_tm = string_base;
850 }
851
852 0 return token_to;
853 }
854  
855 0 void myhtml_token_set_replacement_character_for_null_token(myhtml_tree_t* tree, myhtml_token_node_t* node)
856 {
857 0 myhtml_token_node_wait_for_done(node);
858
859 myhtml_string_t new_str;
860 0 myhtml_string_init(tree->mchar, tree->mchar_node_id, &new_str, (node->my_str_tm.length + 32));
861
862 0 myhtml_string_append_with_replacement_null_characters_only(&new_str, node->my_str_tm.data, node->my_str_tm.length);
863
864 0 node->length = new_str.length;
865
866 // TODO: send to cache prev str
867 0 node->my_str_tm = new_str;
868 0 }
869  
870 0 void myhtml_token_set_done(myhtml_token_node_t* node)
871 {
872 0 node->type |= MyHTML_TOKEN_TYPE_DONE;
873 0 }
874  
875 0 void myhtml_token_print_param_by_idx(myhtml_tree_t* myhtml_tree, myhtml_token_node_t* node, FILE* out)
876 {
877 0 ▶ if(node->type & MyHTML_TOKEN_TYPE_CLOSE) {
Branch: 1 branch
BranchTrueFalseTotal
if(node->type & MyHTML_TOKEN_TYPE_CLOSE) { 0 0 0
878 0 fprintf(out, "</");
879 }
880 else {
881 0 fprintf(out, "<");
882 }
883
884 0 fprintf(out, "tag_ctx_idx=%zu; body_begin=%zu; body_length=%zu; attr_first=%zu; attr_last=%zu",
885 node->tag_ctx_idx, node->begin, node->length,
886 0 (size_t)node->attr_first, (size_t)node->attr_last);
887
888 0 ▶ if(node->type & MyHTML_TOKEN_TYPE_CLOSE_SELF) {
Branch: 1 branch
BranchTrueFalseTotal
if(node->type & MyHTML_TOKEN_TYPE_CLOSE_SELF) { 0 0 0
889 0 fprintf(out, " />\n");
890 }
891 else {
892 0 fprintf(out, ">\n");
893 }
894 0 }
895  
896 0 void myhtml_token_print_by_idx(myhtml_tree_t* tree, myhtml_token_node_t* node, FILE* out)
897 {
898 0 const myhtml_tag_context_t *ctx = myhtml_tag_get_by_id(tree->tags, node->tag_ctx_idx);
899
900 0 ▶ if(node->tag_ctx_idx == MyHTML_TAG__TEXT ||
Branch: 1 branch
BranchTrueFalseTotal
if(node->tag_ctx_idx == MyHTML_TAG__TEXT || 0 0 0
901 0 ▶ node->tag_ctx_idx == MyHTML_TAG__COMMENT)
Branch: 1 branch
BranchTrueFalseTotal
node->tag_ctx_idx == MyHTML_TAG__COMMENT) 0 0 0
902 {
903 0 ▶ if(node->length) {
Branch: 1 branch
BranchTrueFalseTotal
if(node->length) { 0 0 0
904 0 fprintf(out, "%.*s: %.*s\n", (int)ctx->name_length, ctx->name,
905 0 (int)node->length, &node->my_str_tm.data[node->begin]);
906 }
907 else {
908 0 fprintf(out, "%.*s is empty\n", (int)ctx->name_length, ctx->name);
909 }
910 }
911 else
912 {
913 0 ▶ if(node->type & MyHTML_TOKEN_TYPE_CLOSE) {
Branch: 1 branch
BranchTrueFalseTotal
if(node->type & MyHTML_TOKEN_TYPE_CLOSE) { 0 0 0
914 0 fprintf(out, "</");
915 }
916 else {
917 0 fprintf(out, "<");
918 }
919
920 0 fprintf(out, "%.*s tagid=\"%zu\"", (int)ctx->name_length, ctx->name, node->tag_ctx_idx);
921
922 0 myhtml_token_print_attr(tree, node, out);
923
924 0 ▶ if(node->type & MyHTML_TOKEN_TYPE_CLOSE_SELF) {
Branch: 1 branch
BranchTrueFalseTotal
if(node->type & MyHTML_TOKEN_TYPE_CLOSE_SELF) { 0 0 0
925 0 fprintf(out, " />\n");
926 }
927 else {
928 0 fprintf(out, ">\n");
929 }
930 }
931 0 }
932  
933 0 void myhtml_token_print_attr(myhtml_tree_t* tree, myhtml_token_node_t* node, FILE* out)
934 {
935 0 myhtml_token_attr_t* attr = node->attr_first;
936
937 0 ▶ while(attr)
Branch: 1 branch
BranchTrueFalseTotal
while(attr) 0 0 0
938 {
939 0 fprintf(out, " %.*s", (int)attr->name_length, &attr->entry.data[attr->name_begin]);
940
941 0 ▶ if(attr->my_namespace != MyHTML_NAMESPACE_HTML)
Branch: 1 branch
BranchTrueFalseTotal
if(attr->my_namespace != MyHTML_NAMESPACE_HTML) 0 0 0
942 {
943 0 switch (attr->my_namespace) {
944 0 case MyHTML_NAMESPACE_SVG:
945 0 fprintf(out, ":svg");
946 0 break;
947 0 case MyHTML_NAMESPACE_MATHML:
948 0 fprintf(out, ":math");
949 0 break;
950 0 case MyHTML_NAMESPACE_XLINK:
951 0 fprintf(out, ":xlink");
952 0 break;
953 0 case MyHTML_NAMESPACE_XML:
954 0 fprintf(out, ":xml");
955 0 break;
956 0 case MyHTML_NAMESPACE_XMLNS:
957 0 fprintf(out, ":xmlns");
958 0 break;
959 0 default:
960 0 fprintf(out, ":UNDEF");
961 0 break;
962 }
963 }
964
965 0 ▶ if(attr->value_begin) {
Branch: 1 branch
BranchTrueFalseTotal
if(attr->value_begin) { 0 0 0
966 0 fprintf(out, "=\"%.*s\"",(int)attr->value_length, &attr->entry.data[attr->value_begin]);
967 }
968
969 0 attr = attr->next;
970 }
971 0 }
972  
973  
« MyHTML.xs ↑ Summary xs/tree.xs »