I wrote this function to make a string all uppercase. Unfortunately, it does not work with the extended ASCII characters, like ä, ö, ü, é, è and so on. How can I convert the string to uppercase and convert these characters also (Ä, Ö, Ü, É, È)?
void toUppercase1(string & strInOut)
{
std::locale loc;
for (std::string::size_type i=0; i<strInput.length(); ++i)
{
strInput.at(i) = std::toupper(strInput.at(i),loc);
}
return;
}
This is the new version.
#include <clocale>
void toUppercase2(string& strInput)
{
setlocale(LC_CTYPE, "sv_SE");
for (std::string::size_type i=0; i<strInput.length(); ++i) {
strInput.at(i) = toupper(strInput.at(i));
}
// reset locale
setlocale(LC_ALL, "");
return;
}
Unfortunately, the above method toUppercase2(string&) is very slow. It seems that changing the locale globally requires some effort. I assume that using a locale object from C++ which is initialized once and then used by toupper is much faster, but I cannot find an example of how to use it properly.
Any hints to where I can find more information about locales and their use is appreciated.