From 41206f68eb257e788a2d038e25f01d9deb7d37af Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 3 Jul 2021 00:18:06 +0200 Subject: Strip whitespace for attribute values as well --- src/HtmlSearch.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/HtmlSearch.c b/src/HtmlSearch.c index 89ee326..03d7e3a 100644 --- a/src/HtmlSearch.c +++ b/src/HtmlSearch.c @@ -329,22 +329,6 @@ static int html_parse_callback(HtmlParser *html_parser, HtmlParseType parse_type return 0; } -QuickMediaStringView quickmedia_html_node_get_attribute_value(QuickMediaMatchNode *self, const char *attribute_name) { - QuickMediaStringView attr_name; - attr_name.data = attribute_name; - attr_name.size = strlen(attribute_name); - - QuickMediaHtmlAttribute *attr = get_attribute_by_name(self->node, attr_name); - if(attr) { - return attr->value; - } else { - QuickMediaStringView attr_value; - attr_value.data = NULL; - attr_value.size = 0; - return attr_value; - } -} - static int is_whitespace(int c) { switch(c) { case ' ': @@ -384,6 +368,24 @@ static void strip(const char *str, size_t size, const char **output_str, size_t rstrip(*output_str, *output_size, output_size, strip_filter_func); } +QuickMediaStringView quickmedia_html_node_get_attribute_value(QuickMediaMatchNode *self, const char *attribute_name) { + QuickMediaStringView attr_name; + attr_name.data = attribute_name; + attr_name.size = strlen(attribute_name); + + QuickMediaHtmlAttribute *attr = get_attribute_by_name(self->node, 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; + } else { + QuickMediaStringView attr_value; + attr_value.data = NULL; + attr_value.size = 0; + return attr_value; + } +} + static int merge_inner_text(QuickMediaHtmlNode *node, QuickMediaString *str) { if(node->is_tag) { int newline = 0; -- cgit v1.2.3