I had a need to do a case insensitive find and found the following code which did the trick
bool ci_equal(char ch1, char ch2)
{
return toupper((unsigned char)ch1) == toupper((unsigned char)ch2);
}
size_t ci_find(const string& str1, const string& str2)
{
string::const_iterator pos = std::search(str1. begin ( ), str1. end ( ), str2.
begin ( ), str2. end ( ), ci_equal);
if (pos == str1. end ( ))
return string::npos;
else
return pos - str1. begin ( );
}
That got me to wondering what it would take to make this a member function of 'string' so it could be called like this:
string S="abcdefghijklmnopqrstuv";
string F="GHI";
S.ci_find(F);
I realize that there are many problems with case conversions in non-English languages but that's not the question I'm interested in.
Being a neophyte, I quickly got lost among containers and templates.
Is there anyway to do this? Could someone point to me an example of something similar?