Skip to content

Instantly share code, notes, and snippets.

@blaquee
Last active August 5, 2017 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blaquee/220da666dc138ad450b1ac213c173227 to your computer and use it in GitHub Desktop.
Save blaquee/220da666dc138ad450b1ac213c173227 to your computer and use it in GitHub Desktop.
strstri implementation in C++
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