Provide str_numc(str, c)

This commit is contained in:
Stefan Rueger
2024-06-16 23:06:12 +01:00
parent d949c06c71
commit 693f5e60bd
2 changed files with 12 additions and 1 deletions

View File

@@ -1486,6 +1486,7 @@ const char *str_ccprintf(const char *fmt, ...)
;
const char *str_ccstrdup(const char *str);
char *str_fgets(FILE *fp, const char **errpp);
size_t str_numc(const char *str, char c);
char *str_lc(char *s);
char *str_uc(char *s);
char *str_lcfirst(char *s);

View File

@@ -77,7 +77,6 @@ int str_caseends(const char *str, const char *ends) {
return str_caseeq(str + str_len - ends_len, ends);
}
/*
* Match string against the partname pattern, returning 1 if it matches, 0 if
* not. Note: str_match_core() is a modified old copy of !fnmatch() from the
@@ -337,6 +336,17 @@ char *str_fgets(FILE *fp, const char **errpp) {
}
// Return the number of times a character c occurs in str
size_t str_numc(const char *str, char c) {
size_t ret = 0;
char is;
while((is = *str++))
if(is == c)
ret++;
return ret;
}
// Changes string to be all lowercase and returns original pointer
char *str_lc(char *s) {
for(char *t = s; *t; t++)