all repos — mgba @ 726986e4479a48322d15d40a9fba60fb6f6bf45c

mGBA Game Boy Advance Emulator

Util: Add startswith
Vicki Pfau vi@endrift.com
Sun, 05 Mar 2017 17:22:24 -0800
commit

726986e4479a48322d15d40a9fba60fb6f6bf45c

parent

000f232c582b0981b66d48d7af799e97faffad8e

2 files changed, 10 insertions(+), 0 deletions(-)

jump to
M include/mgba-util/string.hinclude/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.csrc/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;