From 623066503a9226fd437c49e57be7199df0a0a2c8 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 24 Nov 2020 13:28:33 +0100 Subject: Added case insensitive compare: c_strcasecmp(), cstr_casecmp(), cstr_equals_caseins(). --- stc/cstr.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/stc/cstr.h b/stc/cstr.h index 4f701c33..a083c807 100644 --- a/stc/cstr.h +++ b/stc/cstr.h @@ -173,11 +173,22 @@ cstr_getline(cstr_t *self, FILE *stream) { STC_INLINE size_t cstr_length(cstr_t s) { return cstr_size(s); } +STC_INLINE int +c_strcasecmp(const char* s1, const char* s2) { + while (*s1 && tolower(*s1) == tolower(*s2)) + ++s1, ++s2; + return tolower(*s1) - tolower(*s2); +} + STC_INLINE bool cstr_equals(cstr_t s1, const char* str) { return strcmp(s1.str, str) == 0; } STC_INLINE bool +cstr_equals_caseins(cstr_t s1, const char* str) { + return c_strcasecmp(s1.str, str) == 0; +} +STC_INLINE bool cstr_equals_s(cstr_t s1, cstr_t s2) { return strcmp(s1.str, s2.str) == 0; } @@ -185,6 +196,10 @@ STC_INLINE int cstr_compare(const cstr_t *s1, const cstr_t *s2) { return strcmp(s1->str, s2->str); } +STC_INLINE int +cstr_casecmp(const cstr_t *s1, const cstr_t *s2) { + return c_strcasecmp(s1->str, s2->str); +} STC_INLINE size_t cstr_find(cstr_t s, const char* needle) { -- cgit v1.2.3