diff --git a/core/src/strutil.c b/core/src/strutil.c index ef74370..ffc698b 100644 --- a/core/src/strutil.c +++ b/core/src/strutil.c @@ -30,6 +30,13 @@ long strfirst(const char* begin, const char* end, char search) { return -1; } +long strcount(const char* begin, const char* end, char search) { + long count = 0; + for(;begin < end && *begin != '\0'; ++begin) + if(*begin == search) ++count; + return count; +} + long strfirst_pred(const char* begin, const char* end, CharPredFn pred) { const char* itr = begin; while(itr != end) diff --git a/core/src/strutil.h b/core/src/strutil.h index 1c43021..ae8592a 100644 --- a/core/src/strutil.h +++ b/core/src/strutil.h @@ -10,6 +10,7 @@ extern uintptr_t strnhash(const char* s, size_t n); extern uintptr_t strhash(const char* s); extern long strlast(const char* rbegin, const char* rend, char search); extern long strfirst(const char* begin, const char* end, char search); +extern long strcount(const char* begin, const char* end, char search); extern long strfirst_pred(const char* begin, const char* end, CharPredFn pred); extern long strlast_pred(const char* rbegin, const char* rend, CharPredFn pred);