mirror of
https://github.com/reactos/reactos.git
synced 2025-01-01 12:04:51 +00:00
Implement IntWideCharToMultiByteUTF8 since it's needed for saving Explorer configuration. (This change should be ported to the release branch.)
svn path=/trunk/; revision=10748
This commit is contained in:
parent
67d68774ab
commit
d4aa975e56
1 changed files with 64 additions and 2 deletions
|
@ -440,8 +440,70 @@ IntWideCharToMultiByteUTF8(UINT CodePage, DWORD Flags,
|
|||
LPSTR MultiByteString, INT MultiByteCount,
|
||||
LPCSTR DefaultChar, LPBOOL UsedDefaultChar)
|
||||
{
|
||||
DPRINT1("WideCharToMultiByte for CP_UTF8 is not implemented!\n");
|
||||
return 0;
|
||||
INT TempLength;
|
||||
WCHAR Char;
|
||||
|
||||
/* Does caller query for output buffer size? */
|
||||
if (MultiByteCount == 0)
|
||||
{
|
||||
for (TempLength = 0; WideCharCount;
|
||||
WideCharCount--, WideCharString++)
|
||||
{
|
||||
TempLength++;
|
||||
if (*WideCharString >= 0x80)
|
||||
{
|
||||
TempLength++;
|
||||
if (*WideCharString >= 0x800)
|
||||
TempLength++;
|
||||
}
|
||||
}
|
||||
return TempLength;
|
||||
}
|
||||
|
||||
for (TempLength = MultiByteCount; WideCharCount;
|
||||
WideCharCount--, WideCharString++)
|
||||
{
|
||||
Char = *WideCharString;
|
||||
if (Char < 0x80)
|
||||
{
|
||||
if (!TempLength)
|
||||
{
|
||||
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
||||
break;
|
||||
}
|
||||
TempLength--;
|
||||
*MultiByteString++ = Char;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Char < 0x800) /* 0x80-0x7ff: 2 bytes */
|
||||
{
|
||||
if (TempLength < 2)
|
||||
{
|
||||
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
||||
break;
|
||||
}
|
||||
MultiByteString[1] = 0x80 | (Char & 0x3f); Char >>= 6;
|
||||
MultiByteString[0] = 0xc0 | Char;
|
||||
MultiByteString += 2;
|
||||
TempLength -= 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* 0x800-0xffff: 3 bytes */
|
||||
if (TempLength < 3)
|
||||
{
|
||||
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
||||
break;
|
||||
}
|
||||
MultiByteString[2] = 0x80 | (Char & 0x3f); Char >>= 6;
|
||||
MultiByteString[1] = 0x80 | (Char & 0x3f); Char >>= 6;
|
||||
MultiByteString[0] = 0xe0 | Char;
|
||||
MultiByteString += 3;
|
||||
TempLength -= 3;
|
||||
}
|
||||
|
||||
return MultiByteCount - TempLength;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue