Util: Add endswith

This commit is contained in:
Jeffrey Pfau 2016-08-23 09:08:46 -07:00
parent b442282650
commit f491196bc4
3 changed files with 11 additions and 0 deletions

View File

@ -74,6 +74,7 @@ Misc:
- Qt: Make reseting when pasued frame-accurate - Qt: Make reseting when pasued frame-accurate
- GBA Video: Optimize compositing cases slightly - GBA Video: Optimize compositing cases slightly
- VFS: Improve zip file detection - VFS: Improve zip file detection
- Util: Add endswith
0.4.1: (2016-07-11) 0.4.1: (2016-07-11)
Bugfixes: Bugfixes:

View File

@ -39,6 +39,15 @@ char* strnrstr(const char* restrict haystack, const char* restrict needle, size_
return last; 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) { uint32_t utf16Char(const uint16_t** unicode, size_t* length) {
if (*length < 2) { if (*length < 2) {
*length = 0; *length = 0;

View File

@ -18,6 +18,7 @@ char* strdup(const char* str);
#endif #endif
char* strnrstr(const char* restrict s1, const char* restrict s2, size_t len); 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); size_t toUtf8(uint32_t unichar, char* buffer);
int utfcmp(const uint16_t* utf16, const char* utf8, size_t utf16Length, size_t utf8Length); int utfcmp(const uint16_t* utf16, const char* utf8, size_t utf16Length, size_t utf8Length);