summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2019-03-23 11:11:47 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2019-03-23 11:11:47 (GMT)
commit1a523cb6c788fc46b234019f4198b865c4b5f502 (patch) (side-by-side diff)
treef9e0ee763a911564df16cb61d06a3145b79cf5d0
parent15b4ea89880ea674717e9fa64e146dd744e8e35c (diff)
downloadmailutils-1a523cb6c788fc46b234019f4198b865c4b5f502.tar.gz
mailutils-1a523cb6c788fc46b234019f4198b865c4b5f502.tar.bz2
Two new string functions
mu_string_prefix(A, B) returns true if B is the prefix of A. mu_string_suffix(A, B) returns true if B is the suffix of A. * include/mailutils/cstr.h (mu_string_prefix) (mu_string_suffix): protos. * libmailutils/string/Makefile.am: Add new files. * libmailutils/string/strpref.c: New file. * libmailutils/string/strsuf.c: New file.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/mailutils/cstr.h3
-rw-r--r--libmailutils/string/Makefile.am2
-rw-r--r--libmailutils/string/strpref.c12
-rw-r--r--libmailutils/string/strsuf.c13
4 files changed, 30 insertions, 0 deletions
diff --git a/include/mailutils/cstr.h b/include/mailutils/cstr.h
index a279422..4ef55be 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 1eb58de..5cdd739 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 0000000..43392ff
--- a/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 0000000..273d2f6
--- a/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;
+}

Return to:

Send suggestions and report system problems to the System administrator.