diff --git a/winpr/libwinpr/crt/CMakeLists.txt b/winpr/libwinpr/crt/CMakeLists.txt index 244f5281e..d82e64fc2 100644 --- a/winpr/libwinpr/crt/CMakeLists.txt +++ b/winpr/libwinpr/crt/CMakeLists.txt @@ -28,7 +28,7 @@ else() IF (ANDROID) list(APPEND CRT_FILES unicode_android.c) elseif (NOT APPLE AND NOT WIN32) - find_package(ICU REQUIRED i18n uc io) + find_package(ICU REQUIRED i18n uc io data) list(APPEND CRT_FILES unicode_icu.c) winpr_include_directory_add(${ICU_INCLUDE_DIRS}) winpr_library_add_private(${ICU_LIBRARIES}) diff --git a/winpr/libwinpr/crt/unicode_icu.c b/winpr/libwinpr/crt/unicode_icu.c index dd1fff551..caa9737d1 100644 --- a/winpr/libwinpr/crt/unicode_icu.c +++ b/winpr/libwinpr/crt/unicode_icu.c @@ -41,6 +41,8 @@ #include "../log.h" #define TAG WINPR_TAG("unicode") +#define UCNV_CONVERT 1 + int int_MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar) { @@ -93,9 +95,16 @@ int int_MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, targetStart = lpWideCharStr; targetCapacity = cchWideChar; - +#if defined(UCNV_CONVERT) + targetLength = + ucnv_convert("UTF-16LE", "UTF-8", targetStart, targetCapacity * sizeof(WCHAR), + lpMultiByteStr, cbMultiByte, &error); + if (targetLength > 0) + targetLength /= sizeof(WCHAR); +#else u_strFromUTF8(targetStart, targetCapacity, &targetLength, lpMultiByteStr, cbMultiByte, &error); +#endif switch (error) { @@ -187,8 +196,12 @@ int int_WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, targetStart = lpMultiByteStr; targetCapacity = cbMultiByte; - +#if defined(UCNV_CONVERT) + targetLength = ucnv_convert("UTF-8", "UTF-16LE", targetStart, targetCapacity, lpWideCharStr, + cchWideChar * sizeof(WCHAR), &error); +#else u_strToUTF8(targetStart, targetCapacity, &targetLength, lpWideCharStr, cchWideChar, &error); +#endif switch (error) { case U_BUFFER_OVERFLOW_ERROR: