aboutsummaryrefslogtreecommitdiff
path: root/src/HtmlSearch.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/HtmlSearch.c')
-rw-r--r--src/HtmlSearch.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/HtmlSearch.c b/src/HtmlSearch.c
index edb2a1c..45d8aa4 100644
--- a/src/HtmlSearch.c
+++ b/src/HtmlSearch.c
@@ -168,6 +168,8 @@ static int find_child_nodes(QuickMediaHtmlChildNode *node, const QuickMediaNodeS
if(!node)
return 0;
+ int match_index = 0;
+
/* We use two loops because we want to find children before grandchildren */
for(QuickMediaHtmlChildNode *child = node; child; child = child->next) {
/* A text node doesn't have a name */
@@ -194,7 +196,9 @@ static int find_child_nodes(QuickMediaHtmlChildNode *node, const QuickMediaNodeS
/* If we search without param, then it's a match */
if(!search_data->param.defined) {
- on_match();
+ if(search_data->param.index == -1 || search_data->param.index == match_index)
+ on_match();
+ ++match_index;
continue;
}
@@ -206,7 +210,9 @@ static int find_child_nodes(QuickMediaHtmlChildNode *node, const QuickMediaNodeS
assert(search_data->param.value.size > 0);
/* If the param value matches what we want to search for */
if(str_glob_match(child_attr->value, search_data->param.value, search_data->param.value_is_glob) == 0) {
- on_match();
+ if(search_data->param.index == -1 || search_data->param.index == match_index)
+ on_match();
+ ++match_index;
continue;
}
}
@@ -508,19 +514,12 @@ QuickMediaStringView quickmedia_html_node_get_text(QuickMediaMatchNode *self) {
}
int quickmedia_html_search_init(QuickMediaHtmlSearch *self, const char *html_source, size_t size) {
- /* Utf8 BOM */
- if(size >= 3 && memcmp(html_source, "\xef\xbb\xbf", 3) == 0) {
- html_source += 3;
- size -= 3;
- }
-
QuickMediaHtmlNode *html_node = &self->root_node;
html_node_init(html_node);
if(html_parser_parse(html_source, size, html_parse_callback, &html_node) != 0) {
quickmedia_html_search_deinit(self);
return 1;
}
-
return 0;
}