Last active
August 5, 2017 01:16
-
-
Save blaquee/220da666dc138ad450b1ac213c173227 to your computer and use it in GitHub Desktop.
strstri implementation in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T, typename U> | |
static const T* stristr(const T* string, const T* substring, U(*tolwr)(U)) | |
{ | |
const T *a, *b; | |
b = substring; | |
if(*b == 0) | |
return string; | |
for(; *string != 0; string += 1) | |
{ | |
if(*string != *b) | |
continue; | |
a = string; | |
while(1) | |
{ | |
if(tolwr(*b) == 0) | |
return string; | |
if(tolwr(*a++) != tolwr(*b++)) | |
break; | |
} | |
b = substring; | |
} | |
return nullptr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment