wmii/lib/libstuff/util/strcasestr.c

26 lines
548 B
C
Raw Permalink Normal View History

2010-05-22 06:52:47 +04:00
/* Written by Kris Maglione <maglione.k at Gmail> */
/* Public domain */
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <strings.h>
#include "util.h"
/* TODO: Make this UTF-8 compliant. */
char*
strcasestr(const char *dst, const char *src) {
2010-08-10 13:46:00 +04:00
int len, dc, sc;
if(src[0] == '\0')
return (char*)(uintptr_t)dst;
2010-05-22 06:52:47 +04:00
len = strlen(src) - 1;
2010-08-10 13:46:00 +04:00
sc = tolower(src[0]);
for(; (dc = *dst); dst++) {
dc = tolower(dc);
if(sc == dc && (len == 0 || !strncasecmp(dst+1, src+1, len)))
return (char*)(uintptr_t)dst;
2010-05-22 06:52:47 +04:00
}
return nil;
2010-06-14 18:30:23 +04:00
}