wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

strcasestr.c (548B)


      1 /* Written by Kris Maglione <maglione.k at Gmail> */
      2 /* Public domain */
      3 #include <ctype.h>
      4 #include <stdint.h>
      5 #include <string.h>
      6 #include <strings.h>
      7 #include "util.h"
      8 
      9 /* TODO: Make this UTF-8 compliant. */
     10 char*
     11 strcasestr(const char *dst, const char *src) {
     12 	int len, dc, sc;
     13 
     14 	if(src[0] == '\0')
     15 		return (char*)(uintptr_t)dst;
     16 
     17 	len = strlen(src) - 1;
     18 	sc  = tolower(src[0]);
     19 	for(; (dc = *dst); dst++) {
     20 		dc = tolower(dc);
     21 		if(sc == dc && (len == 0 || !strncasecmp(dst+1, src+1, len)))
     22 			return (char*)(uintptr_t)dst;
     23 	}
     24 	return nil;
     25 }