From 053259c5e9b869f2e5b3aaacbe9fabaaaf55c135 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 15 May 2024 22:32:58 +0200 Subject: Append --- src/HtmlSearch.c | 109 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 53 deletions(-) diff --git a/src/HtmlSearch.c b/src/HtmlSearch.c index 7d5c5c5..eb41fd1 100644 --- a/src/HtmlSearch.c +++ b/src/HtmlSearch.c @@ -70,11 +70,66 @@ static char string_view_char_or(const QuickMediaStringView *str, size_t index, c return fallback; } +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); +} + /* Returns 0 on match */ -static int str_glob_match(const QuickMediaStringView str, const QuickMediaStringView glob, int is_glob) { +static int str_glob_match(QuickMediaStringView str, QuickMediaStringView glob, int is_glob) { size_t str_index = 0; size_t glob_index = 0; + strip(str.data, str.size, &str.data, &str.size, is_whitespace); + strip(glob.data, glob.size, &glob.data, &glob.size, is_whitespace); + if(!is_glob) { if(glob.size == str.size && memcmp(str.data, glob.data, str.size) == 0) return 0; @@ -142,58 +197,6 @@ static char to_upper(char c) { return c; } -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 string_views_equal_case_insensitive_strip(QuickMediaStringView str1, QuickMediaStringView str2) { if(str2.size != str1.size) return 1; -- cgit v1.2.3