From 8e2e792b2c3e1fa04a0ac67ea7d9010939ca8009 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Mon, 13 Sep 2021 14:52:05 +0200 Subject: Removed most of the case-insensitive cstr methods, as they won't work with utf-8. --- docs/cstr_api.md | 9 +-------- examples/mapmap.c | 10 +++++----- include/stc/cstr.h | 40 +--------------------------------------- 3 files changed, 7 insertions(+), 52 deletions(-) diff --git a/docs/cstr_api.md b/docs/cstr_api.md index fd2b241f..b922092d 100644 --- a/docs/cstr_api.md +++ b/docs/cstr_api.md @@ -68,12 +68,6 @@ bool cstr_contains(cstr s, const char* needle); bool cstr_starts_with(cstr s, const char* str); bool cstr_ends_with(cstr s, const char* str); -bool cstr_iequalto(cstr s, const char* str); // prefix i = case-insensitive -size_t cstr_ifind_n(cstr s, const char* needle, size_t pos, size_t nmax); -bool cstr_icontains(cstr s, const char* needle); -bool cstr_istarts_with(cstr s, const char* str); -bool cstr_iends_with(cstr s, const char* str); - void cstr_push_back(cstr* self, char ch); void cstr_pop_back(cstr* self); char* cstr_front(cstr* self); @@ -99,9 +93,8 @@ int c_rawstr_compare(const char** x, const char** y); bool c_rawstr_equals(const char** x, const char** y); uint64_t c_rawstr_hash(const char* const* x, ...); -int c_strncasecmp(const char* str1, const char* str2, size_t n); char* c_strnstrn(const char* str, const char* needle, size_t slen, size_t nlen); -char* c_strncasestrn(const char* str, const char* needle, size_t slen, size_t nlen); +int c_strncasecmp(const char* str1, const char* str2, size_t n); ``` ## Types diff --git a/examples/mapmap.c b/examples/mapmap.c index b7dd8afb..b158b96a 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -18,10 +18,9 @@ int main(void) { c_forauto (cmap_cfg, cfg) { - cmap_str init = cmap_str_init(); - cmap_cfg_insert(&cfg, cstr_from("user"), init); - cmap_cfg_insert(&cfg, cstr_from("group"), init); - cmap_cfg_insert(&cfg, cstr_from("admin"), init); + cmap_cfg_insert(&cfg, cstr_from("user"), cmap_str_init()); + cmap_cfg_insert(&cfg, cstr_from("group"), cmap_str_init()); + cmap_cfg_insert(&cfg, cstr_from("admin"), cmap_str_init()); cmap_str_emplace(cmap_cfg_at(&cfg, "user"), "name", "Joe"); cmap_str_emplace(cmap_cfg_at(&cfg, "user"), "groups", "proj1,proj3"); @@ -34,6 +33,7 @@ int main(void) c_foreach (i, cmap_cfg, cfg) c_foreach (j, cmap_str, i.ref->second) - printf("%s: %s - %s (%u)\n", i.ref->first.str, j.ref->first.str, j.ref->second.str, i.ref->second.bucket_count); + printf("%s: %s - %s (%u)\n", i.ref->first.str, j.ref->first.str, j.ref->second.str, + i.ref->second.bucket_count); } } \ No newline at end of file diff --git a/include/stc/cstr.h b/include/stc/cstr.h index a14c4f72..681f38b1 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -62,12 +62,10 @@ STC_API void cstr_replace_all(cstr* self, const char* find, const cha STC_API void cstr_erase_n(cstr* self, size_t pos, size_t n); STC_API size_t cstr_find(cstr s, const char* needle); STC_API size_t cstr_find_n(cstr s, const char* needle, size_t pos, size_t nmax); -STC_API size_t cstr_ifind_n(cstr s, const char* needle, size_t pos, size_t nmax); STC_API bool cstr_getdelim(cstr *self, int delim, FILE *stream); -STC_API int c_strncasecmp(const char* s1, const char* s2, size_t nmax); STC_API char* c_strnstrn(const char* s, const char* needle, size_t slen, size_t nlen); -STC_API char* c_strncasestrn(const char* s, const char* needle, size_t slen, size_t nlen); +STC_API int c_strncasecmp(const char* s1, const char* s2, size_t nmax); STC_INLINE cstr cstr_init() { return cstr_null; } #define cstr_lit(literal) \ @@ -122,12 +120,8 @@ STC_INLINE bool cstr_equalto(cstr s, const char* str) { return strcmp(s.str, str) == 0; } STC_INLINE bool cstr_equalto_s(cstr s1, cstr s2) { return strcmp(s1.str, s2.str) == 0; } -STC_INLINE bool cstr_iequalto(cstr s, const char* str) - { return c_strncasecmp(s.str, str, cstr_npos) == 0; } STC_INLINE bool cstr_contains(cstr s, const char* needle) { return strstr(s.str, needle) != NULL; } -STC_INLINE bool cstr_icontains(cstr s, const char* needle) - { return c_strncasestrn(s.str, needle, cstr_size(s), strlen(needle)) != NULL; } STC_INLINE bool cstr_getline(cstr *self, FILE *stream) { return cstr_getdelim(self, '\n', stream); } @@ -172,18 +166,6 @@ cstr_ends_with(cstr s, const char* sub) { return n <= sz && !memcmp(s.str + sz - n, sub, n); } -STC_INLINE bool -cstr_istarts_with(cstr s, const char* sub) { - while (*sub && tolower(*s.str) == tolower(*sub)) ++s.str, ++sub; - return *sub == 0; -} - -STC_INLINE bool -cstr_iends_with(cstr s, const char* sub) { - size_t n = strlen(sub), sz = _cstr_rep(&s)->size; - return n <= sz && !c_strncasecmp(s.str + sz - n, sub, n); -} - /* container adaptor functions: */ #define cstr_toraw(xp) ((xp)->str) // deprecated #define cstr_compare(xp, yp) strcmp((xp)->str, (yp)->str) @@ -382,14 +364,6 @@ cstr_find_n(cstr s, const char* needle, size_t pos, size_t nmax) { return res ? res - s.str : cstr_npos; } -STC_DEF size_t -cstr_ifind_n(cstr s, const char* needle, size_t pos, size_t nmax) { - if (pos > _cstr_rep(&s)->size) return cstr_npos; - size_t nlen = strlen(needle); - char* res = c_strncasestrn(s.str + pos, needle, _cstr_rep(&s)->size - pos, nmax < nlen ? nmax : nlen); - return res ? res - s.str : cstr_npos; -} - STC_DEF int c_strncasecmp(const char* s1, const char* s2, size_t nmax) { int ret = 0; @@ -409,17 +383,5 @@ c_strnstrn(const char *s, const char *needle, size_t slen, size_t nlen) { return NULL; } -STC_DEF char* -c_strncasestrn(const char *s, const char *needle, size_t slen, size_t nlen) { - if (!nlen) return (char *)s; - if (nlen > slen) return NULL; - int c = tolower(*needle); slen -= nlen; - do { - if (tolower(*s) == c && !c_strncasecmp(s, needle, nlen)) return (char *)s; - ++s; - } while (slen--); - return NULL; -} - #endif #endif \ No newline at end of file -- cgit v1.2.3