| 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/myhtml.h" |
| 20 |
|
| |
| 21 |
1 |
| void myhtml_init_marker(myhtml_t* myhtml) |
| 22 |
|
| { |
| 23 |
1 |
| myhtml->marker = (myhtml_tree_node_t*)mymalloc(sizeof(myhtml_tree_node_t)); |
| 24 |
|
| |
| 25 |
1 |
▶ | if(myhtml->marker) |
Branch: 1 branch
| Branch | True | False | Total |
| if(myhtml->marker) |
1 |
0 |
1 |
|
| 26 |
1 |
| myhtml_tree_node_clean(myhtml->marker); |
| 27 |
1 |
| } |
| 28 |
|
| |
| 29 |
1 |
| void myhtml_destroy_marker(myhtml_t* myhtml) |
| 30 |
|
| { |
| 31 |
1 |
▶ | if(myhtml->marker) |
Branch: 1 branch
| Branch | True | False | Total |
| if(myhtml->marker) |
1 |
0 |
1 |
|
| 32 |
1 |
| free(myhtml->marker); |
| 33 |
1 |
| } |
| 34 |
|
| |
| 35 |
1 |
| myhtml_t * myhtml_create(void) |
| 36 |
|
| { |
| 37 |
1 |
| return (myhtml_t*)mymalloc(sizeof(myhtml_t)); |
| 38 |
|
| } |
| 39 |
|
| |
| 40 |
1 |
| myhtml_status_t myhtml_init(myhtml_t* myhtml, enum myhtml_options opt, size_t thread_count, size_t queue_size) |
| 41 |
|
| { |
| 42 |
|
| myhtml_status_t status; |
| 43 |
|
| |
| 44 |
1 |
| myhtml_init_marker(myhtml); |
| 45 |
|
| |
| 46 |
1 |
| myhtml->async_incoming_buf = mcobject_async_create(); |
| 47 |
1 |
▶ | if(myhtml->async_incoming_buf == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(myhtml->async_incoming_buf == NULL) |
0 |
1 |
1 |
|
| 48 |
0 |
| return MyHTML_STATUS_ERROR_MEMORY_ALLOCATION; |
| 49 |
|
| |
| 50 |
1 |
| mcobject_async_status_t mcstatus = mcobject_async_init(myhtml->async_incoming_buf, 32, 1024, sizeof(myhtml_incoming_buf_t)); |
| 51 |
1 |
▶ | if(mcstatus != MCOBJECT_ASYNC_STATUS_OK) |
Branch: 1 branch
| Branch | True | False | Total |
| if(mcstatus != MCOBJECT_ASYNC_STATUS_OK) |
0 |
1 |
1 |
|
| 52 |
0 |
| return MyHTML_STATUS_ERROR_MEMORY_ALLOCATION; |
| 53 |
|
| |
| 54 |
|
| // for tags node and other |
| 55 |
1 |
| myhtml->mchar = mchar_async_create(64, 4096); |
| 56 |
|
| |
| 57 |
1 |
| myhtml->tag_index = mcobject_async_create(); |
| 58 |
1 |
| mcstatus = mcobject_async_init(myhtml->tag_index, 128, 1024, sizeof(myhtml_tag_index_node_t)); |
| 59 |
|
| |
| 60 |
1 |
▶ | if(mcstatus != MCOBJECT_ASYNC_STATUS_OK) |
Branch: 1 branch
| Branch | True | False | Total |
| if(mcstatus != MCOBJECT_ASYNC_STATUS_OK) |
0 |
1 |
1 |
|
| 61 |
0 |
| return MyHTML_STATUS_TAGS_ERROR_MCOBJECT_CREATE; |
| 62 |
|
| |
| 63 |
1 |
| status = myhtml_tokenizer_state_init(myhtml); |
| 64 |
1 |
▶ | if(status) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(status) { |
0 |
1 |
1 |
|
| 65 |
0 |
| myhtml->insertion_func = NULL; |
| 66 |
0 |
| myhtml->thread = NULL; |
| 67 |
|
| |
| 68 |
0 |
| return status; |
| 69 |
|
| } |
| 70 |
|
| |
| 71 |
1 |
| status = myhtml_rules_init(myhtml); |
| 72 |
1 |
▶ | if(status) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(status) { |
0 |
1 |
1 |
|
| 73 |
0 |
| myhtml->thread = NULL; |
| 74 |
|
| |
| 75 |
0 |
| return status; |
| 76 |
|
| } |
| 77 |
|
| |
| 78 |
1 |
| myhtml->opt = opt; |
| 79 |
1 |
| myhtml->thread = mythread_create(); |
| 80 |
|
| |
| 81 |
|
| #ifdef MyHTML_BUILD_WITHOUT_THREADS |
| 82 |
|
| |
| 83 |
|
| status = mythread_init(myhtml->thread, NULL, thread_count, queue_size); |
| 84 |
|
| |
| 85 |
|
| if(status) |
| 86 |
|
| return status; |
| 87 |
|
| |
| 88 |
|
| #else /* MyHTML_BUILD_WITHOUT_THREADS */ |
| 89 |
1 |
| switch (opt) { |
| 90 |
0 |
| case MyHTML_OPTIONS_PARSE_MODE_SINGLE: |
| 91 |
0 |
| status = mythread_init(myhtml->thread, "lastmac", 0, queue_size); |
| 92 |
0 |
▶ | if(status) |
Branch: 1 branch
| Branch | True | False | Total |
| if(status) |
0 |
0 |
0 |
|
| 93 |
0 |
| return status; |
| 94 |
|
| |
| 95 |
0 |
| break; |
| 96 |
|
| |
| 97 |
0 |
| case MyHTML_OPTIONS_PARSE_MODE_ALL_IN_ONE: |
| 98 |
0 |
| status = mythread_init(myhtml->thread, "lastmac", 1, queue_size); |
| 99 |
0 |
▶ | if(status) |
Branch: 1 branch
| Branch | True | False | Total |
| if(status) |
0 |
0 |
0 |
|
| 100 |
0 |
| return status; |
| 101 |
|
| |
| 102 |
0 |
| myhread_create_stream(myhtml->thread, myhtml_parser_worker_index_stream, &status); |
| 103 |
0 |
| break; |
| 104 |
|
| |
| 105 |
0 |
| case MyHTML_OPTIONS_PARSE_MODE_WORKER_TREE: |
| 106 |
0 |
| status = mythread_init(myhtml->thread, "lastmac", 2, queue_size); |
| 107 |
0 |
▶ | if(status) |
Branch: 1 branch
| Branch | True | False | Total |
| if(status) |
0 |
0 |
0 |
|
| 108 |
0 |
| return status; |
| 109 |
|
| |
| 110 |
0 |
| myhread_create_stream(myhtml->thread, myhtml_parser_index, &status); |
| 111 |
0 |
| myhread_create_stream(myhtml->thread, myhtml_parser_worker_stream, &status); |
| 112 |
0 |
| break; |
| 113 |
|
| |
| 114 |
0 |
| case MyHTML_OPTIONS_PARSE_MODE_WORKER_INDEX: |
| 115 |
0 |
| status = mythread_init(myhtml->thread, "lastmac", 2, queue_size); |
| 116 |
0 |
▶ | if(status) |
Branch: 1 branch
| Branch | True | False | Total |
| if(status) |
0 |
0 |
0 |
|
| 117 |
0 |
| return status; |
| 118 |
|
| |
| 119 |
0 |
| myhread_create_stream(myhtml->thread, myhtml_parser_worker_index, &status); |
| 120 |
0 |
| myhread_create_stream(myhtml->thread, myhtml_parser_stream, &status); |
| 121 |
0 |
| break; |
| 122 |
|
| |
| 123 |
0 |
| case MyHTML_OPTIONS_PARSE_MODE_TREE_INDEX: |
| 124 |
0 |
▶ | if(thread_count == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if(thread_count == 0) |
0 |
0 |
0 |
|
| 125 |
0 |
| thread_count = 1; |
| 126 |
|
| |
| 127 |
0 |
| status = mythread_init(myhtml->thread, "lastmac", (thread_count + 1), queue_size); |
| 128 |
0 |
▶ | if(status) |
Branch: 1 branch
| Branch | True | False | Total |
| if(status) |
0 |
0 |
0 |
|
| 129 |
0 |
| return status; |
| 130 |
|
| |
| 131 |
0 |
| myhread_create_stream(myhtml->thread, myhtml_parser_stream_index, &status); |
| 132 |
0 |
| myhread_create_batch(myhtml->thread, myhtml_parser_worker, &status, thread_count); |
| 133 |
0 |
| break; |
| 134 |
|
| |
| 135 |
1 |
| default: |
| 136 |
|
| // default MyHTML_OPTIONS_PARSE_MODE_SEPARATELY |
| 137 |
1 |
▶ | if(thread_count == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if(thread_count == 0) |
0 |
1 |
1 |
|
| 138 |
0 |
| thread_count = 1; |
| 139 |
|
| |
| 140 |
1 |
| status = mythread_init(myhtml->thread, "lastmac", (thread_count + 2), queue_size); |
| 141 |
1 |
▶ | if(status) |
Branch: 1 branch
| Branch | True | False | Total |
| if(status) |
0 |
1 |
1 |
|
| 142 |
0 |
| return status; |
| 143 |
|
| |
| 144 |
1 |
| myhread_create_stream(myhtml->thread, myhtml_parser_index, &status); |
| 145 |
1 |
| myhread_create_stream(myhtml->thread, myhtml_parser_stream, &status); |
| 146 |
1 |
| myhread_create_batch(myhtml->thread, myhtml_parser_worker, &status, thread_count); |
| 147 |
1 |
| break; |
| 148 |
|
| } |
| 149 |
|
| |
| 150 |
|
| #endif /* MyHTML_BUILD_WITHOUT_THREADS */ |
| 151 |
|
| |
| 152 |
1 |
| myhtml_clean(myhtml); |
| 153 |
|
| |
| 154 |
1 |
| return status; |
| 155 |
|
| } |
| 156 |
|
| |
| 157 |
1 |
| void myhtml_clean(myhtml_t* myhtml) |
| 158 |
|
| { |
| 159 |
1 |
| mythread_clean(myhtml->thread); |
| 160 |
|
| |
| 161 |
1 |
| mcobject_async_node_all_clean(myhtml->async_incoming_buf); |
| 162 |
1 |
| } |
| 163 |
|
| |
| 164 |
1 |
| myhtml_t* myhtml_destroy(myhtml_t* myhtml) |
| 165 |
|
| { |
| 166 |
1 |
▶ | if(myhtml == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(myhtml == NULL) |
0 |
1 |
1 |
|
| 167 |
0 |
| return NULL; |
| 168 |
|
| |
| 169 |
1 |
| myhtml_destroy_marker(myhtml); |
| 170 |
|
| |
| 171 |
1 |
| mythread_destroy(myhtml->thread, true); |
| 172 |
1 |
| myhtml_tokenizer_state_destroy(myhtml); |
| 173 |
|
| |
| 174 |
1 |
| myhtml->async_incoming_buf = mcobject_async_destroy(myhtml->async_incoming_buf, true); |
| 175 |
1 |
| myhtml->tag_index = mcobject_async_destroy(myhtml->tag_index, true); |
| 176 |
1 |
| myhtml->mchar = mchar_async_destroy(myhtml->mchar, true); |
| 177 |
|
| |
| 178 |
1 |
▶ | if(myhtml->insertion_func) |
Branch: 1 branch
| Branch | True | False | Total |
| if(myhtml->insertion_func) |
1 |
0 |
1 |
|
| 179 |
1 |
| free(myhtml->insertion_func); |
| 180 |
|
| |
| 181 |
1 |
| free(myhtml); |
| 182 |
|
| |
| 183 |
1 |
| return NULL; |
| 184 |
|
| } |
| 185 |
|
| |
| 186 |
0 |
| myhtml_status_t myhtml_parse(myhtml_tree_t* tree, myhtml_encoding_t encoding, const char* html, size_t html_size) |
| 187 |
|
| { |
| 188 |
0 |
▶ | if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { |
0 |
0 |
0 |
|
| 189 |
0 |
| myhtml_tree_clean(tree); |
| 190 |
|
| } |
| 191 |
|
| |
| 192 |
0 |
| myhtml_encoding_set(tree, encoding); |
| 193 |
|
| |
| 194 |
0 |
| myhtml_tokenizer_begin(tree, html, html_size); |
| 195 |
0 |
| myhtml_tokenizer_end(tree); |
| 196 |
|
| |
| 197 |
0 |
| return MyHTML_STATUS_OK; |
| 198 |
|
| } |
| 199 |
|
| |
| 200 |
0 |
| myhtml_status_t myhtml_parse_fragment(myhtml_tree_t* tree, myhtml_encoding_t encoding, const char* html, size_t html_size, myhtml_tag_id_t tag_id, enum myhtml_namespace my_namespace) |
| 201 |
|
| { |
| 202 |
0 |
▶ | if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { |
0 |
0 |
0 |
|
| 203 |
0 |
| myhtml_tree_clean(tree); |
| 204 |
|
| } |
| 205 |
|
| |
| 206 |
0 |
▶ | if(tag_id == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if(tag_id == 0) |
0 |
0 |
0 |
|
| 207 |
0 |
| tag_id = MyHTML_TAG_DIV; |
| 208 |
|
| |
| 209 |
0 |
▶ | if(my_namespace == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if(my_namespace == 0) |
0 |
0 |
0 |
|
| 210 |
0 |
| my_namespace = MyHTML_NAMESPACE_HTML; |
| 211 |
|
| |
| 212 |
0 |
| myhtml_tokenizer_fragment_init(tree, tag_id, my_namespace); |
| 213 |
0 |
| myhtml_encoding_set(tree, encoding); |
| 214 |
|
| |
| 215 |
0 |
| myhtml_tokenizer_begin(tree, html, html_size); |
| 216 |
0 |
| myhtml_tokenizer_end(tree); |
| 217 |
|
| |
| 218 |
0 |
| return MyHTML_STATUS_OK; |
| 219 |
|
| } |
| 220 |
|
| |
| 221 |
0 |
| myhtml_status_t myhtml_parse_single(myhtml_tree_t* tree, myhtml_encoding_t encoding, const char* html, size_t html_size) |
| 222 |
|
| { |
| 223 |
0 |
▶ | if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { |
0 |
0 |
0 |
|
| 224 |
0 |
| myhtml_tree_clean(tree); |
| 225 |
|
| } |
| 226 |
|
| |
| 227 |
0 |
| tree->flags |= MyHTML_TREE_FLAGS_SINGLE_MODE; |
| 228 |
|
| |
| 229 |
0 |
| myhtml_encoding_set(tree, encoding); |
| 230 |
|
| |
| 231 |
0 |
| myhtml_tokenizer_begin(tree, html, html_size); |
| 232 |
0 |
| myhtml_tokenizer_end(tree); |
| 233 |
|
| |
| 234 |
0 |
| return MyHTML_STATUS_OK; |
| 235 |
|
| } |
| 236 |
|
| |
| 237 |
0 |
| myhtml_status_t myhtml_parse_fragment_single(myhtml_tree_t* tree, myhtml_encoding_t encoding, const char* html, size_t html_size, myhtml_tag_id_t tag_id, enum myhtml_namespace my_namespace) |
| 238 |
|
| { |
| 239 |
0 |
▶ | if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { |
0 |
0 |
0 |
|
| 240 |
0 |
| myhtml_tree_clean(tree); |
| 241 |
|
| } |
| 242 |
|
| |
| 243 |
0 |
▶ | if(tag_id == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if(tag_id == 0) |
0 |
0 |
0 |
|
| 244 |
0 |
| tag_id = MyHTML_TAG_DIV; |
| 245 |
|
| |
| 246 |
0 |
▶ | if(my_namespace == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if(my_namespace == 0) |
0 |
0 |
0 |
|
| 247 |
0 |
| my_namespace = MyHTML_NAMESPACE_HTML; |
| 248 |
|
| |
| 249 |
0 |
| tree->flags |= MyHTML_TREE_FLAGS_SINGLE_MODE; |
| 250 |
|
| |
| 251 |
0 |
| myhtml_tokenizer_fragment_init(tree, tag_id, my_namespace); |
| 252 |
0 |
| myhtml_encoding_set(tree, encoding); |
| 253 |
|
| |
| 254 |
0 |
| myhtml_tokenizer_begin(tree, html, html_size); |
| 255 |
0 |
| myhtml_tokenizer_end(tree); |
| 256 |
|
| |
| 257 |
0 |
| return MyHTML_STATUS_OK; |
| 258 |
|
| } |
| 259 |
|
| |
| 260 |
0 |
| myhtml_status_t myhtml_parse_chunk(myhtml_tree_t* tree, const char* html, size_t html_size) |
| 261 |
|
| { |
| 262 |
0 |
▶ | if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { |
0 |
0 |
0 |
|
| 263 |
0 |
| myhtml_tree_clean(tree); |
| 264 |
|
| } |
| 265 |
|
| |
| 266 |
0 |
| myhtml_tokenizer_chunk(tree, html, html_size); |
| 267 |
|
| |
| 268 |
0 |
| return MyHTML_STATUS_OK; |
| 269 |
|
| } |
| 270 |
|
| |
| 271 |
0 |
| myhtml_status_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 my_namespace) |
| 272 |
|
| { |
| 273 |
0 |
▶ | if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { |
0 |
0 |
0 |
|
| 274 |
0 |
| myhtml_tree_clean(tree); |
| 275 |
|
| } |
| 276 |
|
| |
| 277 |
0 |
▶ | if(tag_id == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if(tag_id == 0) |
0 |
0 |
0 |
|
| 278 |
0 |
| tag_id = MyHTML_TAG_DIV; |
| 279 |
|
| |
| 280 |
0 |
▶ | if(my_namespace == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if(my_namespace == 0) |
0 |
0 |
0 |
|
| 281 |
0 |
| my_namespace = MyHTML_NAMESPACE_HTML; |
| 282 |
|
| |
| 283 |
0 |
| myhtml_tokenizer_fragment_init(tree, tag_id, my_namespace); |
| 284 |
|
| |
| 285 |
0 |
| myhtml_tokenizer_chunk(tree, html, html_size); |
| 286 |
|
| |
| 287 |
0 |
| return MyHTML_STATUS_OK; |
| 288 |
|
| } |
| 289 |
|
| |
| 290 |
0 |
| myhtml_status_t myhtml_parse_chunk_single(myhtml_tree_t* tree, const char* html, size_t html_size) |
| 291 |
|
| { |
| 292 |
0 |
▶ | if((tree->flags & MyHTML_TREE_FLAGS_SINGLE_MODE) == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if((tree->flags & MyHTML_TREE_FLAGS_SINGLE_MODE) == 0) |
0 |
0 |
0 |
|
| 293 |
0 |
| tree->flags |= MyHTML_TREE_FLAGS_SINGLE_MODE; |
| 294 |
|
| |
| 295 |
0 |
| return myhtml_parse_chunk(tree, html, html_size); |
| 296 |
|
| } |
| 297 |
|
| |
| 298 |
0 |
| myhtml_status_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 my_namespace) |
| 299 |
|
| { |
| 300 |
0 |
▶ | if((tree->flags & MyHTML_TREE_FLAGS_SINGLE_MODE) == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if((tree->flags & MyHTML_TREE_FLAGS_SINGLE_MODE) == 0) |
0 |
0 |
0 |
|
| 301 |
0 |
| tree->flags |= MyHTML_TREE_FLAGS_SINGLE_MODE; |
| 302 |
|
| |
| 303 |
0 |
| return myhtml_parse_chunk_fragment(tree, html, html_size, tag_id, my_namespace); |
| 304 |
|
| } |
| 305 |
|
| |
| 306 |
0 |
| myhtml_status_t myhtml_parse_chunk_end(myhtml_tree_t* tree) |
| 307 |
|
| { |
| 308 |
0 |
| myhtml_tokenizer_end(tree); |
| 309 |
0 |
| return MyHTML_STATUS_OK; |
| 310 |
|
| } |
| 311 |
|
| |
| 312 |
0 |
| void myhtml_encoding_set(myhtml_tree_t* tree, myhtml_encoding_t encoding) |
| 313 |
|
| { |
| 314 |
0 |
▶ | if(encoding >= MyHTML_ENCODING_LAST_ENTRY) |
Branch: 1 branch
| Branch | True | False | Total |
| if(encoding >= MyHTML_ENCODING_LAST_ENTRY) |
0 |
0 |
0 |
|
| 315 |
0 |
| return; |
| 316 |
|
| |
| 317 |
0 |
| tree->encoding_usereq = encoding; |
| 318 |
0 |
| tree->encoding = encoding; |
| 319 |
|
| } |
| 320 |
|
| |
| 321 |
0 |
| myhtml_encoding_t myhtml_encoding_get(myhtml_tree_t* tree) |
| 322 |
|
| { |
| 323 |
0 |
| return tree->encoding; |
| 324 |
|
| } |
| 325 |
|
| |
| 326 |
|
| /* |
| 327 |
|
| * Nodes |
| 328 |
|
| */ |
| 329 |
0 |
| myhtml_collection_t * myhtml_get_nodes_by_tag_id(myhtml_tree_t* tree, myhtml_collection_t *collection, myhtml_tag_id_t tag_id, myhtml_status_t *status) |
| 330 |
|
| { |
| 331 |
0 |
| myhtml_tag_index_entry_t *index_tag = myhtml_tag_index_entry(tree->indexes->tags, tag_id); |
| 332 |
0 |
| myhtml_tag_index_node_t *index_node = myhtml_tag_index_first(tree->indexes->tags, tag_id); |
| 333 |
|
| |
| 334 |
0 |
▶ | if(index_tag->count == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(index_tag->count == 0) { |
0 |
0 |
0 |
|
| 335 |
0 |
▶ | if(status) |
Branch: 1 branch
| Branch | True | False | Total |
| if(status) |
0 |
0 |
0 |
|
| 336 |
0 |
| *status = MyHTML_STATUS_OK; |
| 337 |
|
| |
| 338 |
0 |
| return collection; |
| 339 |
|
| } |
| 340 |
|
| |
| 341 |
0 |
| myhtml_status_t mystatus = MyHTML_STATUS_OK; |
| 342 |
0 |
| size_t idx = 0; |
| 343 |
|
| |
| 344 |
0 |
▶ | if(collection == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(collection == NULL) { |
0 |
0 |
0 |
|
| 345 |
0 |
| collection = myhtml_collection_create((index_tag->count + 128), &mystatus); |
| 346 |
|
| |
| 347 |
0 |
| collection->length += index_tag->count; |
| 348 |
|
| } |
| 349 |
|
| else { |
| 350 |
0 |
| idx = collection->length; |
| 351 |
0 |
| mystatus = myhtml_collection_check_size(collection, index_tag->count); |
| 352 |
|
| } |
| 353 |
|
| |
| 354 |
0 |
▶ | if(mystatus) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(mystatus) { |
0 |
0 |
0 |
|
| 355 |
0 |
▶ | if(status) |
Branch: 1 branch
| Branch | True | False | Total |
| if(status) |
0 |
0 |
0 |
|
| 356 |
0 |
| *status = mystatus; |
| 357 |
|
| |
| 358 |
0 |
| return collection; |
| 359 |
|
| } |
| 360 |
|
| |
| 361 |
0 |
▶ | while (index_node) |
Branch: 1 branch
| Branch | True | False | Total |
| while (index_node) |
0 |
0 |
0 |
|
| 362 |
|
| { |
| 363 |
0 |
| collection->list[idx] = index_node->node; |
| 364 |
0 |
| idx++; |
| 365 |
|
| |
| 366 |
0 |
| index_node = index_node->next; |
| 367 |
|
| } |
| 368 |
|
| |
| 369 |
0 |
| collection->list[idx] = NULL; |
| 370 |
|
| |
| 371 |
0 |
▶ | if(status) |
Branch: 1 branch
| Branch | True | False | Total |
| if(status) |
0 |
0 |
0 |
|
| 372 |
0 |
| *status = mystatus; |
| 373 |
|
| |
| 374 |
0 |
| return collection; |
| 375 |
|
| } |
| 376 |
|
| |
| 377 |
0 |
| myhtml_collection_t * myhtml_get_nodes_by_name(myhtml_tree_t* tree, myhtml_collection_t *collection, const char* html, size_t length, myhtml_status_t *status) |
| 378 |
|
| { |
| 379 |
0 |
| const myhtml_tag_context_t *tag_ctx = myhtml_tag_get_by_name(tree->tags, html, length); |
| 380 |
0 |
| return myhtml_get_nodes_by_tag_id(tree, collection, tag_ctx->id, status); |
| 381 |
|
| } |
| 382 |
|
| |
| 383 |
|
| /* |
| 384 |
|
| * Manipulate Nodes |
| 385 |
|
| */ |
| 386 |
0 |
| myhtml_tree_node_t * myhtml_node_first(myhtml_tree_t* tree) |
| 387 |
|
| { |
| 388 |
0 |
▶ | if(tree->fragment) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(tree->fragment) { |
0 |
0 |
0 |
|
| 389 |
|
| // document -> html -> need element |
| 390 |
0 |
▶ | if(tree->document && tree->document->child) |
Branch: 2 branches
| Branch | True | False | Total |
| if(tree->document && tree->document->child) |
0 |
0 |
0 |
| if(tree->document && tree->document->child) |
0 |
0 |
0 |
|
| 391 |
0 |
| return tree->document->child->child; |
| 392 |
|
| } |
| 393 |
0 |
▶ | else if(tree->document) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if(tree->document) { |
0 |
0 |
0 |
|
| 394 |
|
| // document -> html |
| 395 |
0 |
| return tree->document->child; |
| 396 |
|
| } |
| 397 |
|
| |
| 398 |
0 |
| return NULL; |
| 399 |
|
| } |
| 400 |
|
| |
| 401 |
0 |
| myhtml_tree_node_t * myhtml_node_next(myhtml_tree_node_t *node) |
| 402 |
|
| { |
| 403 |
0 |
| return node->next; |
| 404 |
|
| } |
| 405 |
|
| |
| 406 |
0 |
| myhtml_tree_node_t * myhtml_node_prev(myhtml_tree_node_t *node) |
| 407 |
|
| { |
| 408 |
0 |
| return node->prev; |
| 409 |
|
| } |
| 410 |
|
| |
| 411 |
0 |
| myhtml_tree_node_t * myhtml_node_parent(myhtml_tree_node_t *node) |
| 412 |
|
| { |
| 413 |
0 |
| return node->parent; |
| 414 |
|
| } |
| 415 |
|
| |
| 416 |
0 |
| myhtml_tree_node_t * myhtml_node_child(myhtml_tree_node_t *node) |
| 417 |
|
| { |
| 418 |
0 |
| return node->child; |
| 419 |
|
| } |
| 420 |
|
| |
| 421 |
0 |
| myhtml_tree_node_t * myhtml_node_last_child(myhtml_tree_node_t *node) |
| 422 |
|
| { |
| 423 |
0 |
| return node->last_child; |
| 424 |
|
| } |
| 425 |
|
| |
| 426 |
0 |
| myhtml_tree_node_t * myhtml_node_create(myhtml_tree_t* tree, myhtml_tag_id_t tag_id, enum myhtml_namespace my_namespace) |
| 427 |
|
| { |
| 428 |
0 |
| myhtml_tree_node_t *node = myhtml_tree_node_create(tree); |
| 429 |
|
| |
| 430 |
0 |
| node->tag_idx = tag_id; |
| 431 |
0 |
| node->my_namespace = my_namespace; |
| 432 |
|
| |
| 433 |
0 |
| return node; |
| 434 |
|
| } |
| 435 |
|
| |
| 436 |
0 |
| myhtml_tree_node_t * myhtml_node_remove(myhtml_tree_node_t *node) |
| 437 |
|
| { |
| 438 |
0 |
| return myhtml_tree_node_remove(node); |
| 439 |
|
| } |
| 440 |
|
| |
| 441 |
0 |
| void myhtml_node_delete(myhtml_tree_t* tree, myhtml_tree_node_t *node) |
| 442 |
|
| { |
| 443 |
0 |
| myhtml_tree_node_delete(tree, node); |
| 444 |
0 |
| } |
| 445 |
|
| |
| 446 |
0 |
| void myhtml_node_delete_recursive(myhtml_tree_t* tree, myhtml_tree_node_t *node) |
| 447 |
|
| { |
| 448 |
0 |
| myhtml_tree_node_delete_recursive(tree, node); |
| 449 |
0 |
| } |
| 450 |
|
| |
| 451 |
0 |
| void myhtml_node_free(myhtml_tree_t* tree, myhtml_tree_node_t *node) |
| 452 |
|
| { |
| 453 |
0 |
| myhtml_tree_node_free(tree, node); |
| 454 |
0 |
| } |
| 455 |
|
| |
| 456 |
0 |
| myhtml_tree_node_t * myhtml_node_insert_before(myhtml_tree_t* tree, myhtml_tree_node_t *target, myhtml_tree_node_t *node) |
| 457 |
|
| { |
| 458 |
0 |
▶ | if(target == NULL || node == NULL) |
Branch: 2 branches
| Branch | True | False | Total |
| if(target == NULL || node == NULL) |
0 |
0 |
0 |
| if(target == NULL || node == NULL) |
0 |
0 |
0 |
|
| 459 |
0 |
| return NULL; |
| 460 |
|
| |
| 461 |
0 |
| myhtml_tree_node_insert_before(tree, target, node); |
| 462 |
|
| |
| 463 |
0 |
| return node; |
| 464 |
|
| } |
| 465 |
|
| |
| 466 |
0 |
| myhtml_tree_node_t * myhtml_node_insert_after(myhtml_tree_t* tree, myhtml_tree_node_t *target, myhtml_tree_node_t *node) |
| 467 |
|
| { |
| 468 |
0 |
▶ | if(target == NULL || node == NULL) |
Branch: 2 branches
| Branch | True | False | Total |
| if(target == NULL || node == NULL) |
0 |
0 |
0 |
| if(target == NULL || node == NULL) |
0 |
0 |
0 |
|
| 469 |
0 |
| return NULL; |
| 470 |
|
| |
| 471 |
0 |
| myhtml_tree_node_insert_after(tree, target, node); |
| 472 |
|
| |
| 473 |
0 |
| return node; |
| 474 |
|
| } |
| 475 |
|
| |
| 476 |
0 |
| myhtml_tree_node_t * myhtml_node_insert_append_child(myhtml_tree_t* tree, myhtml_tree_node_t *target, myhtml_tree_node_t *node) |
| 477 |
|
| { |
| 478 |
0 |
▶ | if(target == NULL || node == NULL) |
Branch: 2 branches
| Branch | True | False | Total |
| if(target == NULL || node == NULL) |
0 |
0 |
0 |
| if(target == NULL || node == NULL) |
0 |
0 |
0 |
|
| 479 |
0 |
| return NULL; |
| 480 |
|
| |
| 481 |
0 |
| myhtml_tree_node_add_child(tree, target, node); |
| 482 |
|
| |
| 483 |
0 |
| return node; |
| 484 |
|
| } |
| 485 |
|
| |
| 486 |
0 |
| myhtml_tree_node_t * myhtml_node_insert_to_appropriate_place(myhtml_tree_t* tree, myhtml_tree_node_t *target, myhtml_tree_node_t *node) |
| 487 |
|
| { |
| 488 |
0 |
▶ | if(target == NULL || node == NULL) |
Branch: 2 branches
| Branch | True | False | Total |
| if(target == NULL || node == NULL) |
0 |
0 |
0 |
| if(target == NULL || node == NULL) |
0 |
0 |
0 |
|
| 489 |
0 |
| return NULL; |
| 490 |
|
| |
| 491 |
|
| enum myhtml_tree_insertion_mode mode; |
| 492 |
|
| |
| 493 |
0 |
| tree->foster_parenting = true; |
| 494 |
0 |
| target = myhtml_tree_appropriate_place_inserting_in_tree(tree, target, &mode); |
| 495 |
0 |
| tree->foster_parenting = false; |
| 496 |
|
| |
| 497 |
0 |
| myhtml_tree_node_insert_by_mode(tree, target, node, mode); |
| 498 |
|
| |
| 499 |
0 |
| return node; |
| 500 |
|
| } |
| 501 |
|
| |
| 502 |
0 |
| myhtml_string_t * myhtml_node_text_set(myhtml_tree_t* tree, myhtml_tree_node_t *node, const char* text, size_t length, myhtml_encoding_t encoding) |
| 503 |
|
| { |
| 504 |
0 |
▶ | if(node == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(node == NULL) |
0 |
0 |
0 |
|
| 505 |
0 |
| return NULL; |
| 506 |
|
| |
| 507 |
0 |
▶ | if(encoding >= MyHTML_ENCODING_LAST_ENTRY) |
Branch: 1 branch
| Branch | True | False | Total |
| if(encoding >= MyHTML_ENCODING_LAST_ENTRY) |
0 |
0 |
0 |
|
| 508 |
0 |
| return NULL; |
| 509 |
|
| |
| 510 |
0 |
▶ | if(node->token == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(node->token == NULL) { |
0 |
0 |
0 |
|
| 511 |
|
| mcobject_async_status_t mcstatus; |
| 512 |
0 |
| node->token = (myhtml_token_node_t*)mcobject_async_malloc(tree->token->nodes_obj, tree->mcasync_token_id, &mcstatus); |
| 513 |
|
| |
| 514 |
0 |
▶ | if(mcstatus) |
Branch: 1 branch
| Branch | True | False | Total |
| if(mcstatus) |
0 |
0 |
0 |
|
| 515 |
0 |
| return NULL; |
| 516 |
|
| |
| 517 |
0 |
| myhtml_token_node_clean(node->token); |
| 518 |
|
| } |
| 519 |
|
| |
| 520 |
0 |
▶ | if(node->token->my_str_tm.data == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(node->token->my_str_tm.data == NULL) { |
0 |
0 |
0 |
|
| 521 |
0 |
| myhtml_string_init(tree->mchar, tree->mchar_node_id, &node->token->my_str_tm, (length + 2)); |
| 522 |
|
| } |
| 523 |
|
| else { |
| 524 |
0 |
▶ | if(node->token->my_str_tm.size < length) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(node->token->my_str_tm.size < length) { |
0 |
0 |
0 |
|
| 525 |
0 |
| mchar_async_free(tree->mchar, node->token->my_str_tm.node_idx, node->token->my_str_tm.data); |
| 526 |
0 |
| myhtml_string_init(tree->mchar, tree->mchar_node_id, &node->token->my_str_tm, length); |
| 527 |
|
| } |
| 528 |
|
| else |
| 529 |
0 |
| node->token->my_str_tm.length = 0; |
| 530 |
|
| } |
| 531 |
|
| |
| 532 |
0 |
▶ | if(encoding != MyHTML_ENCODING_UTF_8) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(encoding != MyHTML_ENCODING_UTF_8) { |
0 |
0 |
0 |
|
| 533 |
0 |
| myhtml_string_append_with_convert_encoding(&node->token->my_str_tm, text, length, encoding); |
| 534 |
|
| } |
| 535 |
|
| else { |
| 536 |
0 |
| myhtml_string_append(&node->token->my_str_tm, text, length); |
| 537 |
|
| } |
| 538 |
|
| |
| 539 |
0 |
| node->token->begin = 0; |
| 540 |
0 |
| node->token->length = node->token->my_str_tm.length; |
| 541 |
|
| |
| 542 |
0 |
| return &node->token->my_str_tm; |
| 543 |
|
| } |
| 544 |
|
| |
| 545 |
0 |
| myhtml_string_t * myhtml_node_text_set_with_charef(myhtml_tree_t* tree, myhtml_tree_node_t *node, const char* text, size_t length, myhtml_encoding_t encoding) |
| 546 |
|
| { |
| 547 |
0 |
▶ | if(node == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(node == NULL) |
0 |
0 |
0 |
|
| 548 |
0 |
| return NULL; |
| 549 |
|
| |
| 550 |
0 |
▶ | if(encoding >= MyHTML_ENCODING_LAST_ENTRY) |
Branch: 1 branch
| Branch | True | False | Total |
| if(encoding >= MyHTML_ENCODING_LAST_ENTRY) |
0 |
0 |
0 |
|
| 551 |
0 |
| return NULL; |
| 552 |
|
| |
| 553 |
0 |
▶ | if(node->token == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(node->token == NULL) { |
0 |
0 |
0 |
|
| 554 |
|
| mcobject_async_status_t mcstatus; |
| 555 |
0 |
| node->token = (myhtml_token_node_t*)mcobject_async_malloc(tree->token->nodes_obj, tree->mcasync_token_id, &mcstatus); |
| 556 |
|
| |
| 557 |
0 |
▶ | if(mcstatus) |
Branch: 1 branch
| Branch | True | False | Total |
| if(mcstatus) |
0 |
0 |
0 |
|
| 558 |
0 |
| return NULL; |
| 559 |
|
| |
| 560 |
0 |
| myhtml_token_node_clean(node->token); |
| 561 |
|
| } |
| 562 |
|
| |
| 563 |
0 |
▶ | if(node->token->my_str_tm.data == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(node->token->my_str_tm.data == NULL) { |
0 |
0 |
0 |
|
| 564 |
0 |
| myhtml_string_init(tree->mchar, tree->mchar_node_id, &node->token->my_str_tm, (length + 2)); |
| 565 |
|
| } |
| 566 |
|
| else { |
| 567 |
0 |
▶ | if(node->token->my_str_tm.size < length) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(node->token->my_str_tm.size < length) { |
0 |
0 |
0 |
|
| 568 |
0 |
| mchar_async_free(tree->mchar, node->token->my_str_tm.node_idx, node->token->my_str_tm.data); |
| 569 |
0 |
| myhtml_string_init(tree->mchar, tree->mchar_node_id, &node->token->my_str_tm, length); |
| 570 |
|
| } |
| 571 |
|
| else |
| 572 |
0 |
| node->token->my_str_tm.length = 0; |
| 573 |
|
| } |
| 574 |
|
| |
| 575 |
0 |
| myhtml_string_char_ref_chunk_t str_chunk = {0, 0, 0, {0}, false, encoding}; |
| 576 |
0 |
| myhtml_encoding_result_clean(&str_chunk.res); |
| 577 |
|
| |
| 578 |
0 |
| myhtml_string_append_charef(&str_chunk, &node->token->my_str_tm, text, length); |
| 579 |
0 |
| myhtml_string_append_charef_end(&str_chunk, &node->token->my_str_tm); |
| 580 |
|
| |
| 581 |
0 |
| node->token->begin = 0; |
| 582 |
0 |
| node->token->length = node->token->my_str_tm.length; |
| 583 |
|
| |
| 584 |
0 |
| return &node->token->my_str_tm; |
| 585 |
|
| } |
| 586 |
|
| |
| 587 |
0 |
| enum myhtml_namespace myhtml_node_namespace(myhtml_tree_node_t *node) |
| 588 |
|
| { |
| 589 |
0 |
| return node->my_namespace; |
| 590 |
|
| } |
| 591 |
|
| |
| 592 |
0 |
| myhtml_tag_id_t myhtml_node_tag_id(myhtml_tree_node_t *node) |
| 593 |
|
| { |
| 594 |
0 |
| return node->tag_idx; |
| 595 |
|
| } |
| 596 |
|
| |
| 597 |
0 |
| const char * myhtml_tag_name_by_id(myhtml_tree_t* tree, myhtml_tag_id_t tag_id, size_t *length) |
| 598 |
|
| { |
| 599 |
0 |
▶ | if(length) |
Branch: 1 branch
| Branch | True | False | Total |
| if(length) |
0 |
0 |
0 |
|
| 600 |
0 |
| *length = 0; |
| 601 |
|
| |
| 602 |
0 |
▶ | if(tree == NULL || tree->tags == NULL) |
Branch: 2 branches
| Branch | True | False | Total |
| if(tree == NULL || tree->tags == NULL) |
0 |
0 |
0 |
| if(tree == NULL || tree->tags == NULL) |
0 |
0 |
0 |
|
| 603 |
0 |
| return NULL; |
| 604 |
|
| |
| 605 |
0 |
| const myhtml_tag_context_t *ctx = myhtml_tag_get_by_id(tree->tags, tag_id); |
| 606 |
|
| |
| 607 |
0 |
▶ | if(ctx == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(ctx == NULL) |
0 |
0 |
0 |
|
| 608 |
0 |
| return NULL; |
| 609 |
|
| |
| 610 |
0 |
▶ | if(length) |
Branch: 1 branch
| Branch | True | False | Total |
| if(length) |
0 |
0 |
0 |
|
| 611 |
0 |
| *length = ctx->name_length; |
| 612 |
|
| |
| 613 |
0 |
| return ctx->name; |
| 614 |
|
| } |
| 615 |
|
| |
| 616 |
0 |
| myhtml_tag_id_t myhtml_tag_id_by_name(myhtml_tree_t* tree, const char *tag_name, size_t length) |
| 617 |
|
| { |
| 618 |
0 |
▶ | if(tree == NULL || tree->tags == NULL) |
Branch: 2 branches
| Branch | True | False | Total |
| if(tree == NULL || tree->tags == NULL) |
0 |
0 |
0 |
| if(tree == NULL || tree->tags == NULL) |
0 |
0 |
0 |
|
| 619 |
0 |
| return MyHTML_TAG__UNDEF; |
| 620 |
|
| |
| 621 |
0 |
| const myhtml_tag_context_t *ctx = myhtml_tag_get_by_name(tree->tags, tag_name, length); |
| 622 |
|
| |
| 623 |
0 |
▶ | if(ctx == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(ctx == NULL) |
0 |
0 |
0 |
|
| 624 |
0 |
| return MyHTML_TAG__UNDEF; |
| 625 |
|
| |
| 626 |
0 |
| return ctx->id; |
| 627 |
|
| } |
| 628 |
|
| |
| 629 |
0 |
| bool myhtml_node_is_close_self(myhtml_tree_node_t *node) |
| 630 |
|
| { |
| 631 |
0 |
▶ | if(node->token) |
Branch: 1 branch
| Branch | True | False | Total |
| if(node->token) |
0 |
0 |
0 |
|
| 632 |
0 |
| return (node->token->type & MyHTML_TOKEN_TYPE_CLOSE_SELF); |
| 633 |
|
| |
| 634 |
0 |
| return false; |
| 635 |
|
| } |
| 636 |
|
| |
| 637 |
0 |
| myhtml_tree_attr_t * myhtml_node_attribute_first(myhtml_tree_node_t *node) |
| 638 |
|
| { |
| 639 |
0 |
▶ | if(node->token) |
Branch: 1 branch
| Branch | True | False | Total |
| if(node->token) |
0 |
0 |
0 |
|
| 640 |
0 |
| return node->token->attr_first; |
| 641 |
|
| |
| 642 |
0 |
| return NULL; |
| 643 |
|
| } |
| 644 |
|
| |
| 645 |
0 |
| myhtml_tree_attr_t * myhtml_node_attribute_last(myhtml_tree_node_t *node) |
| 646 |
|
| { |
| 647 |
0 |
▶ | if(node->token) |
Branch: 1 branch
| Branch | True | False | Total |
| if(node->token) |
0 |
0 |
0 |
|
| 648 |
0 |
| return node->token->attr_first; |
| 649 |
|
| |
| 650 |
0 |
| return NULL; |
| 651 |
|
| } |
| 652 |
|
| |
| 653 |
0 |
| const char * myhtml_node_text(myhtml_tree_node_t *node, size_t *length) |
| 654 |
|
| { |
| 655 |
0 |
▶ | if(node->token && node->token->length && node->token->my_str_tm.data) |
Branch: 3 branches
| Branch | True | False | Total |
| if(node->token && node->token->length && node->token->my_str_tm.data) |
0 |
0 |
0 |
| if(node->token && node->token->length && node->token->my_str_tm.data) |
0 |
0 |
0 |
| if(node->token && node->token->length && node->token->my_str_tm.data) |
0 |
0 |
0 |
|
| 656 |
|
| { |
| 657 |
0 |
▶ | if(length) |
Branch: 1 branch
| Branch | True | False | Total |
| if(length) |
0 |
0 |
0 |
|
| 658 |
0 |
| *length = node->token->length; |
| 659 |
|
| |
| 660 |
0 |
| return &node->token->my_str_tm.data[node->token->begin]; |
| 661 |
|
| } |
| 662 |
|
| |
| 663 |
0 |
▶ | if(length) |
Branch: 1 branch
| Branch | True | False | Total |
| if(length) |
0 |
0 |
0 |
|
| 664 |
0 |
| *length = 0; |
| 665 |
|
| |
| 666 |
0 |
| return NULL; |
| 667 |
|
| } |
| 668 |
|
| |
| 669 |
0 |
| myhtml_string_t * myhtml_node_string(myhtml_tree_node_t *node) |
| 670 |
|
| { |
| 671 |
0 |
▶ | if(node && node->token) |
Branch: 2 branches
| Branch | True | False | Total |
| if(node && node->token) |
0 |
0 |
0 |
| if(node && node->token) |
0 |
0 |
0 |
|
| 672 |
0 |
| return &node->token->my_str_tm; |
| 673 |
|
| |
| 674 |
0 |
| return NULL; |
| 675 |
|
| } |
| 676 |
|
| |
| 677 |
|
| /* |
| 678 |
|
| * Attributes |
| 679 |
|
| */ |
| 680 |
0 |
| myhtml_tree_attr_t * myhtml_attribute_next(myhtml_tree_attr_t *attr) |
| 681 |
|
| { |
| 682 |
0 |
| return attr->next; |
| 683 |
|
| } |
| 684 |
|
| |
| 685 |
0 |
| myhtml_tree_attr_t * myhtml_attribute_prev(myhtml_tree_attr_t *attr) |
| 686 |
|
| { |
| 687 |
0 |
| return attr->prev; |
| 688 |
|
| } |
| 689 |
|
| |
| 690 |
0 |
| enum myhtml_namespace myhtml_attribute_namespace(myhtml_tree_attr_t *attr) |
| 691 |
|
| { |
| 692 |
0 |
| return attr->my_namespace; |
| 693 |
|
| } |
| 694 |
|
| |
| 695 |
0 |
| const char * myhtml_attribute_name(myhtml_tree_attr_t *attr, size_t *length) |
| 696 |
|
| { |
| 697 |
0 |
▶ | if(attr->entry.data && attr->name_length) |
Branch: 2 branches
| Branch | True | False | Total |
| if(attr->entry.data && attr->name_length) |
0 |
0 |
0 |
| if(attr->entry.data && attr->name_length) |
0 |
0 |
0 |
|
| 698 |
|
| { |
| 699 |
0 |
▶ | if(length) |
Branch: 1 branch
| Branch | True | False | Total |
| if(length) |
0 |
0 |
0 |
|
| 700 |
0 |
| *length = attr->name_length; |
| 701 |
|
| |
| 702 |
0 |
| return &attr->entry.data[attr->name_begin]; |
| 703 |
|
| } |
| 704 |
|
| |
| 705 |
0 |
▶ | if(length) |
Branch: 1 branch
| Branch | True | False | Total |
| if(length) |
0 |
0 |
0 |
|
| 706 |
0 |
| *length = 0; |
| 707 |
|
| |
| 708 |
0 |
| return NULL; |
| 709 |
|
| } |
| 710 |
|
| |
| 711 |
0 |
| const char * myhtml_attribute_value(myhtml_tree_attr_t *attr, size_t *length) |
| 712 |
|
| { |
| 713 |
0 |
▶ | if(attr->entry.data && attr->value_length) |
Branch: 2 branches
| Branch | True | False | Total |
| if(attr->entry.data && attr->value_length) |
0 |
0 |
0 |
| if(attr->entry.data && attr->value_length) |
0 |
0 |
0 |
|
| 714 |
|
| { |
| 715 |
0 |
▶ | if(length) |
Branch: 1 branch
| Branch | True | False | Total |
| if(length) |
0 |
0 |
0 |
|
| 716 |
0 |
| *length = attr->value_length; |
| 717 |
|
| |
| 718 |
0 |
| return &attr->entry.data[attr->value_begin]; |
| 719 |
|
| } |
| 720 |
|
| |
| 721 |
0 |
▶ | if(length) |
Branch: 1 branch
| Branch | True | False | Total |
| if(length) |
0 |
0 |
0 |
|
| 722 |
0 |
| *length = 0; |
| 723 |
|
| |
| 724 |
0 |
| return NULL; |
| 725 |
|
| } |
| 726 |
|
| |
| 727 |
0 |
| myhtml_tree_attr_t * myhtml_attribute_by_key(myhtml_tree_node_t *node, const char *key, size_t key_len) |
| 728 |
|
| { |
| 729 |
0 |
▶ | if(node == NULL || node->token == NULL) |
Branch: 2 branches
| Branch | True | False | Total |
| if(node == NULL || node->token == NULL) |
0 |
0 |
0 |
| if(node == NULL || node->token == NULL) |
0 |
0 |
0 |
|
| 730 |
0 |
| return NULL; |
| 731 |
|
| |
| 732 |
0 |
| return myhtml_token_attr_by_name(node->token, key, key_len); |
| 733 |
|
| } |
| 734 |
|
| |
| 735 |
0 |
| myhtml_tree_attr_t * myhtml_attribute_add(myhtml_tree_t *tree, myhtml_tree_node_t *node, const char *key, size_t key_len, const char *value, size_t value_len, myhtml_encoding_t encoding) |
| 736 |
|
| { |
| 737 |
0 |
▶ | if(node == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(node == NULL) |
0 |
0 |
0 |
|
| 738 |
0 |
| return NULL; |
| 739 |
|
| |
| 740 |
0 |
▶ | if(node->token == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(node->token == NULL) { |
0 |
0 |
0 |
|
| 741 |
|
| mcobject_async_status_t mcstatus; |
| 742 |
0 |
| node->token = (myhtml_token_node_t*)mcobject_async_malloc(tree->token->nodes_obj, tree->mcasync_token_id, &mcstatus); |
| 743 |
|
| |
| 744 |
0 |
▶ | if(mcstatus) |
Branch: 1 branch
| Branch | True | False | Total |
| if(mcstatus) |
0 |
0 |
0 |
|
| 745 |
0 |
| return NULL; |
| 746 |
|
| |
| 747 |
0 |
| myhtml_token_node_clean(node->token); |
| 748 |
|
| } |
| 749 |
|
| |
| 750 |
0 |
| return myhtml_token_node_attr_append_with_convert_encoding(tree->token, node->token, key, key_len, |
| 751 |
|
| value, value_len, tree->mcasync_token_id, encoding); |
| 752 |
|
| } |
| 753 |
|
| |
| 754 |
0 |
| myhtml_tree_attr_t * myhtml_attribute_remove(myhtml_tree_node_t *node, myhtml_tree_attr_t *attr) |
| 755 |
|
| { |
| 756 |
0 |
▶ | if(node == NULL || node->token == NULL) |
Branch: 2 branches
| Branch | True | False | Total |
| if(node == NULL || node->token == NULL) |
0 |
0 |
0 |
| if(node == NULL || node->token == NULL) |
0 |
0 |
0 |
|
| 757 |
0 |
| return NULL; |
| 758 |
|
| |
| 759 |
0 |
| return myhtml_token_attr_remove(node->token, attr); |
| 760 |
|
| } |
| 761 |
|
| |
| 762 |
0 |
| myhtml_tree_attr_t * myhtml_attribute_remove_by_key(myhtml_tree_node_t *node, const char *key, size_t key_len) |
| 763 |
|
| { |
| 764 |
0 |
▶ | if(node == NULL || node->token == NULL) |
Branch: 2 branches
| Branch | True | False | Total |
| if(node == NULL || node->token == NULL) |
0 |
0 |
0 |
| if(node == NULL || node->token == NULL) |
0 |
0 |
0 |
|
| 765 |
0 |
| return NULL; |
| 766 |
|
| |
| 767 |
0 |
| return myhtml_token_attr_remove_by_name(node->token, key, key_len); |
| 768 |
|
| } |
| 769 |
|
| |
| 770 |
0 |
| void myhtml_attribute_delete(myhtml_tree_t *tree, myhtml_tree_node_t *node, myhtml_tree_attr_t *attr) |
| 771 |
|
| { |
| 772 |
0 |
▶ | if(node == NULL || node->token == NULL) |
Branch: 2 branches
| Branch | True | False | Total |
| if(node == NULL || node->token == NULL) |
0 |
0 |
0 |
| if(node == NULL || node->token == NULL) |
0 |
0 |
0 |
|
| 773 |
0 |
| return; |
| 774 |
|
| |
| 775 |
0 |
| myhtml_token_attr_remove(node->token, attr); |
| 776 |
0 |
| myhtml_attribute_free(tree, attr); |
| 777 |
|
| } |
| 778 |
|
| |
| 779 |
0 |
| void myhtml_attribute_free(myhtml_tree_t *tree, myhtml_tree_attr_t *attr) |
| 780 |
|
| { |
| 781 |
0 |
| mchar_async_free(attr->entry.mchar, attr->entry.node_idx, attr->entry.data); |
| 782 |
0 |
| mcobject_async_free(tree->token->attr_obj, attr); |
| 783 |
0 |
| } |
| 784 |
|
| |
| 785 |
|
| /* |
| 786 |
|
| * Collections |
| 787 |
|
| */ |
| 788 |
0 |
| myhtml_collection_t * myhtml_collection_create(size_t size, myhtml_status_t *status) |
| 789 |
|
| { |
| 790 |
0 |
| myhtml_collection_t *collection = (myhtml_collection_t*)malloc(sizeof(myhtml_collection_t)); |
| 791 |
|
| |
| 792 |
0 |
▶ | if(collection == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(collection == NULL) { |
0 |
0 |
0 |
|
| 793 |
0 |
▶ | if(status) |
Branch: 1 branch
| Branch | True | False | Total |
| if(status) |
0 |
0 |
0 |
|
| 794 |
0 |
| *status = MyHTML_STATUS_ERROR_MEMORY_ALLOCATION; |
| 795 |
|
| |
| 796 |
0 |
| return NULL; |
| 797 |
|
| } |
| 798 |
|
| |
| 799 |
0 |
| collection->size = size; |
| 800 |
0 |
| collection->length = 0; |
| 801 |
0 |
| collection->list = (myhtml_tree_node_t **)mymalloc(sizeof(myhtml_tree_node_t*) * size); |
| 802 |
|
| |
| 803 |
0 |
▶ | if(collection->list == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(collection->list == NULL) { |
0 |
0 |
0 |
|
| 804 |
0 |
| free(collection); |
| 805 |
|
| |
| 806 |
0 |
▶ | if(status) |
Branch: 1 branch
| Branch | True | False | Total |
| if(status) |
0 |
0 |
0 |
|
| 807 |
0 |
| *status = MyHTML_STATUS_ERROR_MEMORY_ALLOCATION; |
| 808 |
|
| |
| 809 |
0 |
| return NULL; |
| 810 |
|
| } |
| 811 |
|
| |
| 812 |
0 |
▶ | if(status) |
Branch: 1 branch
| Branch | True | False | Total |
| if(status) |
0 |
0 |
0 |
|
| 813 |
0 |
| *status = MyHTML_STATUS_OK; |
| 814 |
|
| |
| 815 |
0 |
| return collection; |
| 816 |
|
| } |
| 817 |
|
| |
| 818 |
0 |
| myhtml_status_t myhtml_collection_check_size(myhtml_collection_t *collection, size_t upto_length) |
| 819 |
|
| { |
| 820 |
0 |
| upto_length = collection->length + upto_length; |
| 821 |
|
| |
| 822 |
0 |
▶ | if(upto_length > collection->size) |
Branch: 1 branch
| Branch | True | False | Total |
| if(upto_length > collection->size) |
0 |
0 |
0 |
|
| 823 |
|
| { |
| 824 |
0 |
| size_t tmp_size = collection->length + 1024; |
| 825 |
0 |
| myhtml_tree_node_t **tmp = (myhtml_tree_node_t **)myrealloc(collection->list, sizeof(myhtml_tree_node_t*) * tmp_size); |
| 826 |
|
| |
| 827 |
0 |
▶ | if(tmp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(tmp) { |
0 |
0 |
0 |
|
| 828 |
0 |
| collection->length = upto_length; |
| 829 |
0 |
| collection->size = tmp_size; |
| 830 |
0 |
| collection->list = tmp; |
| 831 |
|
| } |
| 832 |
|
| else |
| 833 |
0 |
| return MyHTML_STATUS_ERROR_MEMORY_ALLOCATION; |
| 834 |
|
| } |
| 835 |
|
| |
| 836 |
0 |
| return MyHTML_STATUS_OK; |
| 837 |
|
| } |
| 838 |
|
| |
| 839 |
0 |
| void myhtml_collection_clean(myhtml_collection_t *collection) |
| 840 |
|
| { |
| 841 |
0 |
▶ | if(collection) |
Branch: 1 branch
| Branch | True | False | Total |
| if(collection) |
0 |
0 |
0 |
|
| 842 |
0 |
| collection->length = 0; |
| 843 |
0 |
| } |
| 844 |
|
| |
| 845 |
0 |
| myhtml_collection_t * myhtml_collection_destroy(myhtml_collection_t *collection) |
| 846 |
|
| { |
| 847 |
0 |
▶ | if(collection == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(collection == NULL) |
0 |
0 |
0 |
|
| 848 |
0 |
| return NULL; |
| 849 |
|
| |
| 850 |
0 |
▶ | if(collection->list) |
Branch: 1 branch
| Branch | True | False | Total |
| if(collection->list) |
0 |
0 |
0 |
|
| 851 |
0 |
| free(collection->list); |
| 852 |
|
| |
| 853 |
0 |
| free(collection); |
| 854 |
|
| |
| 855 |
0 |
| return NULL; |
| 856 |
|
| } |
| 857 |
|
| |
| 858 |
|
| // incoming buffer |
| 859 |
0 |
| void myhtml_incomming_buf_add(myhtml_t* myhtml, myhtml_tree_t* tree, myhtml_incoming_buf_t *current, const char *html, size_t html_size) |
| 860 |
|
| { |
| 861 |
0 |
| tree->incoming_buf = mcobject_async_malloc(myhtml->async_incoming_buf, tree->mcasync_incoming_buf_id, NULL); |
| 862 |
|
| |
| 863 |
0 |
| tree->incoming_buf->size = html_size; |
| 864 |
0 |
| tree->incoming_buf->length = 0; |
| 865 |
0 |
| tree->incoming_buf->data = html; |
| 866 |
0 |
| tree->incoming_buf->offset = tree->global_offset; |
| 867 |
|
| |
| 868 |
0 |
▶ | if(current) |
Branch: 1 branch
| Branch | True | False | Total |
| if(current) |
0 |
0 |
0 |
|
| 869 |
0 |
| current->next = tree->incoming_buf; |
| 870 |
|
| |
| 871 |
0 |
| tree->incoming_buf->prev = current; |
| 872 |
0 |
| tree->incoming_buf->next = NULL; |
| 873 |
0 |
| } |
| 874 |
|
| |
| 875 |
0 |
| void myhtml_tree_incomming_buf_clean(myhtml_tree_t* tree, myhtml_incoming_buf_t *current) |
| 876 |
|
| { |
| 877 |
0 |
| memset(current, 0, sizeof(myhtml_incoming_buf_t)); |
| 878 |
0 |
| } |
| 879 |
|
| |
| 880 |
0 |
| const char * myhtml_tree_incomming_buf_get_last(myhtml_tree_t *tree, myhtml_incoming_buf_t *inc_buf, size_t current_offset, size_t len) |
| 881 |
|
| { |
| 882 |
0 |
▶ | if(current_offset >= len) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(current_offset >= len) { |
0 |
0 |
0 |
|
| 883 |
0 |
| return &tree->incoming_buf->data[ (current_offset - len) ]; |
| 884 |
|
| } |
| 885 |
|
| |
| 886 |
0 |
▶ | if(tree->temp_tag_name.data == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(tree->temp_tag_name.data == NULL) |
0 |
0 |
0 |
|
| 887 |
0 |
| myhtml_tree_temp_tag_name_init(&tree->temp_tag_name); |
| 888 |
|
| else |
| 889 |
0 |
| myhtml_tree_temp_tag_name_clean(&tree->temp_tag_name); |
| 890 |
|
| |
| 891 |
0 |
| inc_buf = inc_buf->prev; |
| 892 |
|
| |
| 893 |
0 |
| size_t tmp_len = len - current_offset; |
| 894 |
0 |
▶ | while (tmp_len) |
Branch: 1 branch
| Branch | True | False | Total |
| while (tmp_len) |
0 |
0 |
0 |
|
| 895 |
|
| { |
| 896 |
0 |
▶ | if(inc_buf->size >= tmp_len) |
Branch: 1 branch
| Branch | True | False | Total |
| if(inc_buf->size >= tmp_len) |
0 |
0 |
0 |
|
| 897 |
0 |
| break; |
| 898 |
|
| |
| 899 |
0 |
| tmp_len -= inc_buf->size; |
| 900 |
0 |
| inc_buf = inc_buf->prev; |
| 901 |
|
| } |
| 902 |
|
| |
| 903 |
0 |
| myhtml_tree_temp_tag_name_append(&tree->temp_tag_name, &inc_buf->data[ (inc_buf->size - tmp_len) ], tmp_len); |
| 904 |
0 |
| tmp_len = len - tmp_len; |
| 905 |
0 |
| inc_buf = inc_buf->next; |
| 906 |
|
| |
| 907 |
0 |
▶ | while (inc_buf && tmp_len) |
Branch: 2 branches
| Branch | True | False | Total |
| while (inc_buf && tmp_len) |
0 |
0 |
0 |
| while (inc_buf && tmp_len) |
0 |
0 |
0 |
|
| 908 |
|
| { |
| 909 |
0 |
▶ | if(tmp_len > inc_buf->size) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(tmp_len > inc_buf->size) { |
0 |
0 |
0 |
|
| 910 |
0 |
| myhtml_tree_temp_tag_name_append(&tree->temp_tag_name, inc_buf->data, inc_buf->size); |
| 911 |
0 |
| tmp_len -= inc_buf->size; |
| 912 |
|
| } |
| 913 |
|
| else { |
| 914 |
0 |
| myhtml_tree_temp_tag_name_append(&tree->temp_tag_name, inc_buf->data, tmp_len); |
| 915 |
0 |
| break; |
| 916 |
|
| } |
| 917 |
|
| |
| 918 |
0 |
| inc_buf = inc_buf->next; |
| 919 |
|
| } |
| 920 |
|
| |
| 921 |
0 |
| return tree->temp_tag_name.data; |
| 922 |
|
| } |
| 923 |
|
| |
| 924 |
0 |
| const char * myhtml_tree_incomming_buf_make_data(myhtml_tree_t *tree, mythread_queue_node_t *qnode, size_t len) |
| 925 |
|
| { |
| 926 |
0 |
▶ | if(tree->incoming_buf->offset <= qnode->begin && |
Branch: 1 branch
| Branch | True | False | Total |
| if(tree->incoming_buf->offset <= qnode->begin && |
0 |
0 |
0 |
|
| 927 |
0 |
▶ | (len + qnode->begin) <= (tree->global_offset + tree->incoming_buf->size)) |
Branch: 1 branch
| Branch | True | False | Total |
| (len + qnode->begin) <= (tree->global_offset + tree->incoming_buf->size)) |
0 |
0 |
0 |
|
| 928 |
|
| { |
| 929 |
0 |
| return &tree->incoming_buf->data[ (qnode->begin - tree->incoming_buf->offset) ]; |
| 930 |
|
| } |
| 931 |
|
| |
| 932 |
0 |
▶ | if(tree->temp_tag_name.data == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(tree->temp_tag_name.data == NULL) |
0 |
0 |
0 |
|
| 933 |
0 |
| myhtml_tree_temp_tag_name_init(&tree->temp_tag_name); |
| 934 |
|
| else |
| 935 |
0 |
| myhtml_tree_temp_tag_name_clean(&tree->temp_tag_name); |
| 936 |
|
| |
| 937 |
0 |
| myhtml_incoming_buf_t *inc_buf = tree->incoming_buf; |
| 938 |
|
| |
| 939 |
0 |
▶ | if(inc_buf == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(inc_buf == NULL) |
0 |
0 |
0 |
|
| 940 |
0 |
| return NULL; |
| 941 |
|
| |
| 942 |
|
| // find original chunk |
| 943 |
0 |
▶ | while (inc_buf->offset > qnode->begin) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (inc_buf->offset > qnode->begin) { |
0 |
0 |
0 |
|
| 944 |
0 |
▶ | if(inc_buf->prev) |
Branch: 1 branch
| Branch | True | False | Total |
| if(inc_buf->prev) |
0 |
0 |
0 |
|
| 945 |
0 |
| inc_buf = inc_buf->prev; |
| 946 |
|
| else |
| 947 |
0 |
| break; |
| 948 |
|
| } |
| 949 |
|
| |
| 950 |
0 |
| size_t relative_current_buf_offset = qnode->begin - inc_buf->offset; |
| 951 |
|
| |
| 952 |
0 |
▶ | if((relative_current_buf_offset + len) <= inc_buf->size) { |
Branch: 1 branch
| Branch | True | False | Total |
| if((relative_current_buf_offset + len) <= inc_buf->size) { |
0 |
0 |
0 |
|
| 953 |
0 |
| return &inc_buf->data[relative_current_buf_offset]; |
| 954 |
|
| } |
| 955 |
|
| |
| 956 |
0 |
| size_t relative_how_buf_left = inc_buf->size - relative_current_buf_offset; |
| 957 |
0 |
| myhtml_tree_temp_tag_name_append(&tree->temp_tag_name, &inc_buf->data[relative_current_buf_offset], relative_how_buf_left); |
| 958 |
|
| |
| 959 |
0 |
| inc_buf = inc_buf->next; |
| 960 |
|
| |
| 961 |
0 |
▶ | while (inc_buf) |
Branch: 1 branch
| Branch | True | False | Total |
| while (inc_buf) |
0 |
0 |
0 |
|
| 962 |
|
| { |
| 963 |
0 |
▶ | if((len - relative_how_buf_left) <= inc_buf->size) { |
Branch: 1 branch
| Branch | True | False | Total |
| if((len - relative_how_buf_left) <= inc_buf->size) { |
0 |
0 |
0 |
|
| 964 |
0 |
| myhtml_tree_temp_tag_name_append(&tree->temp_tag_name, inc_buf->data, (len - relative_how_buf_left)); |
| 965 |
0 |
| break; |
| 966 |
|
| } |
| 967 |
|
| else { |
| 968 |
0 |
| relative_how_buf_left += inc_buf->size; |
| 969 |
0 |
| myhtml_tree_temp_tag_name_append(&tree->temp_tag_name, inc_buf->data, inc_buf->size); |
| 970 |
|
| } |
| 971 |
|
| |
| 972 |
0 |
| inc_buf = inc_buf->next; |
| 973 |
|
| } |
| 974 |
|
| |
| 975 |
0 |
| return tree->temp_tag_name.data; |
| 976 |
|
| } |
| 977 |
|
| |
| 978 |
|
| /* queue */ |
| 979 |
0 |
| void myhtml_queue_add(myhtml_tree_t *tree, const char *html, size_t begin, mythread_queue_node_t *qnode) |
| 980 |
|
| { |
| 981 |
|
| #ifndef MyHTML_BUILD_WITHOUT_THREADS |
| 982 |
|
| |
| 983 |
0 |
▶ | if(tree->flags & MyHTML_TREE_FLAGS_SINGLE_MODE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(tree->flags & MyHTML_TREE_FLAGS_SINGLE_MODE) { |
0 |
0 |
0 |
|
| 984 |
0 |
| myhtml_parser_worker(0, tree->current_qnode); |
| 985 |
0 |
▶ | while(myhtml_rules_tree_dispatcher(tree, tree->current_qnode->token)){}; |
Branch: 1 branch
| Branch | True | False | Total |
| while(myhtml_rules_tree_dispatcher(tree, tree->current_qnode->token)){}; |
0 |
0 |
0 |
|
| 986 |
|
| |
| 987 |
0 |
| tree->current_qnode = mythread_queue_node_malloc_limit(tree->myhtml->thread, tree->queue, html, (tree->global_offset + begin), 4, NULL); |
| 988 |
|
| } |
| 989 |
|
| else { |
| 990 |
0 |
| tree->current_qnode = mythread_queue_node_malloc_round(tree->myhtml->thread, tree->queue_entry, html, (tree->global_offset + begin), NULL); |
| 991 |
|
| } |
| 992 |
|
| |
| 993 |
|
| #else |
| 994 |
|
| |
| 995 |
|
| myhtml_parser_worker(0, tree->current_qnode); |
| 996 |
|
| while(myhtml_rules_tree_dispatcher(tree, tree->current_qnode->token)){}; |
| 997 |
|
| |
| 998 |
|
| tree->current_qnode = mythread_queue_node_malloc_limit(tree->myhtml->thread, tree->queue, html, (tree->global_offset + begin), 4, NULL); |
| 999 |
|
| |
| 1000 |
|
| #endif /* MyHTML_BUILD_WITHOUT_THREADS */ |
| 1001 |
|
| |
| 1002 |
0 |
| tree->current_qnode->tree = tree; |
| 1003 |
0 |
| tree->current_qnode->prev = qnode; |
| 1004 |
|
| |
| 1005 |
0 |
▶ | if(qnode) |
Branch: 1 branch
| Branch | True | False | Total |
| if(qnode) |
0 |
0 |
0 |
|
| 1006 |
0 |
| myhtml_tokenizer_calc_current_namespace(tree, qnode); |
| 1007 |
|
| |
| 1008 |
0 |
| myhtml_token_node_malloc(tree->token, tree->current_qnode->token, tree->token->mcasync_token_id); |
| 1009 |
0 |
| } |
| 1010 |
|
| |
| 1011 |
0 |
| bool myhtml_utils_strcmp(const char* ab, const char* to_lowercase, size_t size) |
| 1012 |
|
| { |
| 1013 |
0 |
| size_t i = 0; |
| 1014 |
|
| |
| 1015 |
|
| for(;;) { |
| 1016 |
0 |
▶ | if(i == size) |
Branch: 1 branch
| Branch | True | False | Total |
| if(i == size) |
0 |
0 |
0 |
|
| 1017 |
0 |
| return true; |
| 1018 |
|
| |
| 1019 |
0 |
▶ | if((const unsigned char)(to_lowercase[i] > 0x40 && to_lowercase[i] < 0x5b ? |
Branch: 2 branches
| Branch | True | False | Total |
| 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 |
|
| 1020 |
0 |
▶ | (to_lowercase[i]|0x60) : to_lowercase[i]) != (const unsigned char)ab[i]) |
Branch: 1 branch
| Branch | True | False | Total |
| (to_lowercase[i]|0x60) : to_lowercase[i]) != (const unsigned char)ab[i]) |
0 |
0 |
0 |
|
| 1021 |
|
| { |
| 1022 |
0 |
| return false; |
| 1023 |
|
| } |
| 1024 |
|
| |
| 1025 |
0 |
| i++; |
| 1026 |
|
| } |
| 1027 |
|
| |
| 1028 |
|
| return false; |
| 1029 |
|
| } |
| 1030 |
|
| |
| 1031 |
0 |
| bool myhtml_is_html_node(myhtml_tree_node_t *node, myhtml_tag_id_t tag_id) |
| 1032 |
|
| { |
| 1033 |
0 |
▶ | if(node == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(node == NULL) |
0 |
0 |
0 |
|
| 1034 |
0 |
| return false; |
| 1035 |
|
| |
| 1036 |
0 |
▶ | return node->tag_idx == tag_id && node->my_namespace == MyHTML_NAMESPACE_HTML; |
Branch: 2 branches
| Branch | True | False | Total |
| return node->tag_idx == tag_id && node->my_namespace == MyHTML_NAMESPACE_HTML; |
0 |
0 |
0 |
| return node->tag_idx == tag_id && node->my_namespace == MyHTML_NAMESPACE_HTML; |
0 |
0 |
0 |
|
| 1037 |
|
| } |
| 1038 |
|
| |