Skip to content

Commit

Permalink
lib/filterx: implement includes function
Browse files Browse the repository at this point in the history
Signed-off-by: Szilard Parrag <[email protected]>
  • Loading branch information
OverOrion committed Sep 23, 2024
1 parent dedc132 commit 39c601f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/filterx/func-str.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#define FILTERX_FUNC_ENDSWITH_USAGE "Usage: endswith(string, suffix, ignorecase=true)" \
"or endswith(string, [suffix_1, suffix_2, ..], ignorecase=true)"

#define FILTERX_FUNC_INCLUDES_USAGE "Usage: includes(string, substring, ignorecase=true)" \
"or includes(string, [substring_1, substring_2, ..], ignorecase=true)"

typedef struct _FilterXStringWithCache
{
FilterXExpr *expr;
Expand Down Expand Up @@ -513,3 +516,18 @@ filterx_function_endswith_new(FilterXFunctionArgs *args, GError **error)
return filterx_function_affix_new(args, "endswith", filterx_function_endswith_process, FILTERX_FUNC_ENDSWITH_USAGE,
error);
}

gboolean
filterx_function_includes_process(const gchar *haystack, gsize haystack_len, const gchar *needle, gsize needle_len)
{
if (needle_len > haystack_len)
return FALSE;
return g_strstr_len(haystack, haystack_len, needle) != NULL;
}

FilterXExpr *
filterx_function_includes_new(FilterXFunctionArgs *args, GError **error)
{
return filterx_function_affix_new(args, "includes", filterx_function_includes_process, FILTERX_FUNC_INCLUDES_USAGE,
error);
}
1 change: 1 addition & 0 deletions lib/filterx/func-str.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@

FilterXExpr *filterx_function_startswith_new(FilterXFunctionArgs *args, GError **error);
FilterXExpr *filterx_function_endswith_new(FilterXFunctionArgs *args, GError **error);
FilterXExpr *filterx_function_includes_new(FilterXFunctionArgs *args, GError **error);

#endif

0 comments on commit 39c601f

Please sign in to comment.