From 606108f4093becae19dcef16b39beee0360ae9e8 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 24 Jul 2021 14:05:29 +0300 Subject: [PATCH] spa: add spa_strstartswith --- spa/include/spa/utils/string.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spa/include/spa/utils/string.h b/spa/include/spa/utils/string.h index a41d07936..01597f78a 100644 --- a/spa/include/spa/utils/string.h +++ b/spa/include/spa/utils/string.h @@ -63,6 +63,22 @@ static inline bool spa_strneq(const char *s1, const char *s2, size_t len) } +/** + * \return true if \a s starts with the \a prefix or false otherwise. + * A \a s is NULL, it never starts with the given \a prefix. A \a prefix of + * NULL is a bug in the caller. + */ +static inline bool spa_strstartswith(const char *s, const char *prefix) +{ + if (SPA_UNLIKELY(s == NULL)) + return false; + + spa_assert(prefix); + + return strncmp(s, prefix, strlen(prefix)) == 0; +} + + /** * \return true if \a s ends with the \a suffix or false otherwise. * A \a s is NULL, it never ends with the given \a suffix. A \a suffix of