From: Martin Mares Date: Tue, 22 Jul 2008 10:13:19 +0000 (+0200) Subject: Libucw: Added str_count_char(). X-Git-Tag: holmes-import~374 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=f18211c316437c9cdefb3366699f4b575f3aa4d7;p=libucw.git Libucw: Added str_count_char(). --- 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 */