diff options
author | lexborisov <lex.borisov@gmail.com> | 2017-03-21 09:56:42 +0300 |
---|---|---|
committer | lexborisov <lex.borisov@gmail.com> | 2017-03-21 09:56:42 +0300 |
commit | 7024458c55c0baedfb29c2f9db213d3b0474c851 (patch) | |
tree | 7ec10676fc5a24bffed67d9f6f89ba14130ea781 /source/myhtml/token.c | |
parent | 0708dba577f51a9cb504db1feeb094aa9badd795 (diff) |
Merge branch 'master' into coverity_scancoverity_scan
Diffstat (limited to 'source/myhtml/token.c')
-rw-r--r-- | source/myhtml/token.c | 294 |
1 files changed, 96 insertions, 198 deletions
diff --git a/source/myhtml/token.c b/source/myhtml/token.c index 1536764..0828dfc 100644 --- a/source/myhtml/token.c +++ b/source/myhtml/token.c @@ -1,5 +1,5 @@ /* - Copyright (C) 2015-2016 Alexander Borisov + Copyright (C) 2015-2017 Alexander Borisov This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -102,7 +102,7 @@ myhtml_token_t * myhtml_token_create(myhtml_tree_t* tree, size_t size) if(size == 0) size = 4096; - myhtml_token_t* token = (myhtml_token_t*)myhtml_malloc(sizeof(myhtml_token_t)); + myhtml_token_t* token = (myhtml_token_t*)mycore_malloc(sizeof(myhtml_token_t)); if(token == NULL) return NULL; @@ -110,15 +110,15 @@ myhtml_token_t * myhtml_token_create(myhtml_tree_t* tree, size_t size) token->nodes_obj = mcobject_async_create(); if(token->nodes_obj == NULL) { - free(token); + mycore_free(token); return NULL; } token->attr_obj = mcobject_async_create(); if(token->attr_obj == NULL) { - free(token->nodes_obj); - free(token); + mycore_free(token->nodes_obj); + mycore_free(token); return NULL; } @@ -157,7 +157,7 @@ myhtml_token_t * myhtml_token_destroy(myhtml_token_t* token) if(token->attr_obj) token->attr_obj = mcobject_async_destroy(token->attr_obj, 1); - myhtml_free(token); + mycore_free(token); return NULL; } @@ -177,7 +177,7 @@ void myhtml_token_node_clean(myhtml_token_node_t* node) memset(node, 0, sizeof(myhtml_token_node_t)); node->type = MyHTML_TOKEN_TYPE_OPEN|MyHTML_TOKEN_TYPE_WHITESPACE; - myhtml_string_clean_all(&node->str); + mycore_string_clean_all(&node->str); } myhtml_token_attr_t * myhtml_token_attr_create(myhtml_token_t* token, size_t async_node_id) @@ -195,8 +195,8 @@ void myhtml_token_attr_clean(myhtml_token_attr_t* attr) memset(attr, 0, sizeof(myhtml_token_attr_t)); attr->ns = MyHTML_NAMESPACE_HTML; - myhtml_string_clean_all(&attr->key); - myhtml_string_clean_all(&attr->value); + mycore_string_clean_all(&attr->key); + mycore_string_clean_all(&attr->value); } myhtml_tag_id_t myhtml_token_node_tag_id(myhtml_token_node_t *token_node) @@ -238,7 +238,7 @@ const char * myhtml_token_node_text(myhtml_token_node_t *token_node, size_t *len return token_node->str.data; } -myhtml_string_t * myhtml_token_node_string(myhtml_token_node_t *token_node) +mycore_string_t * myhtml_token_node_string(myhtml_token_node_t *token_node) { return &token_node->str; } @@ -253,16 +253,18 @@ bool myhtml_token_node_is_close_self(myhtml_token_node_t *token_node) return (token_node->type & MyHTML_TOKEN_TYPE_CLOSE_SELF); } -void myhtml_token_node_wait_for_done(myhtml_token_node_t* node) +void myhtml_token_node_wait_for_done(myhtml_token_t* token, myhtml_token_node_t* node) { -#ifndef MyHTML_BUILD_WITHOUT_THREADS - - const struct timespec timeout = {0, 0}; - while((node->type & MyHTML_TOKEN_TYPE_DONE) == 0) {myhtml_thread_nanosleep(&timeout);} - +#ifndef MyCORE_BUILD_WITHOUT_THREADS + while((node->type & MyHTML_TOKEN_TYPE_DONE) == 0) {mythread_nanosleep_sleep(token->tree->myhtml->thread_stream->timespec);} #endif } +void myhtml_token_set_done(myhtml_token_node_t* node) +{ + node->type |= MyHTML_TOKEN_TYPE_DONE; +} + myhtml_token_node_t * myhtml_token_node_clone(myhtml_token_t* token, myhtml_token_node_t* node, size_t token_thread_idx, size_t attr_thread_idx) { if(node == NULL) @@ -283,7 +285,7 @@ myhtml_token_node_t * myhtml_token_node_clone(myhtml_token_t* token, myhtml_toke new_node->element_begin = node->element_begin; new_node->element_length = node->element_length; - myhtml_string_init(tree->mchar, tree->mchar_node_id, &new_node->str, node->str.size); + mycore_string_init(tree->mchar, tree->mchar_node_id, &new_node->str, node->str.size); myhtml_token_node_attr_copy(token, node, new_node, attr_thread_idx); return new_node; @@ -291,10 +293,10 @@ myhtml_token_node_t * myhtml_token_node_clone(myhtml_token_t* token, myhtml_toke void myhtml_token_node_text_append(myhtml_token_t* token, myhtml_token_node_t* dest, const char* text, size_t text_len) { - myhtml_string_init(token->tree->mchar, token->tree->mchar_node_id, &dest->str, (text_len + 2)); + mycore_string_init(token->tree->mchar, token->tree->mchar_node_id, &dest->str, (text_len + 2)); - myhtml_string_t* string = &dest->str; - myhtml_string_append(string, text, text_len); + mycore_string_t* string = &dest->str; + mycore_string_append(string, text, text_len); } myhtml_token_attr_t * myhtml_token_node_attr_append(myhtml_token_t* token, myhtml_token_node_t* dest, @@ -305,18 +307,18 @@ myhtml_token_attr_t * myhtml_token_node_attr_append(myhtml_token_t* token, myhtm new_attr->next = 0; if(key_len) { - myhtml_string_init(token->tree->mchar, token->tree->mchar_node_id, &new_attr->key, (key_len + 1)); - myhtml_string_append_lowercase(&new_attr->key, key, key_len); + mycore_string_init(token->tree->mchar, token->tree->mchar_node_id, &new_attr->key, (key_len + 1)); + mycore_string_append_lowercase(&new_attr->key, key, key_len); } else - myhtml_string_clean_all(&new_attr->key); + mycore_string_clean_all(&new_attr->key); if(value_len) { - myhtml_string_init(token->tree->mchar, token->tree->mchar_node_id, &new_attr->value, (value_len + 1)); - myhtml_string_append(&new_attr->value, value, value_len); + mycore_string_init(token->tree->mchar, token->tree->mchar_node_id, &new_attr->value, (value_len + 1)); + mycore_string_append(&new_attr->value, value, value_len); } else - myhtml_string_clean_all(&new_attr->value); + mycore_string_clean_all(&new_attr->value); if(dest->attr_first == NULL) { new_attr->prev = 0; @@ -339,32 +341,32 @@ myhtml_token_attr_t * myhtml_token_node_attr_append(myhtml_token_t* token, myhtm myhtml_token_attr_t * myhtml_token_node_attr_append_with_convert_encoding(myhtml_token_t* token, myhtml_token_node_t* dest, const char* key, size_t key_len, const char* value, size_t value_len, - size_t thread_idx, myhtml_encoding_t encoding) + size_t thread_idx, myencoding_t encoding) { myhtml_token_attr_t* new_attr = mcobject_async_malloc(token->attr_obj, thread_idx, NULL); new_attr->next = 0; if(key_len) { - myhtml_string_init(token->tree->mchar, token->tree->mchar_node_id, &new_attr->key, (key_len + 1)); + mycore_string_init(token->tree->mchar, token->tree->mchar_node_id, &new_attr->key, (key_len + 1)); - if(encoding == MyHTML_ENCODING_UTF_8) - myhtml_string_append_lowercase(&new_attr->key, key, key_len); + if(encoding == MyENCODING_UTF_8) + mycore_string_append_lowercase(&new_attr->key, key, key_len); else - myhtml_string_append_lowercase_ascii_with_convert_encoding(&new_attr->key, key, key_len, encoding); + myencoding_string_append_lowercase_ascii(&new_attr->key, key, key_len, encoding); } else - myhtml_string_clean_all(&new_attr->key); + mycore_string_clean_all(&new_attr->key); if(value_len) { - myhtml_string_init(token->tree->mchar, token->tree->mchar_node_id, &new_attr->value, (value_len + 1)); + mycore_string_init(token->tree->mchar, token->tree->mchar_node_id, &new_attr->value, (value_len + 1)); - if(encoding == MyHTML_ENCODING_UTF_8) - myhtml_string_append(&new_attr->value, value, value_len); + if(encoding == MyENCODING_UTF_8) + mycore_string_append(&new_attr->value, value, value_len); else - myhtml_string_append_with_convert_encoding(&new_attr->value, value, value_len, encoding); + myencoding_string_append(&new_attr->value, value, value_len, encoding); } else - myhtml_string_clean_all(&new_attr->value); + mycore_string_clean_all(&new_attr->value); if(dest->attr_first == NULL) { new_attr->prev = 0; @@ -415,18 +417,18 @@ bool myhtml_token_attr_copy(myhtml_token_t* token, myhtml_token_attr_t* attr, my new_attr->next = 0; if(attr->key.length) { - myhtml_string_init(token->tree->mchar, token->tree->mchar_node_id, &new_attr->key, (attr->key.length + 1)); - myhtml_string_append_lowercase(&new_attr->key, attr->key.data, attr->key.length); + mycore_string_init(token->tree->mchar, token->tree->mchar_node_id, &new_attr->key, (attr->key.length + 1)); + mycore_string_append_lowercase(&new_attr->key, attr->key.data, attr->key.length); } else - myhtml_string_clean_all(&new_attr->key); + mycore_string_clean_all(&new_attr->key); if(attr->value.length) { - myhtml_string_init(token->tree->mchar, token->tree->mchar_node_id, &new_attr->value, (attr->value.length + 1)); - myhtml_string_append(&new_attr->value, attr->value.data, attr->value.length); + mycore_string_init(token->tree->mchar, token->tree->mchar_node_id, &new_attr->value, (attr->value.length + 1)); + mycore_string_append(&new_attr->value, attr->value.data, attr->value.length); } else - myhtml_string_clean_all(&new_attr->value); + mycore_string_clean_all(&new_attr->value); if(dest->attr_first == NULL) { new_attr->prev = 0; @@ -455,8 +457,8 @@ myhtml_token_attr_t * myhtml_token_attr_match(myhtml_token_t* token, myhtml_toke { if(attr->key.length == key_size && attr->value.length == value_size) { - if((myhtml_strcmp(attr->key.data, key) == 0)) { - if((myhtml_strcmp(attr->value.data, value) == 0)) + if((mycore_strcmp(attr->key.data, key) == 0)) { + if((mycore_strcmp(attr->value.data, value) == 0)) return attr; else return NULL; @@ -478,8 +480,8 @@ myhtml_token_attr_t * myhtml_token_attr_match_case(myhtml_token_t* token, myhtml { if(attr->key.length == key_size && attr->value.length == value_size) { - if((myhtml_strcmp(attr->key.data, key) == 0)) { - if((myhtml_strcasecmp(attr->value.data, value) == 0)) + if((mycore_strcmp(attr->key.data, key) == 0)) { + if((mycore_strcasecmp(attr->value.data, value) == 0)) return attr; else return NULL; @@ -504,7 +506,7 @@ void myhtml_token_adjust_mathml_attributes(myhtml_token_node_t* target) void _myhtml_token_create_copy_srt(myhtml_token_t* token, const char* from, size_t from_size, char** to) { *to = mchar_async_malloc(token->tree->mchar, token->tree->mchar_node_id, (from_size + 2)); - myhtml_string_raw_copy(*to, from, from_size); + mycore_string_raw_copy(*to, from, from_size); } void myhtml_token_strict_doctype_by_token(myhtml_token_t* token, myhtml_token_node_t* target, myhtml_tree_doctype_t* return_doctype) @@ -514,7 +516,7 @@ void myhtml_token_strict_doctype_by_token(myhtml_token_t* token, myhtml_token_no if(attr && attr->key.length) { _myhtml_token_create_copy_srt(token, attr->key.data, attr->key.length, &return_doctype->attr_name); - if(myhtml_strcmp("html", return_doctype->attr_name)) + if(mycore_strcmp("html", return_doctype->attr_name)) return_doctype->is_html = false; else return_doctype->is_html = true; @@ -525,11 +527,11 @@ void myhtml_token_strict_doctype_by_token(myhtml_token_t* token, myhtml_token_no _myhtml_token_create_copy_srt(token, "\0", 1, &return_doctype->attr_name); if(return_doctype->attr_public) - myhtml_free(return_doctype->attr_public); + mycore_free(return_doctype->attr_public); return_doctype->attr_public = NULL; if(return_doctype->attr_system) - myhtml_free(return_doctype->attr_system); + mycore_free(return_doctype->attr_system); return_doctype->attr_system = NULL; return; @@ -539,7 +541,7 @@ void myhtml_token_strict_doctype_by_token(myhtml_token_t* token, myhtml_token_no if(attr && attr->value.length) { - if(myhtml_strcasecmp(attr->value.data, "PUBLIC") == 0) + if(mycore_strcasecmp(attr->value.data, "PUBLIC") == 0) { // try see public attr = attr->next; @@ -554,22 +556,22 @@ void myhtml_token_strict_doctype_by_token(myhtml_token_t* token, myhtml_token_no _myhtml_token_create_copy_srt(token, attr->value.data, attr->value.length, &return_doctype->attr_system); else { if(return_doctype->attr_system) - myhtml_free(return_doctype->attr_system); + mycore_free(return_doctype->attr_system); _myhtml_token_create_copy_srt(token, "\0", 1, &return_doctype->attr_system); } } else { if(return_doctype->attr_public) - myhtml_free(return_doctype->attr_public); + mycore_free(return_doctype->attr_public); return_doctype->attr_public = NULL; if(return_doctype->attr_system) - myhtml_free(return_doctype->attr_system); + mycore_free(return_doctype->attr_system); return_doctype->attr_system = NULL; } } - else if(myhtml_strncasecmp(attr->value.data, "SYSTEM", attr->value.length) == 0) + else if(mycore_strncasecmp(attr->value.data, "SYSTEM", attr->value.length) == 0) { attr = attr->next; @@ -579,21 +581,21 @@ void myhtml_token_strict_doctype_by_token(myhtml_token_t* token, myhtml_token_no } else { if(return_doctype->attr_public) - myhtml_free(return_doctype->attr_public); + mycore_free(return_doctype->attr_public); return_doctype->attr_public = NULL; if(return_doctype->attr_system) - myhtml_free(return_doctype->attr_system); + mycore_free(return_doctype->attr_system); return_doctype->attr_system = NULL; } } else { if(return_doctype->attr_public) - myhtml_free(return_doctype->attr_public); + mycore_free(return_doctype->attr_public); return_doctype->attr_public = NULL; if(return_doctype->attr_system) - myhtml_free(return_doctype->attr_system); + mycore_free(return_doctype->attr_system); return_doctype->attr_system = NULL; } } @@ -601,14 +603,14 @@ void myhtml_token_strict_doctype_by_token(myhtml_token_t* token, myhtml_token_no bool myhtml_token_doctype_check_html_4_0(myhtml_tree_doctype_t* return_doctype) { - return myhtml_strcmp(return_doctype->attr_public, "-//W3C//DTD HTML 4.0//EN") && - (return_doctype->attr_system == NULL || myhtml_strcmp(return_doctype->attr_system, "http://www.w3.org/TR/REC-html40/strict.dtd")); + return mycore_strcmp(return_doctype->attr_public, "-//W3C//DTD HTML 4.0//EN") && + (return_doctype->attr_system == NULL || mycore_strcmp(return_doctype->attr_system, "http://www.w3.org/TR/REC-html40/strict.dtd")); } bool myhtml_token_doctype_check_html_4_01(myhtml_tree_doctype_t* return_doctype) { - return myhtml_strcmp(return_doctype->attr_public, "-//W3C//DTD HTML 4.01//EN") && - (return_doctype->attr_system == NULL || myhtml_strcmp(return_doctype->attr_system, "http://www.w3.org/TR/html4/strict.dtd")); + return mycore_strcmp(return_doctype->attr_public, "-//W3C//DTD HTML 4.01//EN") && + (return_doctype->attr_system == NULL || mycore_strcmp(return_doctype->attr_system, "http://www.w3.org/TR/html4/strict.dtd")); } bool myhtml_token_doctype_check_xhtml_1_0(myhtml_tree_doctype_t* return_doctype) @@ -616,8 +618,8 @@ bool myhtml_token_doctype_check_xhtml_1_0(myhtml_tree_doctype_t* return_doctype) if(return_doctype->attr_system == NULL) return true; - return myhtml_strcmp(return_doctype->attr_public, "-//W3C//DTD XHTML 1.0 Strict//EN") && - myhtml_strcmp(return_doctype->attr_system, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"); + return mycore_strcmp(return_doctype->attr_public, "-//W3C//DTD XHTML 1.0 Strict//EN") && + mycore_strcmp(return_doctype->attr_system, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"); } bool myhtml_token_doctype_check_xhtml_1_1(myhtml_tree_doctype_t* return_doctype) @@ -625,8 +627,8 @@ bool myhtml_token_doctype_check_xhtml_1_1(myhtml_tree_doctype_t* return_doctype) if(return_doctype->attr_system == NULL) return true; - return myhtml_strcmp(return_doctype->attr_public, "-//W3C//DTD XHTML 1.1//EN") && - myhtml_strcmp(return_doctype->attr_system, "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"); + return mycore_strcmp(return_doctype->attr_public, "-//W3C//DTD XHTML 1.1//EN") && + mycore_strcmp(return_doctype->attr_system, "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"); } bool myhtml_token_release_and_check_doctype_attributes(myhtml_token_t* token, myhtml_token_node_t* target, myhtml_tree_doctype_t* return_doctype) @@ -641,7 +643,7 @@ bool myhtml_token_release_and_check_doctype_attributes(myhtml_token_t* token, my if((return_doctype->is_html || return_doctype->attr_public || - (return_doctype->attr_system && myhtml_strcmp(return_doctype->attr_system, "about:legacy-compat")))) + (return_doctype->attr_system && mycore_strcmp(return_doctype->attr_system, "about:legacy-compat")))) { if(return_doctype->attr_public == NULL) return false; @@ -669,8 +671,8 @@ void myhtml_token_adjust_svg_attributes(myhtml_token_node_t* target) myhtml_token_attr_svg_replacement[i].from_size); if(attr) { - myhtml_string_clean(&attr->key); - myhtml_string_append(&attr->key, myhtml_token_attr_svg_replacement[i].to, + mycore_string_clean(&attr->key); + mycore_string_append(&attr->key, myhtml_token_attr_svg_replacement[i].to, myhtml_token_attr_svg_replacement[i].to_size); } } @@ -686,8 +688,8 @@ void myhtml_token_adjust_foreign_attributes(myhtml_token_node_t* target) myhtml_token_attr_namespace_replacement[i].from_size); if(attr) { - myhtml_string_clean(&attr->key); - myhtml_string_append(&attr->key, myhtml_token_attr_namespace_replacement[i].to, + mycore_string_clean(&attr->key); + mycore_string_append(&attr->key, myhtml_token_attr_namespace_replacement[i].to, myhtml_token_attr_namespace_replacement[i].to_size); attr->ns = myhtml_token_attr_namespace_replacement[i].ns; @@ -708,10 +710,10 @@ bool myhtml_token_attr_compare(myhtml_token_node_t* target, myhtml_token_node_t* if(target_attr->key.length == dest_attr->key.length && target_attr->value.length == dest_attr->value.length) { - if(myhtml_strcmp(target_attr->key.data, dest_attr->key.data) != 0) + if(mycore_strcmp(target_attr->key.data, dest_attr->key.data) != 0) break; - if(myhtml_strcasecmp(target_attr->value.data, dest_attr->value.data) != 0) + if(mycore_strcasecmp(target_attr->value.data, dest_attr->value.data) != 0) break; } else @@ -734,7 +736,7 @@ myhtml_token_attr_t * myhtml_token_attr_by_name(myhtml_token_node_t* node, const while (attr) { if(name_length == attr->key.length) { - if(myhtml_strcmp(attr->key.data, name) == 0) + if(mycore_strcmp(attr->key.data, name) == 0) break; } @@ -803,11 +805,11 @@ myhtml_token_attr_t * myhtml_token_attr_remove_by_name(myhtml_token_node_t* node myhtml_token_node_t * myhtml_token_merged_two_token_string(myhtml_tree_t* tree, myhtml_token_node_t* token_to, myhtml_token_node_t* token_from, bool cp_reverse) { - myhtml_token_node_wait_for_done(token_to); - myhtml_token_node_wait_for_done(token_from); + myhtml_token_node_wait_for_done(tree->token, token_to); + myhtml_token_node_wait_for_done(tree->token, token_from); - myhtml_string_t *string1 = &token_to->str; - myhtml_string_t *string2 = &token_from->str; + mycore_string_t *string1 = &token_to->str; + mycore_string_t *string2 = &token_from->str; token_to->raw_begin = 0; token_to->raw_length = 0; @@ -815,10 +817,10 @@ myhtml_token_node_t * myhtml_token_merged_two_token_string(myhtml_tree_t* tree, if(token_to->str.node_idx == tree->mchar_node_id) { if(cp_reverse) { - //myhtml_string_copy(string2, &string_base); + //mycore_string_copy(string2, &string_base); } else { - myhtml_string_copy(string1, string2); + mycore_string_copy(string1, string2); } return token_to; @@ -826,25 +828,25 @@ myhtml_token_node_t * myhtml_token_merged_two_token_string(myhtml_tree_t* tree, if(token_from->str.node_idx == tree->mchar_node_id) { if(cp_reverse) { - myhtml_string_copy(string2, string1); + mycore_string_copy(string2, string1); } else { - myhtml_string_copy(string1, string2); + mycore_string_copy(string1, string2); } return token_from; } else { - myhtml_string_t string_base; - myhtml_string_init(tree->mchar, tree->mchar_node_id, &string_base, (string1->length + string2->length + 2)); + mycore_string_t string_base; + mycore_string_init(tree->mchar, tree->mchar_node_id, &string_base, (string1->length + string2->length + 2)); if(cp_reverse) { - myhtml_string_copy(&string_base, string2); - myhtml_string_copy(&string_base, string1); + mycore_string_copy(&string_base, string2); + mycore_string_copy(&string_base, string1); } else { - myhtml_string_copy(&string_base, string1); - myhtml_string_copy(&string_base, string2); + mycore_string_copy(&string_base, string1); + mycore_string_copy(&string_base, string2); } token_to->str = string_base; @@ -855,117 +857,13 @@ myhtml_token_node_t * myhtml_token_merged_two_token_string(myhtml_tree_t* tree, void myhtml_token_set_replacement_character_for_null_token(myhtml_tree_t* tree, myhtml_token_node_t* node) { - myhtml_token_node_wait_for_done(node); + myhtml_token_node_wait_for_done(tree->token, node); - myhtml_string_t new_str; - myhtml_string_init(tree->mchar, tree->mchar_node_id, &new_str, (node->str.length + 2)); + mycore_string_t new_str; + mycore_string_init(tree->mchar, tree->mchar_node_id, &new_str, (node->str.length + 2)); - myhtml_string_append_with_replacement_null_characters_only(&new_str, node->str.data, node->str.length); + mycore_string_append_with_replacement_null_characters(&new_str, node->str.data, node->str.length); node->str = new_str; } -void myhtml_token_set_done(myhtml_token_node_t* node) -{ - node->type |= MyHTML_TOKEN_TYPE_DONE; -} - -void myhtml_token_print_param_by_idx(myhtml_tree_t* myhtml_tree, myhtml_token_node_t* node, FILE* out) -{ - if(node->type & MyHTML_TOKEN_TYPE_CLOSE) { - fprintf(out, "</"); - } - else { - fprintf(out, "<"); - } - - fprintf(out, "tag_id=%zu; body_begin=%zu; body_length=%zu; attr_first=%zu; attr_last=%zu", - node->tag_id, node->raw_begin, node->raw_length, - (size_t)node->attr_first, (size_t)node->attr_last); - - if(node->type & MyHTML_TOKEN_TYPE_CLOSE_SELF) { - fprintf(out, " />\n"); - } - else { - fprintf(out, ">\n"); - } -} - -void myhtml_token_print_by_idx(myhtml_tree_t* tree, myhtml_token_node_t* node, FILE* out) -{ - const myhtml_tag_context_t *ctx = myhtml_tag_get_by_id(tree->tags, node->tag_id); - - if(node->tag_id == MyHTML_TAG__TEXT || - node->tag_id == MyHTML_TAG__COMMENT) - { - if(node->str.length) { - fprintf(out, "%.*s: %.*s\n", (int)ctx->name_length, ctx->name, - (int)node->str.length, node->str.data); - } - else { - fprintf(out, "%.*s is empty\n", (int)ctx->name_length, ctx->name); - } - } - else - { - if(node->type & MyHTML_TOKEN_TYPE_CLOSE) { - fprintf(out, "</"); - } - else { - fprintf(out, "<"); - } - - fprintf(out, "%.*s tagid=\"%zu\"", (int)ctx->name_length, ctx->name, node->tag_id); - - myhtml_token_print_attr(tree, node, out); - - if(node->type & MyHTML_TOKEN_TYPE_CLOSE_SELF) { - fprintf(out, " />\n"); - } - else { - fprintf(out, ">\n"); - } - } -} - -void myhtml_token_print_attr(myhtml_tree_t* tree, myhtml_token_node_t* node, FILE* out) -{ - myhtml_token_attr_t* attr = node->attr_first; - - while(attr) - { - fprintf(out, " %s", attr->key.data); - - if(attr->ns != MyHTML_NAMESPACE_HTML) - { - switch (attr->ns) { - case MyHTML_NAMESPACE_SVG: - fprintf(out, ":svg"); - break; - case MyHTML_NAMESPACE_MATHML: - fprintf(out, ":math"); - break; - case MyHTML_NAMESPACE_XLINK: - fprintf(out, ":xlink"); - break; - case MyHTML_NAMESPACE_XML: - fprintf(out, ":xml"); - break; - case MyHTML_NAMESPACE_XMLNS: - fprintf(out, ":xmlns"); - break; - default: - fprintf(out, ":UNDEF"); - break; - } - } - - if(attr->value.length) { - fprintf(out, "=\"%s\"", attr->value.data); - } - - attr = attr->next; - } -} - - |