- Fix size functions to return the correct results in all cases. Modified: trunk/reactos/lib/rtl/nls.c Modified: trunk/reactos/lib/rtl/unicode.c _____
Modified: trunk/reactos/lib/rtl/nls.c --- trunk/reactos/lib/rtl/nls.c 2005-09-06 19:38:51 UTC (rev 17704) +++ trunk/reactos/lib/rtl/nls.c 2005-09-06 19:47:06 UTC (rev 17705) @@ -278,35 +278,50 @@
/* * @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 @@ 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 */ _____
Modified: trunk/reactos/lib/rtl/unicode.c --- trunk/reactos/lib/rtl/unicode.c 2005-09-06 19:38:51 UTC (rev 17704) +++ trunk/reactos/lib/rtl/unicode.c 2005-09-06 19:47:06 UTC (rev 17705) @@ -68,13 +68,15 @@
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 @@ */ 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 @@ 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 @@ */ 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)); }