aboutsummaryrefslogtreecommitdiffstats
path: root/src/util/StringUtil.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-03-02 22:26:46 +0100
committerMax Kellermann <max@duempel.org>2015-03-03 11:29:31 +0100
commit820debf45a3bc5567fc16a4f982bdf41df7d7ef2 (patch)
treec5a83325ebabf0079609c8976c89f59a08909685 /src/util/StringUtil.cxx
parentc19292c036ecc8791ad985968638baa76b7f0d3c (diff)
downloadmpd-820debf45a3bc5567fc16a4f982bdf41df7d7ef2.tar.gz
mpd-820debf45a3bc5567fc16a4f982bdf41df7d7ef2.tar.xz
mpd-820debf45a3bc5567fc16a4f982bdf41df7d7ef2.zip
util/StringUtil: add FindStringSuffix()
Diffstat (limited to 'src/util/StringUtil.cxx')
-rw-r--r--src/util/StringUtil.cxx15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/util/StringUtil.cxx b/src/util/StringUtil.cxx
index 4d538989f..107354b6e 100644
--- a/src/util/StringUtil.cxx
+++ b/src/util/StringUtil.cxx
@@ -96,6 +96,21 @@ StringEndsWith(const char *haystack, const char *needle)
needle, needle_length) == 0;
}
+const char *
+FindStringSuffix(const char *p, const char *suffix)
+{
+ const size_t p_length = strlen(p);
+ const size_t suffix_length = strlen(suffix);
+
+ if (p_length < suffix_length)
+ return nullptr;
+
+ const char *q = p + p_length - suffix_length;
+ return memcmp(q, suffix, suffix_length) == 0
+ ? q
+ : nullptr;
+}
+
char *
CopyString(char *gcc_restrict dest, const char *gcc_restrict src, size_t size)
{