https://github.com/git/git
Raw File
Tip revision: c8dd1e3bb1152844983558802a52c9e4c17652b4 authored by Junio C Hamano on 05 May 2017, 04:03:40 UTC
Git 2.7.5
Tip revision: c8dd1e3
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