| 1382 | using LCMapStringEx_t = int (WINAPI*)(LPCWSTR lpLocaleName, DWORD dwMapFlags, LPCWSTR lpSrcStr, int cchSrc, LPWSTR lpDestStr, int cchDest, LPNLSVERSIONINFO lpVersionInformation, LPVOID lpReserved, LPARAM sortHandle); |
| 1383 | |
| 1384 | static String LCMapStringAuto(const String& input, unsigned mapFlags) |
| 1385 | { |
| 1386 | if (input.empty()) |
| 1387 | return input; |
| 1388 | |
| 1389 | static LCMapStringEx_t pLCMapStringEx = nullptr; |
| 1390 | static bool checked = false; |
| 1391 | |
| 1392 | if (!checked) |
| 1393 | { |
| 1394 | HMODULE hKernel32 = GetModuleHandleW(L"kernel32.dll"); |
| 1395 | if (hKernel32) |
| 1396 | pLCMapStringEx = reinterpret_cast<LCMapStringEx_t>(GetProcAddress(hKernel32, "LCMapStringEx")); |
| 1397 | checked = true; |
| 1398 | } |
| 1399 | |
| 1400 | if (pLCMapStringEx) |
| 1401 | { |
| 1402 | int len = pLCMapStringEx(nullptr, mapFlags, input.c_str(), static_cast<int>(input.size()), nullptr, 0, nullptr, nullptr, 0); |
| 1403 | if (len <= 0) |
| 1404 | return input; |
| 1405 | std::wstring result(len, L'\0'); |
| 1406 | pLCMapStringEx(nullptr, mapFlags, input.c_str(), static_cast<int>(input.size()), result.data(), len, nullptr, nullptr, 0); |
| 1407 | return result; |
| 1408 | } |
| 1409 | |
| 1410 | // XP fallback |
| 1411 | int len = LCMapStringW(LOCALE_USER_DEFAULT, mapFlags, input.c_str(), static_cast<int>(input.size()), nullptr, 0); |
| 1412 | if (len <= 0) |
| 1413 | return input; |
| 1414 | |
| 1415 | std::wstring result(len, L'\0'); |
| 1416 | LCMapStringW(LOCALE_USER_DEFAULT, mapFlags, input.c_str(), static_cast<int>(input.size()), result.data(), len); |
| 1417 | |
| 1418 | return result; |
| 1419 | } |
| 1420 | |
| 1421 | String toUpper(const String& s) |
| 1422 | { |
no test coverage detected