aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/HtmlSearch.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/HtmlSearch.c b/src/HtmlSearch.c
index ebf2e4a..edb2a1c 100644
--- a/src/HtmlSearch.c
+++ b/src/HtmlSearch.c
@@ -90,11 +90,14 @@ static int str_glob_match(const QuickMediaStringView str, const QuickMediaString
return 1;
}
+ size_t prev_str_index = 0;
+ size_t prev_glob_index = 0;
+ char next_glob_c = '\0';
for(;;) {
char glob_c = string_view_char_or(&glob, glob_index, '\0');
if(glob_c == '*') {
glob_index += find_first_not_char(glob.data + glob_index, glob.size - glob_index, '*');
- char next_glob_c = string_view_char_or(&glob, glob_index, '\0');
+ next_glob_c = string_view_char_or(&glob, glob_index, '\0');
if(next_glob_c == '\0')
return 0;
@@ -102,19 +105,30 @@ static int str_glob_match(const QuickMediaStringView str, const QuickMediaString
if(!s_p)
return 1;
- const size_t new_str_index = (const char*)s_p - (str.data + str_index);
- str_index = new_str_index;
+ str_index = (const char*)s_p - str.data;
+ prev_str_index = str_index;
+ prev_glob_index = glob_index;
} else {
char str_c = string_view_char_or(&str, str_index, '\0');
- if(str_c != glob_c)
- return 1;
+ if(str_c != glob_c) {
+ str_index = prev_str_index + 1;
+ glob_index = prev_glob_index;
+
+ const void *s_p = memchr(str.data + str_index, next_glob_c, str.size - str_index);
+ if(!s_p)
+ return 1;
+
+ str_index = (const char*)s_p - str.data;
+ prev_str_index = str_index;
+ continue;
+ }
if(str_c == '\0')
return 0;
- }
- ++str_index;
- ++glob_index;
+ ++str_index;
+ ++glob_index;
+ }
}
assert(0); /* shouldn't happen */