aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/HtmlSearch.c120
1 files changed, 57 insertions, 63 deletions
diff --git a/src/HtmlSearch.c b/src/HtmlSearch.c
index adf64bd..4ae27af 100644
--- a/src/HtmlSearch.c
+++ b/src/HtmlSearch.c
@@ -331,58 +331,6 @@ void html_node_child_deinit(QuickMediaHtmlChildNode *self) {
html_node_deinit(&self->node);
}
-static int is_whitespace(int c) {
- switch(c) {
- case ' ':
- case '\n':
- case '\r':
- case '\t':
- case '\v':
- return 1;
- default:
- return 0;
- }
-}
-
-static int is_newline(int c) {
- return c == '\n' || c == '\r';
-}
-
-static void lstrip(const char *str, size_t size, const char **output_str, size_t *output_size, int(*strip_filter_func)(int)) {
- if(size == 0) {
- *output_str = str;
- *output_size = size;
- return;
- }
-
- size_t i = 0;
- while(i < size && strip_filter_func(str[i])) {
- ++i;
- }
-
- *output_str = str + i;
- *output_size = size - i;
-}
-
-static void rstrip(const char *str, size_t size, size_t *output_size, int(*strip_filter_func)(int)) {
- if(size == 0) {
- *output_size = size;
- return;
- }
-
- ssize_t i = size - 1;
- while(i >= 0 && strip_filter_func(str[i])) {
- --i;
- }
-
- *output_size = i + 1;
-}
-
-static void strip(const char *str, size_t size, const char **output_str, size_t *output_size, int(*strip_filter_func)(int)) {
- lstrip(str, size, output_str, output_size, strip_filter_func);
- rstrip(*output_str, *output_size, output_size, strip_filter_func);
-}
-
static int html_parse_callback(HtmlParser *html_parser, HtmlParseType parse_type, void *userdata) {
QuickMediaHtmlNode **html_node_p = userdata;
QuickMediaHtmlNode *html_node = *html_node_p;
@@ -404,11 +352,7 @@ static int html_parse_callback(HtmlParser *html_parser, HtmlParseType parse_type
break;
}
case HTML_PARSE_ATTRIBUTE: {
- HtmlStringView attr_key = html_parser->attribute_key;
- HtmlStringView attr_value = html_parser->attribute_value;
- strip(attr_key.data, attr_key.size, &attr_key.data, &attr_key.size, is_whitespace);
- strip(attr_value.data, attr_value.size, &attr_value.data, &attr_value.size, is_whitespace);
- if(html_node_add_attribute(html_node, attr_key, attr_value) != 0)
+ if(html_node_add_attribute(html_node, html_parser->attribute_key, html_parser->attribute_value) != 0)
return 1;
break;
}
@@ -439,9 +383,7 @@ QuickMediaStringView quickmedia_html_node_get_attribute_value(QuickMediaHtmlNode
QuickMediaHtmlAttribute *attr = get_attribute_by_name(self, attr_name);
if(attr) {
- QuickMediaStringView attr_value = attr->value;
- strip(attr_value.data, attr_value.size, &attr_value.data, &attr_value.size, is_whitespace);
- return attr_value;
+ return attr->value;
} else {
QuickMediaStringView attr_value;
attr_value.data = NULL;
@@ -467,20 +409,72 @@ QuickMediaHtmlNode* quickmedia_html_node_find_child(QuickMediaHtmlNode *self, co
if(!child->node.is_tag)
continue;
- if(!string_views_equal_case_insensitive(child->node.name, tag))
+ if(string_views_equal_case_insensitive(child->node.name, tag) != 0)
continue;
- QuickMediaHtmlAttribute *attr = get_attribute_by_name(child, attr_name);
+ QuickMediaHtmlAttribute *attr = get_attribute_by_name(&child->node, attr_name);
if(!attr)
continue;
- if(string_views_equal_case_insensitive(attr->value, attr_value))
+ if(string_views_equal_case_insensitive(attr->value, attr_value) == 0)
return &child->node;
}
return NULL;
}
+static int is_whitespace(int c) {
+ switch(c) {
+ case ' ':
+ case '\n':
+ case '\r':
+ case '\t':
+ case '\v':
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+static int is_newline(int c) {
+ return c == '\n' || c == '\r';
+}
+
+static void lstrip(const char *str, size_t size, const char **output_str, size_t *output_size, int(*strip_filter_func)(int)) {
+ if(size == 0) {
+ *output_str = str;
+ *output_size = size;
+ return;
+ }
+
+ size_t i = 0;
+ while(i < size && strip_filter_func(str[i])) {
+ ++i;
+ }
+
+ *output_str = str + i;
+ *output_size = size - i;
+}
+
+static void rstrip(const char *str, size_t size, size_t *output_size, int(*strip_filter_func)(int)) {
+ if(size == 0) {
+ *output_size = size;
+ return;
+ }
+
+ ssize_t i = size - 1;
+ while(i >= 0 && strip_filter_func(str[i])) {
+ --i;
+ }
+
+ *output_size = i + 1;
+}
+
+static void strip(const char *str, size_t size, const char **output_str, size_t *output_size, int(*strip_filter_func)(int)) {
+ lstrip(str, size, output_str, output_size, strip_filter_func);
+ rstrip(*output_str, *output_size, output_size, strip_filter_func);
+}
+
static int merge_inner_text(QuickMediaHtmlNode *node, QuickMediaString *str) {
if(node->is_tag) {
int newline = 0;