Util: Add startswith
Vicki Pfau vi@endrift.com
Sun, 05 Mar 2017 17:22:24 -0800
2 files changed,
10 insertions(+),
0 deletions(-)
M
include/mgba-util/string.h
→
include/mgba-util/string.h
@@ -21,6 +21,7 @@ #endif
char* strnrstr(const char* restrict s1, const char* restrict s2, size_t len); bool endswith(const char* restrict s1, const char* restrict end); +bool startswith(const char* restrict s1, const char* restrict start); size_t toUtf8(uint32_t unichar, char* buffer); int utfcmp(const uint16_t* utf16, const char* utf8, size_t utf16Length, size_t utf8Length);
M
src/util/string.c
→
src/util/string.c
@@ -48,6 +48,15 @@ }
return strcmp(&s1[len - endLen], end) == 0; } +bool startswith(const char* restrict s1, const char* restrict start) { + size_t len = strlen(s1); + size_t startLen = strlen(start); + if (len < startLen) { + return false; + } + return strncmp(s1, start, startLen) == 0; +} + uint32_t utf16Char(const uint16_t** unicode, size_t* length) { if (*length < 2) { *length = 0;