diff options
| author | Tyge Løvset <[email protected]> | 2020-11-24 13:28:33 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-11-24 13:28:33 +0100 |
| commit | 623066503a9226fd437c49e57be7199df0a0a2c8 (patch) | |
| tree | ce5bf19eb895c52a2d658c87a0daec4408dd393b | |
| parent | 02dee6ce206368adc6dbd43985eafd29bcd273ea (diff) | |
| download | STC-modified-623066503a9226fd437c49e57be7199df0a0a2c8.tar.gz STC-modified-623066503a9226fd437c49e57be7199df0a0a2c8.zip | |
Added case insensitive compare: c_strcasecmp(), cstr_casecmp(), cstr_equals_caseins().
| -rw-r--r-- | stc/cstr.h | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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) {
|
