mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 01:55:19 +00:00
- Fix size functions to return the correct results in all cases.
svn path=/trunk/; revision=17705
This commit is contained in:
parent
7ed06b56e6
commit
84cbfb9d8e
2 changed files with 91 additions and 74 deletions
|
@ -278,35 +278,50 @@ RtlMultiByteToUnicodeN(
|
|||
/*
|
||||
* @implemented
|
||||
*/
|
||||
NTSTATUS STDCALL
|
||||
NTSTATUS
|
||||
STDCALL
|
||||
RtlMultiByteToUnicodeSize(PULONG UnicodeSize,
|
||||
PCSTR MbString,
|
||||
ULONG MbSize)
|
||||
{
|
||||
ULONG Length;
|
||||
ULONG Length = 0;
|
||||
|
||||
if (NlsMbCodePageTag == FALSE)
|
||||
{
|
||||
/* single-byte code page */
|
||||
*UnicodeSize = MbSize * sizeof (WCHAR);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* multi-byte code page */
|
||||
for (Length = 0; MbSize; MbSize--, MbString++, Length++)
|
||||
{
|
||||
if (NlsLeadByteInfo[(UCHAR)*MbString] != 0)
|
||||
{
|
||||
if (!--MbSize)
|
||||
break; /* partial char, ignore it */
|
||||
MbString++;
|
||||
}
|
||||
}
|
||||
if (!NlsMbCodePageTag)
|
||||
{
|
||||
/* single-byte code page */
|
||||
*UnicodeSize = MbSize * sizeof (WCHAR);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* multi-byte code page */
|
||||
while (MbSize--)
|
||||
{
|
||||
if (NlsLeadByteInfo[*(PUCHAR)MbString++])
|
||||
{
|
||||
if (!MbSize)
|
||||
{
|
||||
/* partial char, ignore it */
|
||||
Length++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Move on */
|
||||
MbSize--;
|
||||
MbString++;
|
||||
}
|
||||
|
||||
*UnicodeSize = Length * sizeof(WCHAR);
|
||||
}
|
||||
/* Increase returned size */
|
||||
Length++;
|
||||
}
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
/* Return final size */
|
||||
*UnicodeSize = Length * sizeof(WCHAR);
|
||||
}
|
||||
|
||||
/* Success */
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
@ -472,47 +487,45 @@ RtlUnicodeToMultiByteN (PCHAR MbString,
|
|||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
NTSTATUS STDCALL
|
||||
NTSTATUS
|
||||
STDCALL
|
||||
RtlUnicodeToMultiByteSize(PULONG MbSize,
|
||||
PWCHAR UnicodeString,
|
||||
ULONG UnicodeSize)
|
||||
{
|
||||
ULONG UnicodeLength;
|
||||
ULONG MbLength;
|
||||
ULONG UnicodeLength = UnicodeSize / sizeof(WCHAR);
|
||||
ULONG MbLength = 0;
|
||||
|
||||
if (NlsMbCodePageTag == FALSE)
|
||||
{
|
||||
/* single-byte code page */
|
||||
*MbSize = UnicodeSize / sizeof (WCHAR);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* multi-byte code page */
|
||||
UnicodeLength = UnicodeSize / sizeof(WCHAR);
|
||||
MbLength = 0;
|
||||
while (UnicodeLength > 0)
|
||||
{
|
||||
if (NlsLeadByteInfo[(USHORT)*UnicodeString] & 0xff00)
|
||||
MbLength++;
|
||||
if (!NlsMbCodePageTag)
|
||||
{
|
||||
/* single-byte code page */
|
||||
*MbSize = UnicodeLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* multi-byte code page */
|
||||
while (UnicodeLength--)
|
||||
{
|
||||
if (HIBYTE(NlsUnicodeToAnsiTable[*UnicodeString++]))
|
||||
{
|
||||
MbLength += sizeof(WCHAR);
|
||||
}
|
||||
else
|
||||
{
|
||||
MbLength++;
|
||||
}
|
||||
}
|
||||
|
||||
*MbSize = MbLength;
|
||||
}
|
||||
|
||||
MbLength++;
|
||||
UnicodeLength--;
|
||||
UnicodeString++;
|
||||
}
|
||||
|
||||
*MbSize = MbLength;
|
||||
}
|
||||
|
||||
return(STATUS_SUCCESS);
|
||||
/* Success */
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* @unimplemented
|
||||
*/
|
||||
|
|
|
@ -68,13 +68,15 @@ ULONG
|
|||
STDCALL
|
||||
RtlxAnsiStringToUnicodeSize(IN PCANSI_STRING AnsiString)
|
||||
{
|
||||
ULONG Size;
|
||||
ULONG Size;
|
||||
|
||||
RtlMultiByteToUnicodeSize(&Size,
|
||||
AnsiString->Buffer,
|
||||
AnsiString->Length);
|
||||
/* Convert from Mb String to Unicode Size */
|
||||
RtlMultiByteToUnicodeSize(&Size,
|
||||
AnsiString->Buffer,
|
||||
AnsiString->Length);
|
||||
|
||||
return(Size);
|
||||
/* Return the size plus the null-char */
|
||||
return(Size + sizeof(WCHAR));
|
||||
}
|
||||
|
||||
|
||||
|
@ -883,16 +885,17 @@ RtlUnicodeStringToInteger(
|
|||
*/
|
||||
ULONG
|
||||
STDCALL
|
||||
RtlxUnicodeStringToOemSize(
|
||||
IN PCUNICODE_STRING UnicodeString)
|
||||
RtlxUnicodeStringToOemSize(IN PCUNICODE_STRING UnicodeString)
|
||||
{
|
||||
ULONG Size;
|
||||
ULONG Size;
|
||||
|
||||
RtlUnicodeToMultiByteSize (&Size,
|
||||
/* Convert the Unicode String to Mb Size */
|
||||
RtlUnicodeToMultiByteSize(&Size,
|
||||
UnicodeString->Buffer,
|
||||
UnicodeString->Length);
|
||||
|
||||
return Size+1; //NB: incl. nullterm
|
||||
/* Return the size + the null char */
|
||||
return (Size + sizeof(CHAR));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1798,14 +1801,15 @@ ULONG
|
|||
STDCALL
|
||||
RtlxOemStringToUnicodeSize(IN PCOEM_STRING OemString)
|
||||
{
|
||||
ULONG Size;
|
||||
ULONG Size;
|
||||
|
||||
//this function returns size including nullterm
|
||||
RtlMultiByteToUnicodeSize(&Size,
|
||||
OemString->Buffer,
|
||||
OemString->Length);
|
||||
/* Convert the Mb String to Unicode Size */
|
||||
RtlMultiByteToUnicodeSize(&Size,
|
||||
OemString->Buffer,
|
||||
OemString->Length);
|
||||
|
||||
return(Size);
|
||||
/* Return the size + null-char */
|
||||
return (Size + sizeof(WCHAR));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1859,17 +1863,17 @@ RtlStringFromGUID (IN REFGUID Guid,
|
|||
*/
|
||||
ULONG
|
||||
STDCALL
|
||||
RtlxUnicodeStringToAnsiSize(
|
||||
IN PCUNICODE_STRING UnicodeString)
|
||||
RtlxUnicodeStringToAnsiSize(IN PCUNICODE_STRING UnicodeString)
|
||||
{
|
||||
ULONG Size;
|
||||
ULONG Size;
|
||||
|
||||
//this function return size without nullterm!
|
||||
RtlUnicodeToMultiByteSize (&Size,
|
||||
/* Convert the Unicode String to Mb Size */
|
||||
RtlUnicodeToMultiByteSize(&Size,
|
||||
UnicodeString->Buffer,
|
||||
UnicodeString->Length);
|
||||
|
||||
return Size + sizeof(CHAR); //NB: incl. nullterm
|
||||
/* Return the size + null-char */
|
||||
return (Size + sizeof(CHAR));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue