Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tolower() is not working for Ü,Ö in c++

Tags:

c++

tolower

When I tried tolower() with non english charecters in c++ it's not working normally. I searched that issue and I came across something about locale but I am not sure about best solution of that.

My sample code is below:

printf("%c ",tolower('Ü'));
like image 506
Yavuz Avatar asked Jan 14 '23 18:01

Yavuz


1 Answers

Unfortunately, the standard C++ library does not have sufficient support for changing the case of all possible non-English characters (in so far as those characters that have case variants at all). This limitation is caused by the fact that the C++ standard assumes that a single character and its case variants occupy exactly one char object (or wchar_t object for wide characters) and for non-English characters that is not guaranteed to be true (also depending on how the characters are coded).

If your environment uses a single-byte encoding for the relevant characters, this might give you what you want:

std::cout << std::tolower('Ü', locale());

With wide characters, you will probably have more luck:

std::wcout << std::tolower(L'Ü', locale());

but even that won't give the correct result for toupper(L'ß'), which would be the two-character sequence L"SS").

If you need support for all characters, take a look at the ICU library, in particular the part about case mappings

like image 119
Bart van Ingen Schenau Avatar answered Jan 24 '23 18:01

Bart van Ingen Schenau