Provide str_is_in_list()

This commit is contained in:
Stefan Rueger
2024-06-25 01:25:33 +01:00
parent 9a834c37c7
commit 76353b8218
2 changed files with 9 additions and 0 deletions

View File

@@ -1474,6 +1474,7 @@ int str_casematch(const char *pattern, const char *string);
int str_matched_by(const char *string, const char *pattern);
int str_casematched_by(const char *string, const char *pattern);
int str_is_pattern(const char *str);
int str_is_in_list(const char *s, const char **l, size_t nl, int (*f)(const char *, const char*));
char *str_sprintf(const char *fmt, ...)
#if defined(__GNUC__) // Ask gcc to check whether format and parameters match
__attribute__ ((format (printf, 1, 2)))

View File

@@ -228,6 +228,14 @@ int str_is_pattern(const char *str) {
}
}
// Is the string s in the list l of strings as matched by f(s, l[i])?
int str_is_in_list(const char *s, const char **l, size_t nl, int (*f)(const char *, const char*)) {
for(size_t i=0; i<nl; i++)
if(f(s, l[i]))
return 1;
return 0;
}
// Return a mmt_malloc'd string with the sprintf() result
char *str_sprintf(const char *fmt, ...) {
int size = 0;