swh:1:snp:47f1e8bb459169b0feb652a9c3d9cbabd8526d4a
Raw File
Tip revision: 00d8bbd3c4bba72a6dfd48c2c0c9cbaa000f13c2 authored by Junio C Hamano on 24 September 2005, 18:38:43 UTC
GIT 0.99.7c
Tip revision: 00d8bbd
strcasestr.c
#include <string.h>
#include <ctype.h>

char *gitstrcasestr(const char *haystack, const char *needle)
{
	int nlen = strlen(needle);
	int hlen = strlen(haystack) - nlen + 1;
	int i;

	for (i = 0; i < hlen; i++) {
		int j;
		for (j = 0; j < nlen; j++) {
			unsigned char c1 = haystack[i+j];
			unsigned char c2 = needle[j];
			if (toupper(c1) != toupper(c2))
				goto next;
		}
		return (char *) haystack + i;
	next:
		;
	}
	return NULL;
}
back to top