↓ Skip to main content

“In both examples, converting the string to uppercase causes the string to get longer.”

Raymond Chendevblogs.microsoft.com ↗

Looping over a string with std::tolower breaks on UTF-16 surrogate pairs, UTF-8 multibyte characters and any case mapping that changes length. Case conversion is a whole-string operation that depends on locale. The fix is LCMapStringEx or ICU’s u_strToUpper. The popular one-liner works fine as long as your users only speak ASCII.