Revision 765428699a5381f113d19974720bc91b5bfeaf1d authored by Junio C Hamano on 17 March 2016, 17:00:44 UTC, committed by Junio C Hamano on 17 March 2016, 18:23:05 UTC
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 32c6dca
Raw File
strcasestr.c
#include "../git-compat-util.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