From 609a4eb6aedfa2ef5bc8ed8d6b350afefbe8714c Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 16 Jan 2018 10:37:19 +0100 Subject: [PATCH] Fixed ICU support for CP_ACP --- winpr/libwinpr/crt/unicode.c | 45 ++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/winpr/libwinpr/crt/unicode.c b/winpr/libwinpr/crt/unicode.c index e552c85..b60cba8 100644 --- a/winpr/libwinpr/crt/unicode.c +++ b/winpr/libwinpr/crt/unicode.c @@ -181,11 +181,13 @@ int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, switch (CodePage) { - case CP_UTF8: - break; - default: - WLog_ERR(TAG, "Unsupported encoding %u", CodePage); - return 0; + case CP_ACP: + case CP_UTF8: + break; + + default: + WLog_ERR(TAG, "Unsupported encoding %u", CodePage); + return 0; } if (cbMultiByte > UINT32_MAX) @@ -193,27 +195,27 @@ int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, targetStart = lpWideCharStr; targetCapacity = cchWideChar; - error = U_ZERO_ERROR; + if (cchWideChar == 0) { u_strFromUTF8(NULL, 0, &targetLength, - lpMultiByteStr, cbMultiByte, &error); + lpMultiByteStr, cbMultiByte, &error); cchWideChar = targetLength; } else { u_strFromUTF8(targetStart, targetCapacity, &targetLength, - lpMultiByteStr, cbMultiByte, &error); + lpMultiByteStr, cbMultiByte, &error); cchWideChar = U_SUCCESS(error) ? targetLength : 0; } } #else + if (cchWideChar == 0) { sourceStart = (const BYTE*) lpMultiByteStr; targetStart = (WCHAR*) NULL; - result = ConvertUTF8toUTF16(&sourceStart, &sourceStart[cbMultiByte], &targetStart, NULL, strictConversion); length = targetStart - ((WCHAR*) NULL); @@ -222,7 +224,6 @@ int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, { sourceStart = (const BYTE*) lpMultiByteStr; targetStart = lpWideCharStr; - result = ConvertUTF8toUTF16(&sourceStart, &sourceStart[cbMultiByte], &targetStart, &targetStart[cchWideChar], strictConversion); length = targetStart - ((WCHAR*) lpWideCharStr); @@ -300,13 +301,15 @@ int WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int int32_t targetLength; int32_t targetCapacity; - switch(CodePage) + switch (CodePage) { - case CP_UTF8: - break; - default: - WLog_ERR(TAG, "Unsupported encoding %u", CodePage); - return 0; + case CP_ACP: + case CP_UTF8: + break; + + default: + WLog_ERR(TAG, "Unsupported encoding %u", CodePage); + return 0; } if (cchWideChar > UINT32_MAX) @@ -314,37 +317,35 @@ int WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int targetStart = lpMultiByteStr; targetCapacity = cbMultiByte; - error = U_ZERO_ERROR; + if (cbMultiByte == 0) { u_strToUTF8(NULL, 0, &targetLength, - lpWideCharStr, cchWideChar, &error); + lpWideCharStr, cchWideChar, &error); cbMultiByte = targetLength; } else { u_strToUTF8(targetStart, targetCapacity, &targetLength, - lpWideCharStr, cchWideChar, &error); + lpWideCharStr, cchWideChar, &error); cbMultiByte = U_SUCCESS(error) ? targetLength : 0; } } #else + if (cbMultiByte == 0) { sourceStart = (WCHAR*) lpWideCharStr; targetStart = (BYTE*) NULL; - result = ConvertUTF16toUTF8(&sourceStart, &sourceStart[cchWideChar], &targetStart, NULL, strictConversion); - length = targetStart - ((BYTE*) NULL); } else { sourceStart = (WCHAR*) lpWideCharStr; targetStart = (BYTE*) lpMultiByteStr; - result = ConvertUTF16toUTF8(&sourceStart, &sourceStart[cchWideChar], &targetStart, &targetStart[cbMultiByte], strictConversion); length = targetStart - ((BYTE*) lpMultiByteStr); -- 2.7.4