Since you are searching for a substring (std :: string) and not an element (character), unfortunately, there is no existing solution that I know about which is immediately available in the standard library for this.
However, it is simple enough: just convert both lines to upper case (or both to lower case - I chose upper case in this example).
std::string upper_string(const std::string& str) { string upper; transform(str.begin(), str.end(), std::back_inserter(upper), toupper); return upper; } std::string::size_type find_str_ci(const std::string& str, const std::string& substr) { return upper(str).find(upper(substr) ); }
This is not a quick fix (bordering the territory of pessimization), but it is the only thing I know from the hands. It is also not so difficult to implement your own case insensitive substring finder if you are concerned about efficiency.
Also, I need to support stand :: wstring / wchar_t. Any ideas?
tolower / toupper in locale will work with wide-format strings, so the above solution should be equally applicable (a simple change to std :: string to std :: wstring).
[Edit] An alternative, as indicated, is to adapt a case-insensitive string type from basic_string, specifying its own character traits. This works if you can accept all string queries, comparisons, etc., so that they are not case sensitive for a given string type.
stinky472 Jun 30 2018-10-18T00: 00Z
source share