From 14665143f973d5dbcdab34de439bdd37a56d0e5f Mon Sep 17 00:00:00 2001 From: Ralph Corderoy Date: Sun, 23 Oct 2016 12:02:55 +0100 Subject: [PATCH] utils.c: Add HasPrefix(s, prefix). HasPrefix returns true if non-NULL s starts with non-NULL prefix. --- h/utils.h | 1 + sbr/utils.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/h/utils.h b/h/utils.h index 0ce68a7e..47ae59f0 100644 --- a/h/utils.h +++ b/h/utils.h @@ -63,6 +63,7 @@ char *find_str (const char [], size_t, const char *); char *rfind_str (const char [], size_t, const char *); char *nmh_strcasestr (const char *, const char *); +bool HasPrefix(const char *s, const char *prefix); bool HasSuffixC(char *s, int c); void TrimSuffixC(char *s, int c); void ToLower(char *s); diff --git a/sbr/utils.c b/sbr/utils.c index d8a43c17..a6f0e111 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -358,6 +358,18 @@ nmh_strcasestr (const char *s1, const char *s2) { } +/* HasPrefix returns true if non-NULL s starts with non-NULL prefix. */ +bool HasPrefix(const char *s, const char *prefix) +{ + while (*s && *s == *prefix) { + s++; + prefix++; + } + + return *prefix == '\0'; +} + + /* HasSuffixC returns true if non-NULL string s ends with a c before the * terminating NUL. */ bool HasSuffixC(char *s, int c) -- 2.56.0