I need to find if a string contains a substring, but according to the current locale's rules.
So, if I'm searching for the string "aba", with the Spanish locale, "cabalgar", "rábano" and "gabán" would all three contain it.
I know I can compare strings with locale information (collate), but is there any built-in or starightforward way to do the same with find, or do I have to write my own?
I'm fine using std::string (up to TR1) or MFC's CString
You could loop over the string indices, and compare a substring with the string you want to find with
std::strcoll
.I haven't used this before, but
std::strxfrm
looks to be what you could use:However, as you can see... This doesn't do what you want. See the comment at your question.
For reference, here is an implementation using boost locale compiled with ICU backend:
Output: