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) { if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { myhtml_tree_clean(tree); } if(tag_id == 0) tag_id = MyHTML_TAG_DIV; if(ns == 0) ns = MyHTML_NAMESPACE_HTML; tree->flags |= MyHTML_TREE_FLAGS_SINGLE_MODE; if(myhtml_tokenizer_fragment_init(tree, tag_id, ns) == NULL) return MyHTML_STATUS_TOKENIZER_ERROR_FRAGMENT_INIT; myhtml_encoding_set(tree, encoding); mystatus_t status = myhtml_tokenizer_begin(tree, html, html_size); if(status) return status; return myhtml_tokenizer_end(tree); }
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) { if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { myhtml_tree_clean(tree); mythread_queue_clean(tree->queue); mythread_clean(tree->myhtml->thread); } if(tag_id == 0) tag_id = MyHTML_TAG_DIV; if(my_namespace == 0) my_namespace = MyHTML_NAMESPACE_HTML; tree->flags |= MyHTML_TREE_FLAGS_SINGLE_MODE; myhtml_tokenizer_fragment_init(tree, tag_id, my_namespace); myhtml_encoding_set(tree, encoding); myhtml_tokenizer_begin(tree, html, html_size); myhtml_tokenizer_end(tree); return MyHTML_STATUS_OK; }
myhtml_status_t myhtml_parse(myhtml_tree_t* tree, myhtml_encoding_t encoding, const char* html, size_t html_size) { if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { myhtml_tree_clean(tree); } myhtml_encoding_set(tree, encoding); myhtml_tokenizer_begin(tree, html, html_size); myhtml_tokenizer_end(tree); return MyHTML_STATUS_OK; }
void chunk_test(void) { struct res_html res = load_html("/new/C-git/myhtml/test/html/chunk.data"); //struct res_html res = load_html("/new/C-git/myhtml/test/broken.html"); myhtml_t* myhtml = myhtml_create(); myhtml_init(myhtml, MyHTML_OPTIONS_DEFAULT, 1, 0); myhtml_tree_t* tree = myhtml_tree_create(); myhtml_tree_init(tree, myhtml); myhtml_encoding_set(tree, MyHTML_ENCODING_UTF_8); size_t begin = 0, i = 0; while (i < res.size) { if(res.html[i] == '\n') { //printf("Parse chunk: %.*s\n", (int)(i - begin), &res.html[begin]); myhtml_parse_chunk(tree, &res.html[begin], (i - begin)); myhtml_tokenizer_wait(tree); begin = i + 1; } i++; } myhtml_parse_chunk(tree, &res.html[begin], (i - begin)); myhtml_parse_chunk_end(tree); i = 0; while (i < res.size) { if(res.html[i] != '\n') { printf("%c", res.html[i]); } i++; } printf("\n"); myhtml_tree_print_node_childs(tree, tree->document, stdout, 0); myhtml_tree_destroy(tree); myhtml_destroy(myhtml); free(res.html); }
mystatus_t myhtml_parse_single(myhtml_tree_t* tree, myencoding_t encoding, const char* html, size_t html_size) { if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { myhtml_tree_clean(tree); } tree->flags |= MyHTML_TREE_FLAGS_SINGLE_MODE; myhtml_encoding_set(tree, encoding); mystatus_t status = myhtml_tokenizer_begin(tree, html, html_size); if(status) return status; return myhtml_tokenizer_end(tree); }
myhtml_status_t myhtml_parse_single(myhtml_tree_t* tree, myhtml_encoding_t encoding, const char* html, size_t html_size) { if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { myhtml_tree_clean(tree); mythread_queue_clean(tree->queue); mythread_clean(tree->myhtml->thread); } tree->flags |= MyHTML_TREE_FLAGS_SINGLE_MODE; myhtml_encoding_set(tree, encoding); myhtml_tokenizer_begin(tree, html, html_size); myhtml_tokenizer_end(tree); return MyHTML_STATUS_OK; }