aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-08-15 20:38:32 +0200
committerdec05eba <dec05eba@protonmail.com>2021-08-15 20:38:32 +0200
commit4a0955b851d087d9e97634ae2b7d2f76b0fe0503 (patch)
tree00ff4c595ace4d57b2bcf9c43ff08b3db8320cdd
parenta87880a43c06e9475b59e6c7741c695b4e41b20c (diff)
Fix glob match
-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 */