Util: Add endswith
Jeffrey Pfau jeffrey@endrift.com
Tue, 23 Aug 2016 09:08:46 -0700
3 files changed,
11 insertions(+),
0 deletions(-)
M
src/util/string.c
→
src/util/string.c
@@ -39,6 +39,15 @@ }
return last; } +bool endswith(const char* restrict s1, const char* restrict end) { + size_t len = strlen(s1); + size_t endLen = strlen(end); + if (len < endLen) { + return false; + } + return strcmp(&s1[len - endLen], end) == 0; +} + uint32_t utf16Char(const uint16_t** unicode, size_t* length) { if (*length < 2) { *length = 0;
M
src/util/string.h
→
src/util/string.h
@@ -18,6 +18,7 @@ char* strdup(const char* str);
#endif char* strnrstr(const char* restrict s1, const char* restrict s2, size_t len); +bool endswith(const char* restrict s1, const char* restrict end); size_t toUtf8(uint32_t unichar, char* buffer); int utfcmp(const uint16_t* utf16, const char* utf8, size_t utf16Length, size_t utf8Length);