Fixed ICU support for CP_ACP

This commit is contained in:
Armin Novak 2018-01-16 10:37:19 +01:00
parent c62fde53a4
commit 609a4eb6ae

View File

@ -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);