From f18211c316437c9cdefb3366699f4b575f3aa4d7 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 22 Jul 2008 12:13:19 +0200 Subject: [PATCH] Libucw: Added str_count_char(). --- ucw/string.c | 13 ++++++++++++- ucw/string.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ucw/string.c b/ucw/string.c index c235292a..19597697 100644 --- a/ucw/string.c +++ b/ucw/string.c @@ -2,7 +2,7 @@ * UCW Library -- String Routines * * (c) 2006 Pavel Charvat - * (c) 2007 Martin Mares + * (c) 2007--2008 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -27,3 +27,14 @@ str_format_flags(char *dest, const char *fmt, uns flags) *dest = 0; return start; } + +uns +str_count_char(const char *str, uns chr) +{ + const byte *s = str; + uns i = 0; + while (*s) + if (*s++ == chr) + i++; + return i; +} diff --git a/ucw/string.h b/ucw/string.h index ffcf8fb4..f96bd023 100644 --- a/ucw/string.h +++ b/ucw/string.h @@ -14,6 +14,7 @@ /* string.c */ char *str_format_flags(char *dest, const char *fmt, uns flags); +uns str_count_char(const char *str, uns chr); /* str-esc.c */ -- 2.39.5