* UCW Library -- String Routines
*
* (c) 2006 Pavel Charvat <pchar@ucw.cz>
- * (c) 2007--2008 Martin Mares <mj@ucw.cz>
+ * (c) 2007--2012 Martin Mares <mj@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
#include "ucw/lib.h"
#include "ucw/string.h"
+#include <string.h>
+
#ifdef CONFIG_DARWIN
uns
strnlen(const char *str, uns n)
i++;
return i;
}
+
+int
+str_starts_with(const char *haystack, const char *needle)
+{
+ while (*needle)
+ if (*haystack++ != *needle++)
+ return 0;
+ return 1;
+}
+
+int
+str_ends_with(const char *haystack, const char *needle)
+{
+ int hlen = strlen(haystack);
+ int nlen = strlen(needle);
+ if (hlen < nlen)
+ return 0;
+ else
+ return !memcmp(haystack + hlen - nlen, needle, nlen);
+}
* UCW Library -- String Routines
*
* (c) 2006 Pavel Charvat <pchar@ucw.cz>
- * (c) 2007--2008 Martin Mares <mj@ucw.cz>
+ * (c) 2007--2012 Martin Mares <mj@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
char *str_format_flags(char *dest, const char *fmt, uns flags);
uns str_count_char(const char *str, uns chr);
+/** Returns a non-zero value if @haystack starts with @needle. **/
+int str_starts_with(const char *haystack, const char *needle);
+
+/** Returns a non-zero value if @haystack ends with @needle. **/
+int str_ends_with(const char *haystack, const char *needle);
+
/* str-esc.c */
char *str_unesc(char *dest, const char *src);