htex

simple incorrect html parser
git clone git://git.relim.de/htex.git
Log | Files | Refs | README

commit f0e7578992f487aa0c587c9373aef11410a0b222
parent 84bd919821a741833491b484d1df0da8037e1750
Author: Robin <kroekerrobin@gmail.com>
Date:   Tue,  9 Apr 2024 09:19:26 +0200

Rename all variables starting with underscore

Diffstat:
Msrc/html.c | 40++++++++++++++++++++--------------------
Msrc/html.h | 12++++++------
2 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/src/html.c b/src/html.c @@ -421,21 +421,21 @@ static struct Tag *tag_init(void) tag->children = NULL; tag->attrs_len = 0; tag->children_len = 0; - tag->_is_void_element = false; - tag->_is_closed = false; - tag->_outer_html_begin_offset = 0; - tag->_outer_html_end_offset = 0; - tag->_inner_html_begin_offset = 0; - tag->_inner_html_end_offset = 0; + tag->is_void_element = false; + tag->is_closed = false; + tag->outer_html_begin_offset = 0; + tag->outer_html_end_offset = 0; + tag->inner_html_begin_offset = 0; + tag->inner_html_end_offset = 0; return tag; } static struct Tag *tag_close_last_unclosed(struct TagList *tag_list, const char *end_tag_name, size_t end_offset) { for (int i=tag_list->len-1; i>-1; i--) { - if (strcmp(tag_list->tags[i]->name, end_tag_name) == 0 && !tag_list->tags[i]->_is_closed) { - tag_list->tags[i]->_is_closed = true; - tag_list->tags[i]->_outer_html_end_offset = end_offset; + if (strcmp(tag_list->tags[i]->name, end_tag_name) == 0 && !tag_list->tags[i]->is_closed) { + tag_list->tags[i]->is_closed = true; + tag_list->tags[i]->outer_html_end_offset = end_offset; return tag_list->tags[i]; } } @@ -445,7 +445,7 @@ static struct Tag *tag_close_last_unclosed(struct TagList *tag_list, const char static struct Tag *tag_get_last_open(struct TagList *tag_list) { for (int i=tag_list->len-1; i>-1; i--) { - if (!tag_list->tags[i]->_is_void_element && !tag_list->tags[i]->_is_closed) { + if (!tag_list->tags[i]->is_void_element && !tag_list->tags[i]->is_closed) { return tag_list->tags[i]; } } @@ -456,7 +456,7 @@ static char *tag_get_outer_html(struct Tag *tag, char *text) { char *outer_html = NULL; int o = 0; - for (int i=tag->_outer_html_begin_offset; i<tag->_outer_html_end_offset; i++) { + for (int i=tag->outer_html_begin_offset; i<tag->outer_html_end_offset; i++) { outer_html = realloc(outer_html, (o+1) * sizeof(char)); outer_html[o] = text[i]; o++; @@ -470,7 +470,7 @@ static char *tag_get_inner_html(struct Tag *tag, char *text) { char *inner_html = NULL; int o = 0; - for (int i=tag->_inner_html_begin_offset; i<tag->_inner_html_end_offset; i++) { + for (int i=tag->inner_html_begin_offset; i<tag->inner_html_end_offset; i++) { inner_html = realloc(inner_html, (o+1) * sizeof(char)); inner_html[o] = text[i]; o++; @@ -482,10 +482,10 @@ static char *tag_get_inner_html(struct Tag *tag, char *text) static enum State tag_process_end_of_opening_tag(struct Tag *tag, size_t offset) { - tag->_inner_html_begin_offset = offset+1; - tag->_is_void_element = tag_is_void_element(tag); - if (tag->_is_void_element) - tag->_outer_html_end_offset = offset+1; + tag->inner_html_begin_offset = offset+1; + tag->is_void_element = tag_is_void_element(tag); + if (tag->is_void_element) + tag->outer_html_end_offset = offset+1; if (strcmp(tag->name, "script") == 0) return STATE_SCRIPT; else if (strcmp(tag->name, "style") == 0) @@ -498,7 +498,7 @@ static void tag_set_inner_html_end_offset(struct Tag *closed_tag, char *text, si int i = offset; while (text[i] != '<') i--; - closed_tag->_inner_html_end_offset = i; + closed_tag->inner_html_end_offset = i; } static void tag_free(struct Tag *tag) @@ -650,7 +650,7 @@ CLEANUP: static struct Tag *tag_parse(struct TagList *tag_list, char *text, size_t offset, enum State state) { struct Tag *tag = tag_init(); - tag->_outer_html_begin_offset= offset-1; + tag->outer_html_begin_offset= offset-1; tag_list->tags = realloc(tag_list->tags, (tag_list->len+1) * sizeof(struct Tag)); tag_list->tags[tag_list->len] = tag; tag_list->len++; @@ -1020,8 +1020,8 @@ void html_document_print_find_result(struct HTMLDocument *document, struct TagLi is_match = false; for (int k=0; k<found_tags->len; k++) { if ( - found_tags->tags[k]->_outer_html_begin_offset <= i && - found_tags->tags[k]->_outer_html_end_offset > i + found_tags->tags[k]->outer_html_begin_offset <= i && + found_tags->tags[k]->outer_html_end_offset > i ) is_match = true; } diff --git a/src/html.h b/src/html.h @@ -34,12 +34,12 @@ struct Tag { char *inner_text; size_t attrs_len; size_t children_len; - bool _is_void_element; // means there is no closing tag - bool _is_closed; - size_t _outer_html_begin_offset; - size_t _outer_html_end_offset; - size_t _inner_html_begin_offset; - size_t _inner_html_end_offset; + bool is_void_element; // means there is no closing tag + bool is_closed; + size_t outer_html_begin_offset; + size_t outer_html_end_offset; + size_t inner_html_begin_offset; + size_t inner_html_end_offset; }; struct TagList {