]> mj.ucw.cz Git - libucw.git/blob - ucw/string.c
195976978a4e369e78ee00263961af141d4c0ee5
[libucw.git] / ucw / string.c
1 /*
2  *      UCW Library -- String Routines
3  *
4  *      (c) 2006 Pavel Charvat <pchar@ucw.cz>
5  *      (c) 2007--2008 Martin Mares <mj@ucw.cz>
6  *
7  *      This software may be freely distributed and used according to the terms
8  *      of the GNU Lesser General Public License.
9  */
10
11 #undef LOCAL_DEBUG
12
13 #include "ucw/lib.h"
14 #include "ucw/string.h"
15
16 char *
17 str_format_flags(char *dest, const char *fmt, uns flags)
18 {
19   char *start = dest;
20   for (uns i=0; fmt[i]; i++)
21     {
22       if (flags & (1 << i))
23         *dest++ = fmt[i];
24       else
25         *dest++ = '-';
26     }
27   *dest = 0;
28   return start;
29 }
30
31 uns
32 str_count_char(const char *str, uns chr)
33 {
34   const byte *s = str;
35   uns i = 0;
36   while (*s)
37     if (*s++ == chr)
38       i++;
39   return i;
40 }