Zstring makeUpperCopy(const Zstring& str) { const size_t len = str.size(); Zstring output; output.resize(len); std::transform(str.begin(), str.end(), output.begin(), [](char c) { return static_cast<char>(::toupper(static_cast<unsigned char>(c))); }); //locale-dependent! //result of toupper() is an unsigned char mapped to int range, so the char representation is in the last 8 bits and we need not care about signedness! //this should work for UTF-8, too: all chars >= 128 are mapped upon themselves! return output; }
Zstring makeUpperCopy(const Zstring& str) { const int len = static_cast<int>(str.size()); if (len == 0) //LCMapString does not allow input sizes of 0! return str; Zstring output = str; //LOCALE_INVARIANT is NOT available with Windows 2000 -> ok //use Windows' upper case conversion: faster than ::CharUpper() if (::LCMapString(LOCALE_INVARIANT, //__in LCID Locale, LCMAP_UPPERCASE, //__in DWORD dwMapFlags, str.c_str(), //__in LPCTSTR lpSrcStr, len, //__in int cchSrc, &*output.begin(), //__out LPTSTR lpDestStr, len) == 0) //__in int cchDest throw std::runtime_error("Error comparing strings (LCMapString). " + std::string(__FILE__) + ":" + numberTo<std::string>(__LINE__)); return output; }