third_party/modest/source/myhtml/myhtml.c

filter: Statementstmt 0.0% 0 / 772 Branchbran 0.0% 0 / 598 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 1370 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« third_party/modest/source/myhtml/data_process.c ↑ Summary third_party/modest/source/myhtml/mynamespace.c »
1 /*
2 Copyright (C) 2015-2017 Alexander Borisov
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18 Author: lex.borisov@gmail.com (Alexander Borisov)
19 */
20  
21 #include "myhtml/myhtml.h"
22  
23 0 void myhtml_init_marker(myhtml_t* myhtml)
24 {
25 0 myhtml->marker = (myhtml_tree_node_t*)mycore_malloc(sizeof(myhtml_tree_node_t));
26
27 0 ▶ if(myhtml->marker)
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml->marker) 0 0 0
28 0 myhtml_tree_node_clean(myhtml->marker);
29 0 }
30  
31 0 void myhtml_destroy_marker(myhtml_t* myhtml)
32 {
33 0 ▶ if(myhtml->marker)
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml->marker) 0 0 0
34 0 mycore_free(myhtml->marker);
35 0 }
36  
37 #ifndef MyCORE_BUILD_WITHOUT_THREADS
38 0 mystatus_t myhtml_stream_create(myhtml_t* myhtml, mystatus_t* status, size_t count, size_t id_increase)
39 {
40 0 ▶ if(count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(count == 0) { 0 0 0
41 0 myhtml->thread_stream = NULL;
42
43 0 *status = MyHTML_STATUS_OK;
44 0 return *status;
45 }
46
47 0 myhtml->thread_stream = mythread_create();
48 0 ▶ if(myhtml->thread_stream == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml->thread_stream == NULL) 0 0 0
49 0 *status = MyCORE_STATUS_THREAD_ERROR_MEMORY_ALLOCATION;
50
51 0 *status = mythread_init(myhtml->thread_stream, MyTHREAD_TYPE_STREAM, count, id_increase);
52
53 0 ▶ if(*status)
Branch: 1 branch
BranchTrueFalseTotal
if(*status) 0 0 0
54 0 myhtml->thread_stream = mythread_destroy(myhtml->thread_stream, NULL, NULL, true);
55
56 0 return *status;
57 }
58  
59 0 mystatus_t myhtml_batch_create(myhtml_t* myhtml, mystatus_t* status, size_t count, size_t id_increase)
60 {
61 0 ▶ if(count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(count == 0) { 0 0 0
62 0 myhtml->thread_batch = NULL;
63
64 0 *status = MyHTML_STATUS_OK;
65 0 return *status;
66 }
67
68 0 myhtml->thread_batch = mythread_create();
69 0 ▶ if(myhtml->thread_stream == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml->thread_stream == NULL) { 0 0 0
70 0 myhtml->thread_stream = mythread_destroy(myhtml->thread_stream, NULL, NULL, true);
71 0 *status = MyCORE_STATUS_THREAD_ERROR_MEMORY_ALLOCATION;
72 }
73
74 0 *status = mythread_init(myhtml->thread_batch, MyTHREAD_TYPE_BATCH, count, id_increase);
75
76 0 ▶ if(*status)
Branch: 1 branch
BranchTrueFalseTotal
if(*status) 0 0 0
77 0 myhtml->thread_batch = mythread_destroy(myhtml->thread_batch , NULL, NULL, true);
78
79 0 return *status;
80 }
81  
82 0 mystatus_t myhtml_create_stream_and_batch(myhtml_t* myhtml, size_t stream_count, size_t batch_count)
83 {
84 mystatus_t status;
85
86 /* stream */
87 0 ▶ if(myhtml_stream_create(myhtml, &status, stream_count, 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml_stream_create(myhtml, &status, stream_count, 0)) { 0 0 0
88 0 return status;
89 }
90
91 /* batch */
92 0 ▶ if(myhtml_batch_create(myhtml, &status, batch_count, stream_count)) {
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml_batch_create(myhtml, &status, batch_count, stream_count)) { 0 0 0
93 0 myhtml->thread_stream = mythread_destroy(myhtml->thread_stream, NULL, NULL, true);
94 0 return status;
95 }
96
97 0 return status;
98 }
99 #endif /* if undef MyCORE_BUILD_WITHOUT_THREADS */
100  
101 0 myhtml_t * myhtml_create(void)
102 {
103 0 return (myhtml_t*)mycore_calloc(1, sizeof(myhtml_t));
104 }
105  
106 0 mystatus_t myhtml_init(myhtml_t* myhtml, enum myhtml_options opt, size_t thread_count, size_t queue_size)
107 {
108 mystatus_t status;
109
110 0 myhtml->opt = opt;
111 0 myhtml_init_marker(myhtml);
112
113 0 status = myhtml_tokenizer_state_init(myhtml);
114 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
115 0 return status;
116
117 0 status = myhtml_rules_init(myhtml);
118  
119 #ifdef MyCORE_BUILD_WITHOUT_THREADS
120
121 myhtml->thread_stream = NULL;
122 myhtml->thread_batch = NULL;
123 myhtml->thread_total = 0;
124
125 #else /* if undef MyCORE_BUILD_WITHOUT_THREADS */
126 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
127 0 return status;
128  
129 0 ▶ if(thread_count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(thread_count == 0) { 0 0 0
130 0 thread_count = 1;
131 }
132  
133 0 switch (opt) {
134 0 case MyHTML_OPTIONS_PARSE_MODE_SINGLE:
135 0 ▶ if((status = myhtml_create_stream_and_batch(myhtml, 0, 0)))
Branch: 1 branch
BranchTrueFalseTotal
if((status = myhtml_create_stream_and_batch(myhtml, 0, 0))) 0 0 0
136 0 return status;
137
138 0 break;
139
140 0 case MyHTML_OPTIONS_PARSE_MODE_ALL_IN_ONE:
141 0 ▶ if((status = myhtml_create_stream_and_batch(myhtml, 1, 0)))
Branch: 1 branch
BranchTrueFalseTotal
if((status = myhtml_create_stream_and_batch(myhtml, 1, 0))) 0 0 0
142 0 return status;
143
144 0 myhtml->thread_stream->context = mythread_queue_list_create(&status);
145 0 status = myhread_entry_create(myhtml->thread_stream, mythread_function_queue_stream, myhtml_parser_worker_stream, MyTHREAD_OPT_STOP);
146
147 0 break;
148
149 0 default:
150 // default MyHTML_OPTIONS_PARSE_MODE_SEPARATELY
151 0 ▶ if(thread_count < 2)
Branch: 1 branch
BranchTrueFalseTotal
if(thread_count < 2) 0 0 0
152 0 thread_count = 2;
153
154 0 ▶ if((status = myhtml_create_stream_and_batch(myhtml, 1, (thread_count - 1))))
Branch: 1 branch
BranchTrueFalseTotal
if((status = myhtml_create_stream_and_batch(myhtml, 1, (thread_count - 1)))) 0 0 0
155 0 return status;
156
157 0 myhtml->thread_stream->context = mythread_queue_list_create(&status);
158 0 myhtml->thread_batch->context = myhtml->thread_stream->context;
159
160 0 status = myhread_entry_create(myhtml->thread_stream, mythread_function_queue_stream, myhtml_parser_stream, MyTHREAD_OPT_STOP);
161 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
162 0 return status;
163
164 0 ▶ for(size_t i = 0; i < myhtml->thread_batch->entries_size; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(size_t i = 0; i < myhtml->thread_batch->entries_size; i++) { 0 0 0
165 0 status = myhread_entry_create(myhtml->thread_batch, mythread_function_queue_batch, myhtml_parser_worker, MyTHREAD_OPT_STOP);
166
167 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
168 0 return status;
169 }
170
171 0 break;
172 }
173
174 0 myhtml->thread_total = thread_count;
175
176 0 myhtml->thread_list[0] = myhtml->thread_stream;
177 0 myhtml->thread_list[1] = myhtml->thread_batch;
178 0 myhtml->thread_list[2] = NULL;
179
180 #endif /* if undef MyCORE_BUILD_WITHOUT_THREADS */
181
182 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
183 0 return status;
184
185 0 myhtml_clean(myhtml);
186
187 0 return status;
188 }
189  
190 0 void myhtml_clean(myhtml_t* myhtml)
191 {
192 /* some code */
193 0 }
194  
195 0 myhtml_t* myhtml_destroy(myhtml_t* myhtml)
196 {
197 0 ▶ if(myhtml == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml == NULL) 0 0 0
198 0 return NULL;
199
200 0 myhtml_destroy_marker(myhtml);
201
202 #ifndef MyCORE_BUILD_WITHOUT_THREADS
203 0 ▶ if(myhtml->thread_stream) {
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml->thread_stream) { 0 0 0
204 0 mythread_queue_list_t* queue_list = myhtml->thread_stream->context;
205  
206 0 ▶ if(queue_list)
Branch: 1 branch
BranchTrueFalseTotal
if(queue_list) 0 0 0
207 0 mythread_queue_list_wait_for_done(myhtml->thread_stream, queue_list);
208
209 0 myhtml->thread_stream = mythread_destroy(myhtml->thread_stream, mythread_callback_quit, NULL, true);
210
211 0 ▶ if(myhtml->thread_batch)
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml->thread_batch) 0 0 0
212 0 myhtml->thread_batch = mythread_destroy(myhtml->thread_batch, mythread_callback_quit, NULL, true);
213
214 0 ▶ if(queue_list)
Branch: 1 branch
BranchTrueFalseTotal
if(queue_list) 0 0 0
215 0 mythread_queue_list_destroy(queue_list);
216 }
217 #endif /* if undef MyCORE_BUILD_WITHOUT_THREADS */
218
219 0 myhtml_tokenizer_state_destroy(myhtml);
220
221 0 ▶ if(myhtml->insertion_func)
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml->insertion_func) 0 0 0
222 0 mycore_free(myhtml->insertion_func);
223
224 0 mycore_free(myhtml);
225
226 0 return NULL;
227 }
228  
229 0 mystatus_t myhtml_parse(myhtml_tree_t* tree, myencoding_t encoding, const char* html, size_t html_size)
230 {
231 0 ▶ if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) {
Branch: 1 branch
BranchTrueFalseTotal
if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { 0 0 0
232 0 myhtml_tree_clean(tree);
233 }
234
235 0 myhtml_encoding_set(tree, encoding);
236 0 mystatus_t status = myhtml_tokenizer_begin(tree, html, html_size);
237
238 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
239 0 return status;
240
241 0 return myhtml_tokenizer_end(tree);
242 }
243  
244 0 mystatus_t myhtml_parse_fragment(myhtml_tree_t* tree, myencoding_t encoding, const char* html, size_t html_size, myhtml_tag_id_t tag_id, enum myhtml_namespace ns)
245 {
246 0 ▶ if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) {
Branch: 1 branch
BranchTrueFalseTotal
if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { 0 0 0
247 0 myhtml_tree_clean(tree);
248 }
249
250 0 ▶ if(tag_id == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(tag_id == 0) 0 0 0
251 0 tag_id = MyHTML_TAG_DIV;
252
253 0 ▶ if(ns == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(ns == 0) 0 0 0
254 0 ns = MyHTML_NAMESPACE_HTML;
255
256 0 ▶ if(myhtml_tokenizer_fragment_init(tree, tag_id, ns) == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml_tokenizer_fragment_init(tree, tag_id, ns) == NULL) 0 0 0
257 0 return MyHTML_STATUS_TOKENIZER_ERROR_FRAGMENT_INIT;
258
259 0 myhtml_encoding_set(tree, encoding);
260 0 mystatus_t status = myhtml_tokenizer_begin(tree, html, html_size);
261
262 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
263 0 return status;
264
265 0 return myhtml_tokenizer_end(tree);
266 }
267  
268 0 mystatus_t myhtml_parse_single(myhtml_tree_t* tree, myencoding_t encoding, const char* html, size_t html_size)
269 {
270 0 ▶ if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) {
Branch: 1 branch
BranchTrueFalseTotal
if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { 0 0 0
271 0 myhtml_tree_clean(tree);
272 }
273
274 0 tree->flags |= MyHTML_TREE_FLAGS_SINGLE_MODE;
275
276 0 myhtml_encoding_set(tree, encoding);
277
278 0 mystatus_t status = myhtml_tokenizer_begin(tree, html, html_size);
279
280 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
281 0 return status;
282
283 0 return myhtml_tokenizer_end(tree);
284 }
285  
286 0 mystatus_t myhtml_parse_fragment_single(myhtml_tree_t* tree, myencoding_t encoding, const char* html, size_t html_size, myhtml_tag_id_t tag_id, enum myhtml_namespace ns)
287 {
288 0 ▶ if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) {
Branch: 1 branch
BranchTrueFalseTotal
if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { 0 0 0
289 0 myhtml_tree_clean(tree);
290 }
291
292 0 ▶ if(tag_id == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(tag_id == 0) 0 0 0
293 0 tag_id = MyHTML_TAG_DIV;
294
295 0 ▶ if(ns == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(ns == 0) 0 0 0
296 0 ns = MyHTML_NAMESPACE_HTML;
297
298 0 tree->flags |= MyHTML_TREE_FLAGS_SINGLE_MODE;
299
300 0 ▶ if(myhtml_tokenizer_fragment_init(tree, tag_id, ns) == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml_tokenizer_fragment_init(tree, tag_id, ns) == NULL) 0 0 0
301 0 return MyHTML_STATUS_TOKENIZER_ERROR_FRAGMENT_INIT;
302
303 0 myhtml_encoding_set(tree, encoding);
304
305 0 mystatus_t status = myhtml_tokenizer_begin(tree, html, html_size);
306
307 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
308 0 return status;
309
310 0 return myhtml_tokenizer_end(tree);
311 }
312  
313 0 mystatus_t myhtml_parse_chunk(myhtml_tree_t* tree, const char* html, size_t html_size)
314 {
315 0 ▶ if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) {
Branch: 1 branch
BranchTrueFalseTotal
if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { 0 0 0
316 0 myhtml_tree_clean(tree);
317 }
318
319 0 return myhtml_tokenizer_chunk(tree, html, html_size);
320 }
321  
322 0 mystatus_t myhtml_parse_chunk_fragment(myhtml_tree_t* tree, const char* html, size_t html_size, myhtml_tag_id_t tag_id, enum myhtml_namespace ns)
323 {
324 0 ▶ if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) {
Branch: 1 branch
BranchTrueFalseTotal
if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { 0 0 0
325 0 myhtml_tree_clean(tree);
326 }
327
328 0 ▶ if(tag_id == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(tag_id == 0) 0 0 0
329 0 tag_id = MyHTML_TAG_DIV;
330
331 0 ▶ if(ns == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(ns == 0) 0 0 0
332 0 ns = MyHTML_NAMESPACE_HTML;
333
334 0 ▶ if(myhtml_tokenizer_fragment_init(tree, tag_id, ns) == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml_tokenizer_fragment_init(tree, tag_id, ns) == NULL) 0 0 0
335 0 return MyHTML_STATUS_TOKENIZER_ERROR_FRAGMENT_INIT;
336
337 0 return myhtml_tokenizer_chunk(tree, html, html_size);
338 }
339  
340 0 mystatus_t myhtml_parse_chunk_single(myhtml_tree_t* tree, const char* html, size_t html_size)
341 {
342 0 ▶ if((tree->flags & MyHTML_TREE_FLAGS_SINGLE_MODE) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if((tree->flags & MyHTML_TREE_FLAGS_SINGLE_MODE) == 0) 0 0 0
343 0 tree->flags |= MyHTML_TREE_FLAGS_SINGLE_MODE;
344
345 0 return myhtml_parse_chunk(tree, html, html_size);
346 }
347  
348 0 mystatus_t myhtml_parse_chunk_fragment_single(myhtml_tree_t* tree, const char* html, size_t html_size, myhtml_tag_id_t tag_id, enum myhtml_namespace ns)
349 {
350 0 ▶ if((tree->flags & MyHTML_TREE_FLAGS_SINGLE_MODE) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if((tree->flags & MyHTML_TREE_FLAGS_SINGLE_MODE) == 0) 0 0 0
351 0 tree->flags |= MyHTML_TREE_FLAGS_SINGLE_MODE;
352
353 0 return myhtml_parse_chunk_fragment(tree, html, html_size, tag_id, ns);
354 }
355  
356 0 mystatus_t myhtml_parse_chunk_end(myhtml_tree_t* tree)
357 {
358 0 return myhtml_tokenizer_end(tree);
359 }
360  
361 0 void myhtml_encoding_set(myhtml_tree_t* tree, myencoding_t encoding)
362 {
363 0 ▶ if(encoding >= MyENCODING_LAST_ENTRY)
Branch: 1 branch
BranchTrueFalseTotal
if(encoding >= MyENCODING_LAST_ENTRY) 0 0 0
364 0 return;
365
366 0 tree->encoding_usereq = encoding;
367 0 tree->encoding = encoding;
368 }
369  
370 0 myencoding_t myhtml_encoding_get(myhtml_tree_t* tree)
371 {
372 0 return tree->encoding;
373 }
374  
375 /*
376 * Nodes
377 */
378  
379 0 mystatus_t myhtml_get_nodes_by_tag_id_in_scope_find_recursion(myhtml_tree_node_t *node, myhtml_collection_t *collection, myhtml_tag_id_t tag_id)
380 {
381 0 ▶ while(node) {
Branch: 1 branch
BranchTrueFalseTotal
while(node) { 0 0 0
382 0 ▶ if(node->tag_id == tag_id) {
Branch: 1 branch
BranchTrueFalseTotal
if(node->tag_id == tag_id) { 0 0 0
383 0 collection->list[ collection->length ] = node;
384 0 collection->length++;
385
386 0 ▶ if(collection->length >= collection->size)
Branch: 1 branch
BranchTrueFalseTotal
if(collection->length >= collection->size) 0 0 0
387 {
388 0 mystatus_t mystatus = myhtml_collection_check_size(collection, 1024, 0);
389
390 0 ▶ if(mystatus != MyHTML_STATUS_OK)
Branch: 1 branch
BranchTrueFalseTotal
if(mystatus != MyHTML_STATUS_OK) 0 0 0
391 0 return mystatus;
392 }
393 }
394
395 0 ▶ if(node->child)
Branch: 1 branch
BranchTrueFalseTotal
if(node->child) 0 0 0
396 0 myhtml_get_nodes_by_tag_id_in_scope_find_recursion(node->child, collection, tag_id);
397
398 0 node = node->next;
399 }
400
401 0 return MyHTML_STATUS_OK;
402 }
403  
404 0 myhtml_collection_t * myhtml_get_nodes_by_tag_id_in_scope(myhtml_tree_t* tree, myhtml_collection_t *collection, myhtml_tree_node_t *node, myhtml_tag_id_t tag_id, mystatus_t *status)
405 {
406 0 ▶ if(node == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(node == NULL) 0 0 0
407 0 return NULL;
408
409 0 mystatus_t mystatus = MyHTML_STATUS_OK;
410
411 0 ▶ if(collection == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(collection == NULL) { 0 0 0
412 0 collection = myhtml_collection_create(1024, &mystatus);
413 }
414
415 0 ▶ if(mystatus) {
Branch: 1 branch
BranchTrueFalseTotal
if(mystatus) { 0 0 0
416 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
417 0 *status = mystatus;
418
419 0 return collection;
420 }
421
422 0 ▶ if(node->child)
Branch: 1 branch
BranchTrueFalseTotal
if(node->child) 0 0 0
423 0 mystatus = myhtml_get_nodes_by_tag_id_in_scope_find_recursion(node->child, collection, tag_id);
424
425 0 collection->list[collection->length] = NULL;
426
427 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
428 0 *status = mystatus;
429
430 0 return collection;
431 }
432  
433 0 myhtml_collection_t * myhtml_get_nodes_by_name_in_scope(myhtml_tree_t* tree, myhtml_collection_t *collection, myhtml_tree_node_t *node, const char* html, size_t length, mystatus_t *status)
434 {
435 0 const myhtml_tag_context_t *tag_ctx = myhtml_tag_get_by_name(tree->tags, html, length);
436 0 ▶ if(tag_ctx == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(tag_ctx == NULL) { 0 0 0
437 0 return NULL;
438 }
439 0 return myhtml_get_nodes_by_tag_id_in_scope(tree, collection, node, tag_ctx->id, status);
440 }
441  
442 0 myhtml_collection_t * myhtml_get_nodes_by_tag_id(myhtml_tree_t* tree, myhtml_collection_t *collection, myhtml_tag_id_t tag_id, mystatus_t *status)
443 {
444 0 ▶ if(collection == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(collection == NULL) { 0 0 0
445 0 collection = myhtml_collection_create(1024, NULL);
446
447 0 ▶ if(collection == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(collection == NULL) 0 0 0
448 0 return NULL;
449 }
450
451 0 myhtml_tree_node_t *node = tree->node_html;
452
453 0 ▶ while(node)
Branch: 1 branch
BranchTrueFalseTotal
while(node) 0 0 0
454 {
455 0 ▶ if(node->tag_id == tag_id)
Branch: 1 branch
BranchTrueFalseTotal
if(node->tag_id == tag_id) 0 0 0
456 {
457 0 ▶ if(myhtml_collection_check_size(collection, 1, 1024) == MyHTML_STATUS_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml_collection_check_size(collection, 1, 1024) == MyHTML_STATUS_OK) { 0 0 0
458 0 collection->list[ collection->length ] = node;
459 0 collection->length++;
460 }
461 else {
462 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
463 0 *status = MyHTML_STATUS_ERROR_MEMORY_ALLOCATION;
464
465 0 return collection;
466 }
467 }
468
469 0 ▶ if(node->child)
Branch: 1 branch
BranchTrueFalseTotal
if(node->child) 0 0 0
470 0 node = node->child;
471 else {
472 0 ▶ while(node != tree->node_html && node->next == NULL)
Branch: 2 branches
BranchTrueFalseTotal
while(node != tree->node_html && node->next == NULL) 0 0 0
while(node != tree->node_html && node->next == NULL) 0 0 0
473 0 node = node->parent;
474
475 0 ▶ if(node == tree->node_html)
Branch: 1 branch
BranchTrueFalseTotal
if(node == tree->node_html) 0 0 0
476 0 break;
477
478 0 node = node->next;
479 }
480 }
481
482 0 ▶ if(myhtml_collection_check_size(collection, 1, 1024) == MyHTML_STATUS_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if(myhtml_collection_check_size(collection, 1, 1024) == MyHTML_STATUS_OK) { 0 0 0
483 0 collection->list[ collection->length ] = NULL;
484 }
485 0 ▶ else if(status) {
Branch: 1 branch
BranchTrueFalseTotal
else if(status) { 0 0 0
486 0 *status = MyHTML_STATUS_ERROR_MEMORY_ALLOCATION;
487 }
488
489 0 return collection;
490 }
491  
492 0 myhtml_collection_t * myhtml_get_nodes_by_name(myhtml_tree_t* tree, myhtml_collection_t *collection, const char* html, size_t length, mystatus_t *status)
493 {
494 0 const myhtml_tag_context_t *tag_ctx = myhtml_tag_get_by_name(tree->tags, html, length);
495
496 0 ▶ if(tag_ctx == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(tag_ctx == NULL) 0 0 0
497 0 return NULL;
498
499 0 return myhtml_get_nodes_by_tag_id(tree, collection, tag_ctx->id, status);
500 }
501  
502 /*
503 * Manipulate Nodes
504 */
505 0 myhtml_tree_node_t * myhtml_node_first(myhtml_tree_t* tree)
506 {
507 0 ▶ if(tree->fragment) {
Branch: 1 branch
BranchTrueFalseTotal
if(tree->fragment) { 0 0 0
508 // document -> html -> need element
509 0 ▶ if(tree->document && tree->document->child)
Branch: 2 branches
BranchTrueFalseTotal
if(tree->document && tree->document->child) 0 0 0
if(tree->document && tree->document->child) 0 0 0
510 0 return tree->document->child->child;
511 }
512 0 ▶ else if(tree->document) {
Branch: 1 branch
BranchTrueFalseTotal
else if(tree->document) { 0 0 0
513 // document -> html
514 0 return tree->document->child;
515 }
516
517 0 return NULL;
518 }
519  
520 0 myhtml_tree_node_t * myhtml_node_next(myhtml_tree_node_t *node)
521 {
522 0 return node->next;
523 }
524  
525 0 myhtml_tree_node_t * myhtml_node_prev(myhtml_tree_node_t *node)
526 {
527 0 return node->prev;
528 }
529  
530 0 myhtml_tree_node_t * myhtml_node_parent(myhtml_tree_node_t *node)
531 {
532 0 return node->parent;
533 }
534  
535 0 myhtml_tree_node_t * myhtml_node_child(myhtml_tree_node_t *node)
536 {
537 0 return node->child;
538 }
539  
540 0 myhtml_tree_node_t * myhtml_node_last_child(myhtml_tree_node_t *node)
541 {
542 0 return node->last_child;
543 }
544  
545 0 myhtml_tree_node_t * myhtml_node_create(myhtml_tree_t* tree, myhtml_tag_id_t tag_id, enum myhtml_namespace ns)
546 {
547 0 myhtml_tree_node_t *node = myhtml_tree_node_create(tree);
548
549 0 node->tag_id = tag_id;
550 0 node->ns = ns;
551
552 0 return node;
553 }
554  
555 0 myhtml_tree_node_t * myhtml_node_remove(myhtml_tree_node_t *node)
556 {
557 0 return myhtml_tree_node_remove(node);
558 }
559  
560 0 void myhtml_node_delete(myhtml_tree_node_t *node)
561 {
562 0 myhtml_tree_node_delete(node);
563 0 }
564  
565 0 void myhtml_node_delete_recursive(myhtml_tree_node_t *node)
566 {
567 0 myhtml_tree_node_delete_recursive(node);
568 0 }
569  
570 0 void myhtml_node_free(myhtml_tree_node_t *node)
571 {
572 0 myhtml_tree_node_free(node);
573 0 }
574  
575 0 myhtml_tree_node_t * myhtml_node_insert_before(myhtml_tree_node_t *target, myhtml_tree_node_t *node)
576 {
577 0 ▶ if(target == NULL || node == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if(target == NULL || node == NULL) 0 0 0
if(target == NULL || node == NULL) 0 0 0
578 0 return NULL;
579
580 0 myhtml_tree_node_insert_before(target, node);
581
582 0 return node;
583 }
584  
585 0 myhtml_tree_node_t * myhtml_node_insert_after(myhtml_tree_node_t *target, myhtml_tree_node_t *node)
586 {
587 0 ▶ if(target == NULL || node == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if(target == NULL || node == NULL) 0 0 0
if(target == NULL || node == NULL) 0 0 0
588 0 return NULL;
589
590 0 myhtml_tree_node_insert_after(target, node);
591
592 0 return node;
593 }
594  
595 0 myhtml_tree_node_t * myhtml_node_append_child(myhtml_tree_node_t *target, myhtml_tree_node_t *node)
596 {
597 0 ▶ if(target == NULL || node == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if(target == NULL || node == NULL) 0 0 0
if(target == NULL || node == NULL) 0 0 0
598 0 return NULL;
599
600 0 myhtml_tree_node_add_child(target, node);
601
602 0 return node;
603 }
604  
605 0 myhtml_tree_node_t * myhtml_node_insert_to_appropriate_place(myhtml_tree_node_t *target, myhtml_tree_node_t *node)
606 {
607 0 ▶ if(target == NULL || node == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if(target == NULL || node == NULL) 0 0 0
if(target == NULL || node == NULL) 0 0 0
608 0 return NULL;
609
610 enum myhtml_tree_insertion_mode mode;
611
612 0 target->tree->foster_parenting = true;
613 0 target = myhtml_tree_appropriate_place_inserting_in_tree(target, &mode);
614 0 target->tree->foster_parenting = false;
615
616 0 myhtml_tree_node_insert_by_mode(target, node, mode);
617
618 0 return node;
619 }
620  
621 0 mycore_string_t * myhtml_node_text_set(myhtml_tree_node_t *node, const char* text, size_t length, myencoding_t encoding)
622 {
623 0 ▶ if(node == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(node == NULL) 0 0 0
624 0 return NULL;
625
626 0 ▶ if(encoding >= MyENCODING_LAST_ENTRY)
Branch: 1 branch
BranchTrueFalseTotal
if(encoding >= MyENCODING_LAST_ENTRY) 0 0 0
627 0 return NULL;
628
629 0 myhtml_tree_t* tree = node->tree;
630
631 0 ▶ if(node->token == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(node->token == NULL) { 0 0 0
632 0 node->token = myhtml_token_node_create(tree->token, tree->mcasync_rules_token_id);
633
634 0 ▶ if(node->token == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(node->token == NULL) 0 0 0
635 0 return NULL;
636
637 0 node->token->type |= MyHTML_TOKEN_TYPE_DONE;
638 }
639
640 0 ▶ if(node->token->str.data == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(node->token->str.data == NULL) { 0 0 0
641 0 mycore_string_init(tree->mchar, tree->mchar_node_id, &node->token->str, (length + 2));
642 }
643 else {
644 0 ▶ if(node->token->str.size < length) {
Branch: 1 branch
BranchTrueFalseTotal
if(node->token->str.size < length) { 0 0 0
645 0 mchar_async_free(tree->mchar, node->token->str.node_idx, node->token->str.data);
646 0 mycore_string_init(tree->mchar, tree->mchar_node_id, &node->token->str, length);
647 }
648 else
649 0 node->token->str.length = 0;
650 }
651
652 0 ▶ if(encoding != MyENCODING_UTF_8) {
Branch: 1 branch
BranchTrueFalseTotal
if(encoding != MyENCODING_UTF_8) { 0 0 0
653 0 myencoding_string_append(&node->token->str, text, length, encoding);
654 }
655 else {
656 0 mycore_string_append(&node->token->str, text, length);
657 }
658
659 0 node->token->raw_begin = 0;
660 0 node->token->raw_length = 0;
661
662 0 return &node->token->str;
663 }
664  
665 0 mycore_string_t * myhtml_node_text_set_with_charef(myhtml_tree_node_t *node, const char* text, size_t length, myencoding_t encoding)
666 {
667 0 ▶ if(node == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(node == NULL) 0 0 0
668 0 return NULL;
669
670 0 ▶ if(encoding >= MyENCODING_LAST_ENTRY)
Branch: 1 branch
BranchTrueFalseTotal
if(encoding >= MyENCODING_LAST_ENTRY) 0 0 0
671 0 return NULL;
672
673 0 myhtml_tree_t* tree = node->tree;
674
675 0 ▶ if(node->token == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(node->token == NULL) { 0 0 0
676 0 node->token = myhtml_token_node_create(tree->token, tree->mcasync_rules_token_id);
677
678 0 ▶ if(node->token == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(node->token == NULL) 0 0 0
679 0 return NULL;
680
681 0 node->token->type |= MyHTML_TOKEN_TYPE_DONE;
682 }
683
684 0 ▶ if(node->token->str.data == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(node->token->str.data == NULL) { 0 0 0
685 0 mycore_string_init(tree->mchar, tree->mchar_node_id, &node->token->str, (length + 2));
686 }
687 else {
688 0 ▶ if(node->token->str.size < length) {
Branch: 1 branch
BranchTrueFalseTotal
if(node->token->str.size < length) { 0 0 0
689 0 mchar_async_free(tree->mchar, node->token->str.node_idx, node->token->str.data);
690 0 mycore_string_init(tree->mchar, tree->mchar_node_id, &node->token->str, length);
691 }
692 else
693 0 node->token->str.length = 0;
694 }
695
696 myhtml_data_process_entry_t proc_entry;
697 0 myhtml_data_process_entry_clean(&proc_entry);
698
699 0 proc_entry.encoding = encoding;
700 0 myencoding_result_clean(&proc_entry.res);
701
702 0 myhtml_data_process(&proc_entry, &node->token->str, text, length);
703 0 myhtml_data_process_end(&proc_entry, &node->token->str);
704
705 0 node->token->raw_begin = 0;
706 0 node->token->raw_length = 0;
707
708 0 return &node->token->str;
709 }
710  
711 0 myhtml_token_node_t* myhtml_node_token(myhtml_tree_node_t *node)
712 {
713 0 return node->token;
714 }
715  
716 0 myhtml_namespace_t myhtml_node_namespace(myhtml_tree_node_t *node)
717 {
718 0 return node->ns;
719 }
720  
721 0 void myhtml_node_namespace_set(myhtml_tree_node_t *node, myhtml_namespace_t ns)
722 {
723 0 node->ns = ns;
724 0 }
725  
726 0 myhtml_tag_id_t myhtml_node_tag_id(myhtml_tree_node_t *node)
727 {
728 0 return node->tag_id;
729 }
730  
731 0 const char * myhtml_tag_name_by_id(myhtml_tree_t* tree, myhtml_tag_id_t tag_id, size_t *length)
732 {
733 0 ▶ if(length)
Branch: 1 branch
BranchTrueFalseTotal
if(length) 0 0 0
734 0 *length = 0;
735
736 0 ▶ if(tree == NULL || tree->tags == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if(tree == NULL || tree->tags == NULL) 0 0 0
if(tree == NULL || tree->tags == NULL) 0 0 0
737 0 return NULL;
738
739 0 const myhtml_tag_context_t *tag_ctx = myhtml_tag_get_by_id(tree->tags, tag_id);
740
741 0 ▶ if(tag_ctx == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(tag_ctx == NULL) 0 0 0
742 0 return NULL;
743
744 0 ▶ if(length)
Branch: 1 branch
BranchTrueFalseTotal
if(length) 0 0 0
745 0 *length = tag_ctx->name_length;
746
747 0 return tag_ctx->name;
748 }
749  
750 0 myhtml_tag_id_t myhtml_tag_id_by_name(myhtml_tree_t* tree, const char *tag_name, size_t length)
751 {
752 0 ▶ if(tree == NULL || tree->tags == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if(tree == NULL || tree->tags == NULL) 0 0 0
if(tree == NULL || tree->tags == NULL) 0 0 0
753 0 return MyHTML_TAG__UNDEF;
754
755 0 const myhtml_tag_context_t *ctx = myhtml_tag_get_by_name(tree->tags, tag_name, length);
756
757 0 ▶ if(ctx == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(ctx == NULL) 0 0 0
758 0 return MyHTML_TAG__UNDEF;
759
760 0 return ctx->id;
761 }
762  
763 0 bool myhtml_node_is_close_self(myhtml_tree_node_t *node)
764 {
765 0 ▶ if(node->token)
Branch: 1 branch
BranchTrueFalseTotal
if(node->token) 0 0 0
766 0 return (node->token->type & MyHTML_TOKEN_TYPE_CLOSE_SELF);
767
768 0 return false;
769 }
770  
771 0 bool myhtml_node_is_void_element(myhtml_tree_node_t *node)
772 {
773 // http://w3c.github.io/html-reference/syntax.html#void-elements
774 0 ▶ switch (node->tag_id)
Branch: 1 branch
BranchTrueFalseTotal
switch (node->tag_id) 0 0 0
775 {
776 0 case MyHTML_TAG_AREA:
777 case MyHTML_TAG_BASE:
778 case MyHTML_TAG_BR:
779 case MyHTML_TAG_COL:
780 case MyHTML_TAG_COMMAND:
781 case MyHTML_TAG_EMBED:
782 case MyHTML_TAG_HR:
783 case MyHTML_TAG_IMG:
784 case MyHTML_TAG_INPUT:
785 case MyHTML_TAG_KEYGEN:
786 case MyHTML_TAG_LINK:
787 case MyHTML_TAG_META:
788 case MyHTML_TAG_PARAM:
789 case MyHTML_TAG_SOURCE:
790 case MyHTML_TAG_TRACK:
791 case MyHTML_TAG_WBR:
792 {
793 0 return true;
794 }
795 0 default:
796 {
797 0 return false;
798 }
799 }
800 }
801  
802 0 myhtml_tree_attr_t * myhtml_node_attribute_first(myhtml_tree_node_t *node)
803 {
804 0 ▶ if(node->token)
Branch: 1 branch
BranchTrueFalseTotal
if(node->token) 0 0 0
805 0 return node->token->attr_first;
806
807 0 return NULL;
808 }
809  
810 0 myhtml_tree_attr_t * myhtml_node_attribute_last(myhtml_tree_node_t *node)
811 {
812 0 ▶ if(node->token)
Branch: 1 branch
BranchTrueFalseTotal
if(node->token) 0 0 0
813 0 return node->token->attr_last;
814
815 0 return NULL;
816 }
817  
818 0 const char * myhtml_node_text(myhtml_tree_node_t *node, size_t *length)
819 {
820 0 ▶ if(node->token && node->token->str.length && node->token->str.data)
Branch: 3 branches
BranchTrueFalseTotal
if(node->token && node->token->str.length && node->token->str.data) 0 0 0
if(node->token && node->token->str.length && node->token->str.data) 0 0 0
if(node->token && node->token->str.length && node->token->str.data) 0 0 0
821 {
822 0 ▶ if(length)
Branch: 1 branch
BranchTrueFalseTotal
if(length) 0 0 0
823 0 *length = node->token->str.length;
824
825 0 return node->token->str.data;
826 }
827
828 0 ▶ if(length)
Branch: 1 branch
BranchTrueFalseTotal
if(length) 0 0 0
829 0 *length = 0;
830
831 0 return NULL;
832 }
833  
834 0 mycore_string_t * myhtml_node_string(myhtml_tree_node_t *node)
835 {
836 0 ▶ if(node && node->token)
Branch: 2 branches
BranchTrueFalseTotal
if(node && node->token) 0 0 0
if(node && node->token) 0 0 0
837 0 return &node->token->str;
838
839 0 return NULL;
840 }
841  
842 0 myhtml_position_t myhtml_node_raw_position(myhtml_tree_node_t *node)
843 {
844 0 ▶ if(node && node->token)
Branch: 2 branches
BranchTrueFalseTotal
if(node && node->token) 0 0 0
if(node && node->token) 0 0 0
845 0 return (myhtml_position_t){node->token->raw_begin, node->token->raw_length};
846
847 0 return (myhtml_position_t){0, 0};
848 }
849  
850 0 myhtml_position_t myhtml_node_element_position(myhtml_tree_node_t *node)
851 {
852 0 ▶ if(node && node->token)
Branch: 2 branches
BranchTrueFalseTotal
if(node && node->token) 0 0 0
if(node && node->token) 0 0 0
853 0 return (myhtml_position_t){node->token->element_begin, node->token->element_length};
854
855 0 return (myhtml_position_t){0, 0};
856 }
857  
858 0 void myhtml_node_set_data(myhtml_tree_node_t *node, void* data)
859 {
860 0 node->data = data;
861 0 }
862  
863 0 void * myhtml_node_get_data(myhtml_tree_node_t *node)
864 {
865 0 return node->data;
866 }
867  
868 0 myhtml_tree_t * myhtml_node_tree(myhtml_tree_node_t *node)
869 {
870 0 return node->tree;
871 }
872  
873 0 mystatus_t myhtml_get_nodes_by_attribute_key_recursion(myhtml_tree_node_t* node, myhtml_collection_t* collection, const char* key, size_t key_len)
874 {
875 0 ▶ while(node)
Branch: 1 branch
BranchTrueFalseTotal
while(node) 0 0 0
876 {
877 0 ▶ if(node->token && node->token->attr_first) {
Branch: 2 branches
BranchTrueFalseTotal
if(node->token && node->token->attr_first) { 0 0 0
if(node->token && node->token->attr_first) { 0 0 0
878 0 myhtml_tree_attr_t* attr = node->token->attr_first;
879
880 0 ▶ while(attr) {
Branch: 1 branch
BranchTrueFalseTotal
while(attr) { 0 0 0
881 0 mycore_string_t* str_key = &attr->key;
882
883 0 ▶ if(str_key->length == key_len && mycore_strncasecmp(str_key->data, key, key_len) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if(str_key->length == key_len && mycore_strncasecmp(str_key->data, key, key_len) == 0) { 0 0 0
if(str_key->length == key_len && mycore_strncasecmp(str_key->data, key, key_len) == 0) { 0 0 0
884 0 collection->list[ collection->length ] = node;
885
886 0 collection->length++;
887 0 ▶ if(collection->length >= collection->size) {
Branch: 1 branch
BranchTrueFalseTotal
if(collection->length >= collection->size) { 0 0 0
888 0 mystatus_t status = myhtml_collection_check_size(collection, 1024, 0);
889
890 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
891 0 return status;
892 }
893 }
894
895 0 attr = attr->next;
896 }
897 }
898
899 0 ▶ if(node->child) {
Branch: 1 branch
BranchTrueFalseTotal
if(node->child) { 0 0 0
900 0 mystatus_t status = myhtml_get_nodes_by_attribute_key_recursion(node->child, collection, key, key_len);
901
902 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
903 0 return status;
904 }
905
906 0 node = node->next;
907 }
908
909 0 return MyHTML_STATUS_OK;
910 }
911  
912 0 myhtml_collection_t * myhtml_get_nodes_by_attribute_key(myhtml_tree_t *tree, myhtml_collection_t* collection, myhtml_tree_node_t* scope_node, const char* key, size_t key_len, mystatus_t* status)
913 {
914 0 ▶ if(collection == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(collection == NULL) { 0 0 0
915 0 collection = myhtml_collection_create(1024, status);
916
917 0 ▶ if((status && *status) || collection == NULL)
Branch: 3 branches
BranchTrueFalseTotal
if((status && *status) || collection == NULL) 0 0 0
if((status && *status) || collection == NULL) 0 0 0
if((status && *status) || collection == NULL) 0 0 0
918 0 return NULL;
919 }
920
921 0 ▶ if(scope_node == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(scope_node == NULL) 0 0 0
922 0 scope_node = tree->node_html;
923
924 0 mystatus_t rec_status = myhtml_get_nodes_by_attribute_key_recursion(scope_node, collection, key, key_len);
925
926 0 ▶ if(rec_status && status)
Branch: 2 branches
BranchTrueFalseTotal
if(rec_status && status) 0 0 0
if(rec_status && status) 0 0 0
927 0 *status = rec_status;
928
929 0 return collection;
930 }
931  
932 /* find by attribute value; case-sensitivity */
933 0 bool myhtml_get_nodes_by_attribute_value_recursion_eq(mycore_string_t* str, const char* value, size_t value_len)
934 {
935 0 ▶ return str->length == value_len && mycore_strncmp(str->data, value, value_len) == 0;
Branch: 2 branches
BranchTrueFalseTotal
return str->length == value_len && mycore_strncmp(str->data, value, value_len) == 0; 0 0 0
return str->length == value_len && mycore_strncmp(str->data, value, value_len) == 0; 0 0 0
936 }
937  
938 0 bool myhtml_get_nodes_by_attribute_value_recursion_whitespace_separated(mycore_string_t* str, const char* value, size_t value_len)
939 {
940 0 ▶ if(str->length < value_len)
Branch: 1 branch
BranchTrueFalseTotal
if(str->length < value_len) 0 0 0
941 0 return false;
942
943 0 const char *data = str->data;
944
945 0 ▶ if(mycore_strncmp(data, value, value_len) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(mycore_strncmp(data, value, value_len) == 0) { 0 0 0
946 0 ▶ if((str->length > value_len && mycore_utils_whithspace(data[value_len], ==, ||)) || str->length == value_len)
Branch: 7 branches
BranchTrueFalseTotal
if((str->length > value_len && mycore_utils_whithspace(data[value_len], ==, ||)) || str->length == value_len) 0 0 0
if((str->length > value_len && mycore_utils_whithspace(data[value_len], ==, ||)) || str->length == value_len) 0 0 0
if((str->length > value_len && mycore_utils_whithspace(data[value_len], ==, ||)) || str->length == value_len) 0 0 0
if((str->length > value_len && mycore_utils_whithspace(data[value_len], ==, ||)) || str->length == value_len) 0 0 0
if((str->length > value_len && mycore_utils_whithspace(data[value_len], ==, ||)) || str->length == value_len) 0 0 0
if((str->length > value_len && mycore_utils_whithspace(data[value_len], ==, ||)) || str->length == value_len) 0 0 0
if((str->length > value_len && mycore_utils_whithspace(data[value_len], ==, ||)) || str->length == value_len) 0 0 0
947 0 return true;
948 }
949
950 0 ▶ for(size_t i = 1; (str->length - i) >= value_len; i++)
Branch: 1 branch
BranchTrueFalseTotal
for(size_t i = 1; (str->length - i) >= value_len; i++) 0 0 0
951 {
952 0 ▶ if(mycore_utils_whithspace(data[(i - 1)], ==, ||)) {
Branch: 5 branches
BranchTrueFalseTotal
if(mycore_utils_whithspace(data[(i - 1)], ==, ||)) { 0 0 0
if(mycore_utils_whithspace(data[(i - 1)], ==, ||)) { 0 0 0
if(mycore_utils_whithspace(data[(i - 1)], ==, ||)) { 0 0 0
if(mycore_utils_whithspace(data[(i - 1)], ==, ||)) { 0 0 0
if(mycore_utils_whithspace(data[(i - 1)], ==, ||)) { 0 0 0
953 0 ▶ if(mycore_strncmp(&data[i], value, value_len) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(mycore_strncmp(&data[i], value, value_len) == 0) { 0 0 0
954 0 ▶ if((i > value_len && mycore_utils_whithspace(data[(i + value_len)], ==, ||)) || (str->length - i) == value_len)
Branch: 7 branches
BranchTrueFalseTotal
if((i > value_len && mycore_utils_whithspace(data[(i + value_len)], ==, ||)) || (str->length - i) == value_len) 0 0 0
if((i > value_len && mycore_utils_whithspace(data[(i + value_len)], ==, ||)) || (str->length - i) == value_len) 0 0 0
if((i > value_len && mycore_utils_whithspace(data[(i + value_len)], ==, ||)) || (str->length - i) == value_len) 0 0 0
if((i > value_len && mycore_utils_whithspace(data[(i + value_len)], ==, ||)) || (str->length - i) == value_len) 0 0 0
if((i > value_len && mycore_utils_whithspace(data[(i + value_len)], ==, ||)) || (str->length - i) == value_len) 0 0 0
if((i > value_len && mycore_utils_whithspace(data[(i + value_len)], ==, ||)) || (str->length - i) == value_len) 0 0 0
if((i > value_len && mycore_utils_whithspace(data[(i + value_len)], ==, ||)) || (str->length - i) == value_len) 0 0 0
955 0 return true;
956 }
957 }
958 }
959
960 0 return false;
961 }
962  
963 0 bool myhtml_get_nodes_by_attribute_value_recursion_begin(mycore_string_t* str, const char* value, size_t value_len)
964 {
965 0 ▶ if(str->length < value_len)
Branch: 1 branch
BranchTrueFalseTotal
if(str->length < value_len) 0 0 0
966 0 return false;
967
968 0 return mycore_strncmp(str->data, value, value_len) == 0;
969 }
970  
971 0 bool myhtml_get_nodes_by_attribute_value_recursion_end(mycore_string_t* str, const char* value, size_t value_len)
972 {
973 0 ▶ if(str->length < value_len)
Branch: 1 branch
BranchTrueFalseTotal
if(str->length < value_len) 0 0 0
974 0 return false;
975
976 0 return mycore_strncmp(&str->data[ (str->length - value_len) ], value, value_len) == 0;
977 }
978  
979 0 bool myhtml_get_nodes_by_attribute_value_recursion_contain(mycore_string_t* str, const char* value, size_t value_len)
980 {
981 0 ▶ if(str->length < value_len)
Branch: 1 branch
BranchTrueFalseTotal
if(str->length < value_len) 0 0 0
982 0 return false;
983
984 0 const char *data = str->data;
985
986 0 ▶ for(size_t i = 0; (str->length - i) >= value_len; i++)
Branch: 1 branch
BranchTrueFalseTotal
for(size_t i = 0; (str->length - i) >= value_len; i++) 0 0 0
987 {
988 0 ▶ if(mycore_strncmp(&data[i], value, value_len) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(mycore_strncmp(&data[i], value, value_len) == 0) { 0 0 0
989 0 return true;
990 }
991 }
992
993 0 return false;
994 }
995  
996 0 bool myhtml_get_nodes_by_attribute_value_recursion_hyphen_separated(mycore_string_t* str, const char* value, size_t value_len)
997 {
998 0 const char *data = str->data;
999
1000 0 ▶ if(str->length < value_len)
Branch: 1 branch
BranchTrueFalseTotal
if(str->length < value_len) 0 0 0
1001 0 return false;
1002 0 ▶ else if(str->length == value_len && mycore_strncmp(data, value, value_len) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
else if(str->length == value_len && mycore_strncmp(data, value, value_len) == 0) { 0 0 0
else if(str->length == value_len && mycore_strncmp(data, value, value_len) == 0) { 0 0 0
1003 0 return true;
1004 }
1005 0 ▶ else if(mycore_strncmp(data, value, value_len) == 0 && data[value_len] == '-') {
Branch: 2 branches
BranchTrueFalseTotal
else if(mycore_strncmp(data, value, value_len) == 0 && data[value_len] == '-') { 0 0 0
else if(mycore_strncmp(data, value, value_len) == 0 && data[value_len] == '-') { 0 0 0
1006 0 return true;
1007 }
1008
1009 0 return false;
1010 }
1011  
1012 /* find by attribute value; case-insensitive */
1013 0 bool myhtml_get_nodes_by_attribute_value_recursion_eq_i(mycore_string_t* str, const char* value, size_t value_len)
1014 {
1015 0 ▶ return str->length == value_len && mycore_strncasecmp(str->data, value, value_len) == 0;
Branch: 2 branches
BranchTrueFalseTotal
return str->length == value_len && mycore_strncasecmp(str->data, value, value_len) == 0; 0 0 0
return str->length == value_len && mycore_strncasecmp(str->data, value, value_len) == 0; 0 0 0
1016 }
1017  
1018 0 bool myhtml_get_nodes_by_attribute_value_recursion_whitespace_separated_i(mycore_string_t* str, const char* value, size_t value_len)
1019 {
1020 0 ▶ if(str->length < value_len)
Branch: 1 branch
BranchTrueFalseTotal
if(str->length < value_len) 0 0 0
1021 0 return false;
1022
1023 0 const char *data = str->data;
1024
1025 0 ▶ if(mycore_strncasecmp(data, value, value_len) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(mycore_strncasecmp(data, value, value_len) == 0) { 0 0 0
1026 0 ▶ if((str->length > value_len && mycore_utils_whithspace(data[value_len], ==, ||)) || str->length == value_len)
Branch: 7 branches
BranchTrueFalseTotal
if((str->length > value_len && mycore_utils_whithspace(data[value_len], ==, ||)) || str->length == value_len) 0 0 0
if((str->length > value_len && mycore_utils_whithspace(data[value_len], ==, ||)) || str->length == value_len) 0 0 0
if((str->length > value_len && mycore_utils_whithspace(data[value_len], ==, ||)) || str->length == value_len) 0 0 0
if((str->length > value_len && mycore_utils_whithspace(data[value_len], ==, ||)) || str->length == value_len) 0 0 0
if((str->length > value_len && mycore_utils_whithspace(data[value_len], ==, ||)) || str->length == value_len) 0 0 0
if((str->length > value_len && mycore_utils_whithspace(data[value_len], ==, ||)) || str->length == value_len) 0 0 0
if((str->length > value_len && mycore_utils_whithspace(data[value_len], ==, ||)) || str->length == value_len) 0 0 0
1027 0 return true;
1028 }
1029
1030 0 ▶ for(size_t i = 1; (str->length - i) >= value_len; i++)
Branch: 1 branch
BranchTrueFalseTotal
for(size_t i = 1; (str->length - i) >= value_len; i++) 0 0 0
1031 {
1032 0 ▶ if(mycore_utils_whithspace(data[(i - 1)], ==, ||)) {
Branch: 5 branches
BranchTrueFalseTotal
if(mycore_utils_whithspace(data[(i - 1)], ==, ||)) { 0 0 0
if(mycore_utils_whithspace(data[(i - 1)], ==, ||)) { 0 0 0
if(mycore_utils_whithspace(data[(i - 1)], ==, ||)) { 0 0 0
if(mycore_utils_whithspace(data[(i - 1)], ==, ||)) { 0 0 0
if(mycore_utils_whithspace(data[(i - 1)], ==, ||)) { 0 0 0
1033 0 ▶ if(mycore_strncasecmp(&data[i], value, value_len) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(mycore_strncasecmp(&data[i], value, value_len) == 0) { 0 0 0
1034 0 ▶ if((i > value_len && mycore_utils_whithspace(data[(i + value_len)], ==, ||)) || (str->length - i) == value_len)
Branch: 7 branches
BranchTrueFalseTotal
if((i > value_len && mycore_utils_whithspace(data[(i + value_len)], ==, ||)) || (str->length - i) == value_len) 0 0 0
if((i > value_len && mycore_utils_whithspace(data[(i + value_len)], ==, ||)) || (str->length - i) == value_len) 0 0 0
if((i > value_len && mycore_utils_whithspace(data[(i + value_len)], ==, ||)) || (str->length - i) == value_len) 0 0 0
if((i > value_len && mycore_utils_whithspace(data[(i + value_len)], ==, ||)) || (str->length - i) == value_len) 0 0 0
if((i > value_len && mycore_utils_whithspace(data[(i + value_len)], ==, ||)) || (str->length - i) == value_len) 0 0 0
if((i > value_len && mycore_utils_whithspace(data[(i + value_len)], ==, ||)) || (str->length - i) == value_len) 0 0 0
if((i > value_len && mycore_utils_whithspace(data[(i + value_len)], ==, ||)) || (str->length - i) == value_len) 0 0 0
1035 0 return true;
1036 }
1037 }
1038 }
1039
1040 0 return false;
1041 }
1042  
1043 0 bool myhtml_get_nodes_by_attribute_value_recursion_begin_i(mycore_string_t* str, const char* value, size_t value_len)
1044 {
1045 0 ▶ if(str->length < value_len)
Branch: 1 branch
BranchTrueFalseTotal
if(str->length < value_len) 0 0 0
1046 0 return false;
1047
1048 0 return mycore_strncasecmp(str->data, value, value_len) == 0;
1049 }
1050  
1051 0 bool myhtml_get_nodes_by_attribute_value_recursion_end_i(mycore_string_t* str, const char* value, size_t value_len)
1052 {
1053 0 ▶ if(str->length < value_len)
Branch: 1 branch
BranchTrueFalseTotal
if(str->length < value_len) 0 0 0
1054 0 return false;
1055
1056 0 return mycore_strncasecmp(&str->data[ (str->length - value_len) ], value, value_len) == 0;
1057 }
1058  
1059 0 bool myhtml_get_nodes_by_attribute_value_recursion_contain_i(mycore_string_t* str, const char* value, size_t value_len)
1060 {
1061 0 ▶ if(str->length < value_len)
Branch: 1 branch
BranchTrueFalseTotal
if(str->length < value_len) 0 0 0
1062 0 return false;
1063
1064 0 const char *data = str->data;
1065
1066 0 ▶ for(size_t i = 0; (str->length - i) >= value_len; i++)
Branch: 1 branch
BranchTrueFalseTotal
for(size_t i = 0; (str->length - i) >= value_len; i++) 0 0 0
1067 {
1068 0 ▶ if(mycore_strncasecmp(&data[i], value, value_len) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(mycore_strncasecmp(&data[i], value, value_len) == 0) { 0 0 0
1069 0 return true;
1070 }
1071 }
1072
1073 0 return false;
1074 }
1075  
1076 0 bool myhtml_get_nodes_by_attribute_value_recursion_hyphen_separated_i(mycore_string_t* str, const char* value, size_t value_len)
1077 {
1078 0 const char *data = str->data;
1079
1080 0 ▶ if(str->length < value_len)
Branch: 1 branch
BranchTrueFalseTotal
if(str->length < value_len) 0 0 0
1081 0 return false;
1082 0 ▶ else if(str->length == value_len && mycore_strncasecmp(data, value, value_len) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
else if(str->length == value_len && mycore_strncasecmp(data, value, value_len) == 0) { 0 0 0
else if(str->length == value_len && mycore_strncasecmp(data, value, value_len) == 0) { 0 0 0
1083 0 return true;
1084 }
1085 0 ▶ else if(mycore_strncasecmp(data, value, value_len) == 0 && data[value_len] == '-') {
Branch: 2 branches
BranchTrueFalseTotal
else if(mycore_strncasecmp(data, value, value_len) == 0 && data[value_len] == '-') { 0 0 0
else if(mycore_strncasecmp(data, value, value_len) == 0 && data[value_len] == '-') { 0 0 0
1086 0 return true;
1087 }
1088
1089 0 return false;
1090 }
1091  
1092 /* find by attribute value; basic functions */
1093 0 mystatus_t myhtml_get_nodes_by_attribute_value_recursion(myhtml_tree_node_t* node, myhtml_collection_t* collection,
1094 myhtml_attribute_value_find_f func_eq,
1095 const char* value, size_t value_len)
1096 {
1097 0 ▶ while(node)
Branch: 1 branch
BranchTrueFalseTotal
while(node) 0 0 0
1098 {
1099 0 ▶ if(node->token && node->token->attr_first) {
Branch: 2 branches
BranchTrueFalseTotal
if(node->token && node->token->attr_first) { 0 0 0
if(node->token && node->token->attr_first) { 0 0 0
1100 0 myhtml_tree_attr_t* attr = node->token->attr_first;
1101
1102 0 ▶ while(attr) {
Branch: 1 branch
BranchTrueFalseTotal
while(attr) { 0 0 0
1103 0 mycore_string_t* str = &attr->value;
1104
1105 0 ▶ if(func_eq(str, value, value_len)) {
Branch: 1 branch
BranchTrueFalseTotal
if(func_eq(str, value, value_len)) { 0 0 0
1106 0 collection->list[ collection->length ] = node;
1107
1108 0 collection->length++;
1109 0 ▶ if(collection->length >= collection->size) {
Branch: 1 branch
BranchTrueFalseTotal
if(collection->length >= collection->size) { 0 0 0
1110 0 mystatus_t status = myhtml_collection_check_size(collection, 1024, 0);
1111
1112 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
1113 0 return status;
1114 }
1115 }
1116
1117 0 attr = attr->next;
1118 }
1119 }
1120
1121 0 ▶ if(node->child) {
Branch: 1 branch
BranchTrueFalseTotal
if(node->child) { 0 0 0
1122 0 mystatus_t status = myhtml_get_nodes_by_attribute_value_recursion(node->child, collection, func_eq, value, value_len);
1123
1124 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
1125 0 return status;
1126 }
1127
1128 0 node = node->next;
1129 }
1130
1131 0 return MyHTML_STATUS_OK;
1132 }
1133  
1134 0 mystatus_t myhtml_get_nodes_by_attribute_value_recursion_by_key(myhtml_tree_node_t* node, myhtml_collection_t* collection,
1135 myhtml_attribute_value_find_f func_eq,
1136 const char* key, size_t key_len,
1137 const char* value, size_t value_len)
1138 {
1139 0 ▶ while(node)
Branch: 1 branch
BranchTrueFalseTotal
while(node) 0 0 0
1140 {
1141 0 ▶ if(node->token && node->token->attr_first) {
Branch: 2 branches
BranchTrueFalseTotal
if(node->token && node->token->attr_first) { 0 0 0
if(node->token && node->token->attr_first) { 0 0 0
1142 0 myhtml_tree_attr_t* attr = node->token->attr_first;
1143
1144 0 ▶ while(attr) {
Branch: 1 branch
BranchTrueFalseTotal
while(attr) { 0 0 0
1145 0 mycore_string_t* str_key = &attr->key;
1146 0 mycore_string_t* str = &attr->value;
1147
1148 0 ▶ if(str_key->length == key_len && mycore_strncasecmp(str_key->data, key, key_len) == 0)
Branch: 2 branches
BranchTrueFalseTotal
if(str_key->length == key_len && mycore_strncasecmp(str_key->data, key, key_len) == 0) 0 0 0
if(str_key->length == key_len && mycore_strncasecmp(str_key->data, key, key_len) == 0) 0 0 0
1149 {
1150 0 ▶ if(func_eq(str, value, value_len)) {
Branch: 1 branch
BranchTrueFalseTotal
if(func_eq(str, value, value_len)) { 0 0 0
1151 0 collection->list[ collection->length ] = node;
1152
1153 0 collection->length++;
1154 0 ▶ if(collection->length >= collection->size) {
Branch: 1 branch
BranchTrueFalseTotal
if(collection->length >= collection->size) { 0 0 0
1155 0 mystatus_t status = myhtml_collection_check_size(collection, 1024, 0);
1156
1157 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
1158 0 return status;
1159 }
1160 }
1161 }
1162
1163 0 attr = attr->next;
1164 }
1165 }
1166
1167 0 ▶ if(node->child) {
Branch: 1 branch
BranchTrueFalseTotal
if(node->child) { 0 0 0
1168 0 mystatus_t status = myhtml_get_nodes_by_attribute_value_recursion_by_key(node->child, collection, func_eq,
1169 key, key_len, value, value_len);
1170
1171 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
1172 0 return status;
1173 }
1174
1175 0 node = node->next;
1176 }
1177
1178 0 return MyHTML_STATUS_OK;
1179 }
1180  
1181 0 myhtml_collection_t * _myhtml_get_nodes_by_attribute_value(myhtml_tree_t *tree, myhtml_collection_t* collection, myhtml_tree_node_t* node,
1182 myhtml_attribute_value_find_f func_eq,
1183 const char* key, size_t key_len,
1184 const char* value, size_t value_len,
1185 mystatus_t* status)
1186 {
1187 0 ▶ if(collection == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(collection == NULL) { 0 0 0
1188 0 collection = myhtml_collection_create(1024, status);
1189
1190 0 ▶ if((status && *status) || collection == NULL)
Branch: 3 branches
BranchTrueFalseTotal
if((status && *status) || collection == NULL) 0 0 0
if((status && *status) || collection == NULL) 0 0 0
if((status && *status) || collection == NULL) 0 0 0
1191 0 return NULL;
1192 }
1193
1194 0 ▶ if(node == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(node == NULL) 0 0 0
1195 0 node = tree->node_html;
1196
1197 mystatus_t rec_status;
1198
1199 0 ▶ if(key && key_len)
Branch: 2 branches
BranchTrueFalseTotal
if(key && key_len) 0 0 0
if(key && key_len) 0 0 0
1200 0 rec_status = myhtml_get_nodes_by_attribute_value_recursion_by_key(node, collection, func_eq, key, key_len, value, value_len);
1201 else
1202 0 rec_status = myhtml_get_nodes_by_attribute_value_recursion(node, collection, func_eq, value, value_len);
1203
1204 0 ▶ if(rec_status && status)
Branch: 2 branches
BranchTrueFalseTotal
if(rec_status && status) 0 0 0
if(rec_status && status) 0 0 0
1205 0 *status = rec_status;
1206
1207 0 return collection;
1208 }
1209  
1210 0 myhtml_collection_t * myhtml_get_nodes_by_attribute_value(myhtml_tree_t *tree, myhtml_collection_t* collection, myhtml_tree_node_t* node,
1211 bool case_insensitive,
1212 const char* key, size_t key_len,
1213 const char* value, size_t value_len,
1214 mystatus_t* status)
1215 {
1216 0 ▶ if(case_insensitive) {
Branch: 1 branch
BranchTrueFalseTotal
if(case_insensitive) { 0 0 0
1217 0 return _myhtml_get_nodes_by_attribute_value(tree, collection, node,
1218 myhtml_get_nodes_by_attribute_value_recursion_eq_i,
1219 key, key_len, value, value_len, status);
1220 }
1221
1222 0 return _myhtml_get_nodes_by_attribute_value(tree, collection, node,
1223 myhtml_get_nodes_by_attribute_value_recursion_eq,
1224 key, key_len, value, value_len, status);
1225 }
1226  
1227 0 myhtml_collection_t * myhtml_get_nodes_by_attribute_value_whitespace_separated(myhtml_tree_t *tree, myhtml_collection_t* collection, myhtml_tree_node_t* node,
1228 bool case_insensitive,
1229 const char* key, size_t key_len,
1230 const char* value, size_t value_len,
1231 mystatus_t* status)
1232 {
1233 0 ▶ if(case_insensitive) {
Branch: 1 branch
BranchTrueFalseTotal
if(case_insensitive) { 0 0 0
1234 0 return _myhtml_get_nodes_by_attribute_value(tree, collection, node,
1235 myhtml_get_nodes_by_attribute_value_recursion_whitespace_separated_i,
1236 key, key_len, value, value_len, status);
1237 }
1238
1239 0 return _myhtml_get_nodes_by_attribute_value(tree, collection, node,
1240 myhtml_get_nodes_by_attribute_value_recursion_whitespace_separated,
1241 key, key_len, value, value_len, status);
1242 }
1243  
1244 0 myhtml_collection_t * myhtml_get_nodes_by_attribute_value_begin(myhtml_tree_t *tree, myhtml_collection_t* collection, myhtml_tree_node_t* node,
1245 bool case_insensitive,
1246 const char* key, size_t key_len,
1247 const char* value, size_t value_len,
1248 mystatus_t* status)
1249 {
1250 0 ▶ if(case_insensitive) {
Branch: 1 branch
BranchTrueFalseTotal
if(case_insensitive) { 0 0 0
1251 0 return _myhtml_get_nodes_by_attribute_value(tree, collection, node,
1252 myhtml_get_nodes_by_attribute_value_recursion_begin_i,
1253 key, key_len, value, value_len, status);
1254 }
1255
1256 0 return _myhtml_get_nodes_by_attribute_value(tree, collection, node,
1257 myhtml_get_nodes_by_attribute_value_recursion_begin,
1258 key, key_len, value, value_len, status);
1259 }
1260  
1261 0 myhtml_collection_t * myhtml_get_nodes_by_attribute_value_end(myhtml_tree_t *tree, myhtml_collection_t* collection, myhtml_tree_node_t* node,
1262 bool case_insensitive,
1263 const char* key, size_t key_len,
1264 const char* value, size_t value_len,
1265 mystatus_t* status)
1266 {
1267 0 ▶ if(case_insensitive) {
Branch: 1 branch
BranchTrueFalseTotal
if(case_insensitive) { 0 0 0
1268 0 return _myhtml_get_nodes_by_attribute_value(tree, collection, node,
1269 myhtml_get_nodes_by_attribute_value_recursion_end_i,
1270 key, key_len, value, value_len, status);
1271 }
1272
1273 0 return _myhtml_get_nodes_by_attribute_value(tree, collection, node,
1274 myhtml_get_nodes_by_attribute_value_recursion_end,
1275 key, key_len, value, value_len, status);
1276 }
1277  
1278 0 myhtml_collection_t * myhtml_get_nodes_by_attribute_value_contain(myhtml_tree_t *tree, myhtml_collection_t* collection, myhtml_tree_node_t* node,
1279 bool case_insensitive,
1280 const char* key, size_t key_len,
1281 const char* value, size_t value_len,
1282 mystatus_t* status)
1283 {
1284 0 ▶ if(case_insensitive) {
Branch: 1 branch
BranchTrueFalseTotal
if(case_insensitive) { 0 0 0
1285 0 return _myhtml_get_nodes_by_attribute_value(tree, collection, node,
1286 myhtml_get_nodes_by_attribute_value_recursion_contain_i,
1287 key, key_len, value, value_len, status);
1288 }
1289
1290 0 return _myhtml_get_nodes_by_attribute_value(tree, collection, node,
1291 myhtml_get_nodes_by_attribute_value_recursion_contain,
1292 key, key_len, value, value_len, status);
1293 }
1294  
1295 0 myhtml_collection_t * myhtml_get_nodes_by_attribute_value_hyphen_separated(myhtml_tree_t *tree, myhtml_collection_t* collection, myhtml_tree_node_t* node,
1296 bool case_insensitive,
1297 const char* key, size_t key_len,
1298 const char* value, size_t value_len,
1299 mystatus_t* status)
1300 {
1301 0 ▶ if(case_insensitive) {
Branch: 1 branch
BranchTrueFalseTotal
if(case_insensitive) { 0 0 0
1302 0 return _myhtml_get_nodes_by_attribute_value(tree, collection, node,
1303 myhtml_get_nodes_by_attribute_value_recursion_hyphen_separated_i,
1304 key, key_len, value, value_len, status);
1305 }
1306
1307 0 return _myhtml_get_nodes_by_attribute_value(tree, collection, node,
1308 myhtml_get_nodes_by_attribute_value_recursion_hyphen_separated,
1309 key, key_len, value, value_len, status);
1310 }
1311  
1312 /*
1313 * Attributes
1314 */
1315 0 myhtml_tree_attr_t * myhtml_attribute_next(myhtml_tree_attr_t *attr)
1316 {
1317 0 return attr->next;
1318 }
1319  
1320 0 myhtml_tree_attr_t * myhtml_attribute_prev(myhtml_tree_attr_t *attr)
1321 {
1322 0 return attr->prev;
1323 }
1324  
1325 0 enum myhtml_namespace myhtml_attribute_namespace(myhtml_tree_attr_t *attr)
1326 {
1327 0 return attr->ns;
1328 }
1329  
1330 0 void myhtml_attribute_namespace_set(myhtml_tree_attr_t *attr, myhtml_namespace_t ns)
1331 {
1332 0 attr->ns = ns;
1333 0 }
1334  
1335 0 const char * myhtml_attribute_key(myhtml_tree_attr_t *attr, size_t *length)
1336 {
1337 0 ▶ if(attr->key.data && attr->key.length)
Branch: 2 branches
BranchTrueFalseTotal
if(attr->key.data && attr->key.length) 0 0 0
if(attr->key.data && attr->key.length) 0 0 0
1338 {
1339 0 ▶ if(length)
Branch: 1 branch
BranchTrueFalseTotal
if(length) 0 0 0
1340 0 *length = attr->key.length;
1341
1342 0 return attr->key.data;
1343 }
1344
1345 0 ▶ if(length)
Branch: 1 branch
BranchTrueFalseTotal
if(length) 0 0 0
1346 0 *length = 0;
1347
1348 0 return NULL;
1349 }
1350  
1351 0 const char * myhtml_attribute_value(myhtml_tree_attr_t *attr, size_t *length)
1352 {
1353 0 ▶ if(attr->value.data && attr->value.length)
Branch: 2 branches
BranchTrueFalseTotal
if(attr->value.data && attr->value.length) 0 0 0
if(attr->value.data && attr->value.length) 0 0 0
1354 {
1355 0 ▶ if(length)
Branch: 1 branch
BranchTrueFalseTotal
if(length) 0 0 0
1356 0 *length = attr->value.length;
1357
1358 0 return attr->value.data;
1359 }
1360
1361 0 ▶ if(length)
Branch: 1 branch
BranchTrueFalseTotal
if(length) 0 0 0
1362 0 *length = 0;
1363
1364 0 return NULL;
1365 }
1366  
1367 0 mycore_string_t * myhtml_attribute_key_string(myhtml_tree_attr_t* attr)
1368 {
1369 0 ▶ if(attr)
Branch: 1 branch
BranchTrueFalseTotal
if(attr) 0 0 0
1370 0 return &attr->key;
1371
1372 0 return NULL;
1373 }
1374  
1375 0 mycore_string_t * myhtml_attribute_value_string(myhtml_tree_attr_t* attr)
1376 {
1377 0 ▶ if(attr)
Branch: 1 branch
BranchTrueFalseTotal
if(attr) 0 0 0
1378 0 return &attr->value;
1379
1380 0 return NULL;
1381 }
1382  
1383 0 myhtml_tree_attr_t * myhtml_attribute_by_key(myhtml_tree_node_t *node, const char *key, size_t key_len)
1384 {
1385 0 ▶ if(node == NULL || node->token == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if(node == NULL || node->token == NULL) 0 0 0
if(node == NULL || node->token == NULL) 0 0 0
1386 0 return NULL;
1387
1388 0 return myhtml_token_attr_by_name(node->token, key, key_len);
1389 }
1390  
1391 0 myhtml_tree_attr_t * myhtml_attribute_add(myhtml_tree_node_t *node, const char *key, size_t key_len, const char *value, size_t value_len, myencoding_t encoding)
1392 {
1393 0 ▶ if(node == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(node == NULL) 0 0 0
1394 0 return NULL;
1395
1396 0 myhtml_tree_t *tree = node->tree;
1397
1398 0 ▶ if(node->token == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(node->token == NULL) { 0 0 0
1399 0 node->token = myhtml_token_node_create(tree->token, tree->mcasync_rules_token_id);
1400
1401 0 ▶ if(node->token == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(node->token == NULL) 0 0 0
1402 0 return NULL;
1403
1404 0 node->token->type |= MyHTML_TOKEN_TYPE_DONE;
1405 }
1406
1407 0 return myhtml_token_node_attr_append_with_convert_encoding(tree->token, node->token, key, key_len,
1408 value, value_len, tree->mcasync_rules_token_id, encoding);
1409 }
1410  
1411 0 myhtml_tree_attr_t * myhtml_attribute_remove(myhtml_tree_node_t *node, myhtml_tree_attr_t *attr)
1412 {
1413 0 ▶ if(node == NULL || node->token == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if(node == NULL || node->token == NULL) 0 0 0
if(node == NULL || node->token == NULL) 0 0 0
1414 0 return NULL;
1415
1416 0 return myhtml_token_attr_remove(node->token, attr);
1417 }
1418  
1419 0 myhtml_tree_attr_t * myhtml_attribute_remove_by_key(myhtml_tree_node_t *node, const char *key, size_t key_len)
1420 {
1421 0 ▶ if(node == NULL || node->token == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if(node == NULL || node->token == NULL) 0 0 0
if(node == NULL || node->token == NULL) 0 0 0
1422 0 return NULL;
1423
1424 0 return myhtml_token_attr_remove_by_name(node->token, key, key_len);
1425 }
1426  
1427 0 void myhtml_attribute_delete(myhtml_tree_t *tree, myhtml_tree_node_t *node, myhtml_tree_attr_t *attr)
1428 {
1429 0 ▶ if(node == NULL || node->token == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if(node == NULL || node->token == NULL) 0 0 0
if(node == NULL || node->token == NULL) 0 0 0
1430 0 return;
1431
1432 0 myhtml_token_attr_remove(node->token, attr);
1433 0 myhtml_attribute_free(tree, attr);
1434 }
1435  
1436 0 void myhtml_attribute_free(myhtml_tree_t *tree, myhtml_tree_attr_t *attr)
1437 {
1438 0 ▶ if(attr->key.data)
Branch: 1 branch
BranchTrueFalseTotal
if(attr->key.data) 0 0 0
1439 0 mchar_async_free(attr->key.mchar, attr->key.node_idx, attr->key.data);
1440 0 ▶ if(attr->value.data)
Branch: 1 branch
BranchTrueFalseTotal
if(attr->value.data) 0 0 0
1441 0 mchar_async_free(attr->value.mchar, attr->value.node_idx, attr->value.data);
1442
1443 0 mcobject_async_free(tree->token->attr_obj, attr);
1444 0 }
1445  
1446 0 myhtml_position_t myhtml_attribute_key_raw_position(myhtml_tree_attr_t *attr)
1447 {
1448 0 ▶ if(attr)
Branch: 1 branch
BranchTrueFalseTotal
if(attr) 0 0 0
1449 0 return (myhtml_position_t){attr->raw_key_begin, attr->raw_key_length};
1450
1451 0 return (myhtml_position_t){0, 0};
1452 }
1453  
1454 0 myhtml_position_t myhtml_attribute_value_raw_position(myhtml_tree_attr_t *attr)
1455 {
1456 0 ▶ if(attr)
Branch: 1 branch
BranchTrueFalseTotal
if(attr) 0 0 0
1457 0 return (myhtml_position_t){attr->raw_value_begin, attr->raw_value_length};
1458
1459 0 return (myhtml_position_t){0, 0};
1460 }
1461  
1462 /*
1463 * Collections
1464 */
1465 0 myhtml_collection_t * myhtml_collection_create(size_t size, mystatus_t *status)
1466 {
1467 0 myhtml_collection_t *collection = (myhtml_collection_t*)mycore_malloc(sizeof(myhtml_collection_t));
1468
1469 0 ▶ if(collection == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(collection == NULL) { 0 0 0
1470 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
1471 0 *status = MyHTML_STATUS_ERROR_MEMORY_ALLOCATION;
1472
1473 0 return NULL;
1474 }
1475
1476 0 collection->size = size;
1477 0 collection->length = 0;
1478 0 collection->list = (myhtml_tree_node_t **)mycore_malloc(sizeof(myhtml_tree_node_t*) * size);
1479
1480 0 ▶ if(collection->list == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(collection->list == NULL) { 0 0 0
1481 0 mycore_free(collection);
1482
1483 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
1484 0 *status = MyHTML_STATUS_ERROR_MEMORY_ALLOCATION;
1485
1486 0 return NULL;
1487 }
1488
1489 0 ▶ if(status)
Branch: 1 branch
BranchTrueFalseTotal
if(status) 0 0 0
1490 0 *status = MyHTML_STATUS_OK;
1491
1492 0 return collection;
1493 }
1494  
1495 0 mystatus_t myhtml_collection_check_size(myhtml_collection_t *collection, size_t need, size_t upto_length)
1496 {
1497 0 ▶ if((collection->length + need) >= collection->size)
Branch: 1 branch
BranchTrueFalseTotal
if((collection->length + need) >= collection->size) 0 0 0
1498 {
1499 0 size_t tmp_size = collection->length + need + upto_length + 1;
1500 0 myhtml_tree_node_t **tmp = (myhtml_tree_node_t **)mycore_realloc(collection->list, sizeof(myhtml_tree_node_t*) * tmp_size);
1501
1502 0 ▶ if(tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if(tmp) { 0 0 0
1503 0 collection->size = tmp_size;
1504 0 collection->list = tmp;
1505 }
1506 else
1507 0 return MyHTML_STATUS_ERROR_MEMORY_ALLOCATION;
1508 }
1509
1510 0 return MyHTML_STATUS_OK;
1511 }
1512  
1513 0 void myhtml_collection_clean(myhtml_collection_t *collection)
1514 {
1515 0 ▶ if(collection)
Branch: 1 branch
BranchTrueFalseTotal
if(collection) 0 0 0
1516 0 collection->length = 0;
1517 0 }
1518  
1519 0 myhtml_collection_t * myhtml_collection_destroy(myhtml_collection_t *collection)
1520 {
1521 0 ▶ if(collection == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(collection == NULL) 0 0 0
1522 0 return NULL;
1523
1524 0 ▶ if(collection->list)
Branch: 1 branch
BranchTrueFalseTotal
if(collection->list) 0 0 0
1525 0 mycore_free(collection->list);
1526
1527 0 mycore_free(collection);
1528
1529 0 return NULL;
1530 }
1531  
1532 /* queue */
1533 0 mystatus_t myhtml_queue_add(myhtml_tree_t *tree, size_t begin, myhtml_token_node_t* token)
1534 {
1535 // TODO: need refactoring this code
1536 // too many conditions
1537 0 mythread_queue_node_t *qnode = tree->current_qnode;
1538
1539 0 ▶ if(tree->parse_flags & MyHTML_TREE_PARSE_FLAGS_SKIP_WHITESPACE_TOKEN) {
Branch: 1 branch
BranchTrueFalseTotal
if(tree->parse_flags & MyHTML_TREE_PARSE_FLAGS_SKIP_WHITESPACE_TOKEN) { 0 0 0
1540 0 ▶ if(token && token->tag_id == MyHTML_TAG__TEXT && token->type & MyHTML_TOKEN_TYPE_WHITESPACE)
Branch: 3 branches
BranchTrueFalseTotal
if(token && token->tag_id == MyHTML_TAG__TEXT && token->type & MyHTML_TOKEN_TYPE_WHITESPACE) 0 0 0
if(token && token->tag_id == MyHTML_TAG__TEXT && token->type & MyHTML_TOKEN_TYPE_WHITESPACE) 0 0 0
if(token && token->tag_id == MyHTML_TAG__TEXT && token->type & MyHTML_TOKEN_TYPE_WHITESPACE) 0 0 0
1541 {
1542 0 myhtml_token_node_clean(token);
1543 0 token->raw_begin = token->element_begin = (tree->global_offset + begin);
1544
1545 0 return MyHTML_STATUS_OK;
1546 }
1547 }
1548
1549 #ifndef MyCORE_BUILD_WITHOUT_THREADS
1550
1551 0 ▶ if(tree->flags & MyHTML_TREE_FLAGS_SINGLE_MODE) {
Branch: 1 branch
BranchTrueFalseTotal
if(tree->flags & MyHTML_TREE_FLAGS_SINGLE_MODE) { 0 0 0
1552 0 ▶ if(qnode && token) {
Branch: 2 branches
BranchTrueFalseTotal
if(qnode && token) { 0 0 0
if(qnode && token) { 0 0 0
1553 0 qnode->args = token;
1554
1555 0 myhtml_parser_worker(0, qnode);
1556 0 myhtml_parser_stream(0, qnode);
1557 }
1558
1559 0 tree->current_qnode = mythread_queue_node_malloc_limit(tree->myhtml->thread_stream, tree->queue, 4, NULL);
1560 }
1561 else {
1562 0 ▶ if(qnode)
Branch: 1 branch
BranchTrueFalseTotal
if(qnode) 0 0 0
1563 0 qnode->args = token;
1564
1565 0 tree->current_qnode = mythread_queue_node_malloc_round(tree->myhtml->thread_stream, tree->queue_entry);
1566
1567 /* we have a clean queue list */
1568 0 ▶ if(tree->queue_entry->queue->nodes_length == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(tree->queue_entry->queue->nodes_length == 0) { 0 0 0
1569 0 mythread_queue_list_entry_make_batch(tree->myhtml->thread_batch, tree->queue_entry);
1570 0 mythread_queue_list_entry_make_stream(tree->myhtml->thread_stream, tree->queue_entry);
1571 }
1572 }
1573
1574 #else
1575
1576 if(qnode && token) {
1577 qnode->args = token;
1578
1579 myhtml_parser_worker(0, qnode);
1580 myhtml_parser_stream(0, qnode);
1581 }
1582
1583 tree->current_qnode = mythread_queue_node_malloc_limit(tree->myhtml->thread_stream, tree->queue, 4, NULL);
1584
1585 #endif /* MyCORE_BUILD_WITHOUT_THREADS */
1586
1587 0 ▶ if(tree->current_qnode == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(tree->current_qnode == NULL) 0 0 0
1588 0 return MyHTML_STATUS_ERROR_MEMORY_ALLOCATION;
1589
1590 0 tree->current_qnode->context = tree;
1591 0 tree->current_qnode->prev = qnode;
1592
1593 0 ▶ if(qnode && token)
Branch: 2 branches
BranchTrueFalseTotal
if(qnode && token) 0 0 0
if(qnode && token) 0 0 0
1594 0 myhtml_tokenizer_calc_current_namespace(tree, token);
1595
1596 0 tree->current_token_node = myhtml_token_node_create(tree->token, tree->token->mcasync_token_id);
1597 0 ▶ if(tree->current_token_node == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(tree->current_token_node == NULL) 0 0 0
1598 0 return MyHTML_STATUS_ERROR_MEMORY_ALLOCATION;
1599
1600 0 tree->current_token_node->raw_begin = tree->current_token_node->element_begin = (tree->global_offset + begin);
1601
1602 0 return MyHTML_STATUS_OK;
1603 }
1604  
1605 0 bool myhtml_utils_strcmp(const char* ab, const char* to_lowercase, size_t size)
1606 {
1607 0 size_t i = 0;
1608
1609 for(;;) {
1610 0 ▶ if(i == size)
Branch: 1 branch
BranchTrueFalseTotal
if(i == size) 0 0 0
1611 0 return true;
1612
1613 0 ▶ if((const unsigned char)(to_lowercase[i] > 0x40 && to_lowercase[i] < 0x5b ?
Branch: 2 branches
BranchTrueFalseTotal
if((const unsigned char)(to_lowercase[i] > 0x40 && to_lowercase[i] < 0x5b ? 0 0 0
if((const unsigned char)(to_lowercase[i] > 0x40 && to_lowercase[i] < 0x5b ? 0 0 0
1614 0 ▶ (to_lowercase[i]|0x60) : to_lowercase[i]) != (const unsigned char)ab[i])
Branch: 1 branch
BranchTrueFalseTotal
(to_lowercase[i]|0x60) : to_lowercase[i]) != (const unsigned char)ab[i]) 0 0 0
1615 {
1616 0 return false;
1617 }
1618
1619 0 i++;
1620 }
1621
1622 return false;
1623 }
1624  
1625 0 bool myhtml_is_html_node(myhtml_tree_node_t *node, myhtml_tag_id_t tag_id)
1626 {
1627 0 ▶ if(node == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(node == NULL) 0 0 0
1628 0 return false;
1629
1630 0 ▶ return node->tag_id == tag_id && node->ns == MyHTML_NAMESPACE_HTML;
Branch: 2 branches
BranchTrueFalseTotal
return node->tag_id == tag_id && node->ns == MyHTML_NAMESPACE_HTML; 0 0 0
return node->tag_id == tag_id && node->ns == MyHTML_NAMESPACE_HTML; 0 0 0
1631 }
1632  
1633 /* version */
1634 0 myhtml_version_t myhtml_version(void)
1635 {
1636 0 return (myhtml_version_t){MyHTML_VERSION_MAJOR, MyHTML_VERSION_MINOR, MyHTML_VERSION_PATCH};
1637 }
1638  
1639  
1640  
1641  
« third_party/modest/source/myhtml/data_process.c ↑ Summary third_party/modest/source/myhtml/mynamespace.c »