2 * UCW Library -- String Routines
4 * (c) 2006 Pavel Charvat <pchar@ucw.cz>
5 * (c) 2007--2012 Martin Mares <mj@ucw.cz>
7 * This software may be freely distributed and used according to the terms
8 * of the GNU Lesser General Public License.
14 #include "ucw/string.h"
20 strnlen(const char *str, uns n)
22 const char *end = str + n;
24 for (c = str; *c && c < end; c++);
30 str_format_flags(char *dest, const char *fmt, uns flags)
33 for (uns i=0; fmt[i]; i++)
45 str_count_char(const char *str, uns chr)
56 str_starts_with(const char *haystack, const char *needle)
59 if (*haystack++ != *needle++)
65 str_ends_with(const char *haystack, const char *needle)
67 int hlen = strlen(haystack);
68 int nlen = strlen(needle);
72 return !memcmp(haystack + hlen - nlen, needle, nlen);