Junio C Hamano | 4050c0d | 2005-12-05 11:54:29 -0800 | [diff] [blame] | 1 | #include "../git-compat-util.h" |
Linus Torvalds | ef34af2 | 2005-09-18 18:30:50 -0700 | [diff] [blame] | 2 | |
| 3 | char *gitstrcasestr(const char *haystack, const char *needle) |
| 4 | { |
| 5 | int nlen = strlen(needle); |
| 6 | int hlen = strlen(haystack) - nlen + 1; |
| 7 | int i; |
| 8 | |
| 9 | for (i = 0; i < hlen; i++) { |
| 10 | int j; |
| 11 | for (j = 0; j < nlen; j++) { |
| 12 | unsigned char c1 = haystack[i+j]; |
| 13 | unsigned char c2 = needle[j]; |
| 14 | if (toupper(c1) != toupper(c2)) |
| 15 | goto next; |
| 16 | } |
| 17 | return (char *) haystack + i; |
| 18 | next: |
| 19 | ; |
| 20 | } |
| 21 | return NULL; |
| 22 | } |