diff options
-rw-r--r-- | include/mailutils/cstr.h | 3 | ||||
-rw-r--r-- | libmailutils/string/Makefile.am | 2 | ||||
-rw-r--r-- | libmailutils/string/strpref.c | 12 | ||||
-rw-r--r-- | libmailutils/string/strsuf.c | 13 |
4 files changed, 30 insertions, 0 deletions
diff --git a/include/mailutils/cstr.h b/include/mailutils/cstr.h index a27942249..4ef55be89 100644 --- a/include/mailutils/cstr.h +++ b/include/mailutils/cstr.h @@ -31,6 +31,9 @@ int mu_c_strcasecmp (const char *a, const char *b); int mu_c_strncasecmp (const char *a, const char *b, size_t n); char *mu_c_strcasestr (const char *haystack, const char *needle); +int mu_string_prefix (char const *str, char const *pfx); +int mu_string_suffix (char const *str, char const *sfx); + size_t mu_rtrim_class (char *str, int __class); size_t mu_rtrim_cset (char *str, const char *cset); size_t mu_ltrim_class (char *str, int __class); diff --git a/libmailutils/string/Makefile.am b/libmailutils/string/Makefile.am index 1eb58dea4..5cdd73913 100644 --- a/libmailutils/string/Makefile.am +++ b/libmailutils/string/Makefile.am @@ -32,7 +32,9 @@ libstring_la_SOURCES = \ str_to_c.c\ strcount.c\ strltrim.c\ + strpref.c\ strskip.c\ + strsuf.c\ stripws.c\ strlst.c\ strrtrim.c\ diff --git a/libmailutils/string/strpref.c b/libmailutils/string/strpref.c new file mode 100644 index 000000000..43392ffa1 --- /dev/null +++ b/libmailutils/string/strpref.c @@ -0,0 +1,12 @@ +#include <config.h> +#include <string.h> +#include <mailutils/cstr.h> + +int +mu_string_prefix (char const *str, char const *pfx) +{ + size_t len = strlen (pfx); + if (strlen (str) < len) + return 0; + return memcmp (str, pfx, len) == 0; +} diff --git a/libmailutils/string/strsuf.c b/libmailutils/string/strsuf.c new file mode 100644 index 000000000..273d2f641 --- /dev/null +++ b/libmailutils/string/strsuf.c @@ -0,0 +1,13 @@ +#include <config.h> +#include <string.h> +#include <mailutils/cstr.h> + +int +mu_string_suffix (char const *str, char const *sfx) +{ + size_t sfxlen = strlen (sfx); + size_t len = strlen (str); + if (len < sfxlen) + return 0; + return memcmp (str + len - sfxlen, sfx, sfxlen) == 0; +} |