1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-06 22:10:53 +00:00

[libdom] Added add_lowercase_to_string

Replace uppercase with lowercase in tag names in html "rewrites"
This commit is contained in:
Witold Filipczyk 2024-05-08 15:27:48 +02:00
parent a9ae51ae9f
commit abc307e86b
4 changed files with 24 additions and 4 deletions

View File

@ -85,3 +85,22 @@ free_document(void *doc)
dom_node *ddd = (dom_node *)doc;
dom_node_unref(ddd);
}
void
add_lowercase_to_string(struct string *buf, const char *str, int len)
{
char *tmp = memacpy(str, len);
int i;
if (!tmp) {
return;
}
for (i = 0; i < len; i++) {
if (tmp[i] >= 'A' && tmp[i] <= 'Z') {
tmp[i] += 32;
}
}
add_bytes_to_string(buf, tmp, len);
mem_free(tmp);
}

View File

@ -12,6 +12,7 @@ void *document_parse_text(const char *charset, char *data, size_t length);
void *document_parse(struct document *document, struct string *source);
void free_document(void *doc);
void *el_match_selector(const char *selector, void *node);
void add_lowercase_to_string(struct string *buf, const char *str, int len);
#ifdef __cplusplus
}

View File

@ -51,7 +51,7 @@ dump_dom_element_closing(struct string *buf, dom_node *node)
/* Get string data and print element name */
add_to_string(buf, "</");
add_bytes_to_string(buf, dom_string_data(node_name), dom_string_byte_length(node_name));
add_lowercase_to_string(buf, dom_string_data(node_name), dom_string_byte_length(node_name));
add_char_to_string(buf, '>');
/* Finished with the node_name dom_string */
@ -146,7 +146,7 @@ dump_dom_element(void *mapa, struct string *buf, dom_node *node, int depth)
save_in_map(mapa, node, buf->length);
/* Get string data and print element name */
add_bytes_to_string(buf, dom_string_data(node_name), dom_string_byte_length(node_name));
add_lowercase_to_string(buf, dom_string_data(node_name), dom_string_byte_length(node_name));
exc = dom_node_get_attributes(node, &attrs);

View File

@ -60,7 +60,7 @@ dump_dom_element_closing(struct string *buf, dom_node *node)
if (strcmp(dom_string_data(node_name), "BR")) {
add_to_string(buf, "</");
add_bytes_to_string(buf, dom_string_data(node_name), dom_string_byte_length(node_name));
add_lowercase_to_string(buf, dom_string_data(node_name), dom_string_byte_length(node_name));
add_char_to_string(buf, '>');
}
@ -169,7 +169,7 @@ dump_dom_element(void *mapa, void *mapa_rev, struct string *buf, dom_node *node,
save_offset_in_map(mapa_rev, node, buf->length);
/* Get string data and print element name */
add_bytes_to_string(buf, dom_string_data(node_name), dom_string_byte_length(node_name));
add_lowercase_to_string(buf, dom_string_data(node_name), dom_string_byte_length(node_name));
if (strcmp(dom_string_data(node_name), "BR") == 0) {
add_char_to_string(buf, '/');