I'm curious if I can implement a function like find
in std :: string
to search insensitive.
The function below find insensitive i want to call this function like that:
int main()
{
std::string s1 = "do SoMething";
std::string s2 = "something";
auto found = s1.findCaseInsensitive(s2);
//or
auto found = std::findCaseInsensitive(s1,s2);
}
size_t findCaseInsensitive(std::string data, std::string toSearch)
{
std::transform(data.begin(), data.end(), data.begin(), ::tolower);
std::transform(toSearch.begin(), toSearch.end(), toSearch.begin(), ::tolower);
return data.find(toSearch);
}
namespace std{
//...
}