util/StringUtil: add StringAfterPrefix()

This commit is contained in:
Max Kellermann
2015-10-16 19:15:30 +02:00
parent 85f58eb082
commit 607c2c5ba2
4 changed files with 49 additions and 0 deletions

View File

@@ -18,6 +18,7 @@
*/
#include "StringUtil.hxx"
#include "StringAPI.hxx"
#include "CharUtil.hxx"
#include "ASCII.hxx"
@@ -44,6 +45,21 @@ StringEndsWith(const char *haystack, const char *needle)
needle, needle_length) == 0;
}
const char *
StringAfterPrefix(const char *string, const char *prefix)
{
#if !CLANG_CHECK_VERSION(3,6)
/* disabled on clang due to -Wtautological-pointer-compare */
assert(string != nullptr);
assert(prefix != nullptr);
#endif
size_t prefix_length = strlen(prefix);
return StringIsEqual(string, prefix, prefix_length)
? string + prefix_length
: nullptr;
}
const char *
FindStringSuffix(const char *p, const char *suffix)
{