Util/StringUtil: add StringStartsWith()

Replaces GLib's g_str_has_prefix().
This commit is contained in:
Max Kellermann
2013-11-28 18:48:35 +01:00
parent a788b7e747
commit af4133e3c9
16 changed files with 68 additions and 60 deletions

View File

@@ -22,6 +22,7 @@
#include "ASCII.hxx"
#include <assert.h>
#include <string.h>
const char *
strchug_fast(const char *p)
@@ -32,6 +33,13 @@ strchug_fast(const char *p)
return p;
}
bool
StringStartsWith(const char *haystack, const char *needle)
{
const size_t length = strlen(needle);
return memcmp(haystack, needle, length) == 0;
}
bool
string_array_contains(const char *const* haystack, const char *needle)
{

View File

@@ -40,6 +40,10 @@ strchug_fast(char *p)
return const_cast<char *>(strchug_fast((const char *)p));
}
gcc_pure
bool
StringStartsWith(const char *haystack, const char *needle);
/**
* Checks whether a string array contains the specified string.
*