Author: dchapyshev
Date: Sun Sep 18 17:26:59 2016
New Revision: 72729

URL: http://svn.reactos.org/svn/reactos?rev=72729&view=rev
Log:
[KERNEL32] Implement MB_USEGLYPHCHARS flag for MultiByteToWideChar. Add checks 
for "Private Use" characters. More correct checks for input parameters.

* Fixes 6 tests for kernel32:codepage

Modified:
    trunk/reactos/dll/win32/kernel32/winnls/string/nls.c

Modified: trunk/reactos/dll/win32/kernel32/winnls/string/nls.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/winnls/string/nls.c?rev=72729&r1=72728&r2=72729&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/winnls/string/nls.c        [iso-8859-1] 
(original)
+++ trunk/reactos/dll/win32/kernel32/winnls/string/nls.c        [iso-8859-1] 
Sun Sep 18 17:26:59 2016
@@ -436,6 +436,7 @@
 {
     PCODEPAGE_ENTRY CodePageEntry;
     PCPTABLEINFO CodePageTable;
+    PUSHORT MultiByteTable;
     LPCSTR TempString;
     INT TempLength;
 
@@ -446,10 +447,22 @@
         SetLastError(ERROR_INVALID_PARAMETER);
         return 0;
     }
+
     CodePageTable = &CodePageEntry->CodePageTable;
 
+    /* If MB_USEGLYPHCHARS flag present and glyph table present */
+    if ((Flags & MB_USEGLYPHCHARS) && CodePageTable->MultiByteTable[256])
+    {
+        /* Use glyph table */
+        MultiByteTable = CodePageTable->MultiByteTable + 256 + 1;
+    }
+    else
+    {
+        MultiByteTable = CodePageTable->MultiByteTable;
+    }
+
     /* Different handling for DBCS code pages. */
-    if (CodePageTable->MaximumCharacterSize > 1)
+    if (CodePageTable->DBCSCodePage)
     {
         UCHAR Char;
         USHORT DBCSOffset;
@@ -498,7 +511,7 @@
 
             if (!DBCSOffset)
             {
-                *WideCharString++ = CodePageTable->MultiByteTable[Char];
+                *WideCharString++ = MultiByteTable[Char];
                 continue;
             }
 
@@ -523,9 +536,12 @@
                  TempLength > 0;
                  TempString++, TempLength--)
             {
-                if (CodePageTable->MultiByteTable[(UCHAR)*TempString] ==
-                    CodePageTable->UniDefaultChar &&
-                    *TempString != CodePageEntry->CodePageTable.DefaultChar)
+                USHORT WideChar = MultiByteTable[(UCHAR)*TempString];
+
+                if ((WideChar == CodePageTable->UniDefaultChar &&
+                    *TempString != 
CodePageEntry->CodePageTable.TransUniDefaultChar) ||
+                    /* "Private Use" characters */
+                    (WideChar >= 0xE000 && WideChar <= 0xF8FF))
                 {
                     SetLastError(ERROR_NO_UNICODE_TRANSLATION);
                     return 0;
@@ -542,7 +558,7 @@
             TempLength > 0;
             MultiByteString++, TempLength--)
         {
-            *WideCharString++ = 
CodePageTable->MultiByteTable[(UCHAR)*MultiByteString];
+            *WideCharString++ = MultiByteTable[(UCHAR)*MultiByteString];
         }
 
         /* Adjust buffer size. Wine trick ;-) */
@@ -1434,9 +1450,9 @@
 {
     /* Check the parameters. */
     if (MultiByteString == NULL ||
-        MultiByteCount == 0 ||
-        (WideCharString == NULL && WideCharCount > 0) ||
-        (PVOID)MultiByteString == (PVOID)WideCharString)
+        MultiByteCount == 0 || WideCharCount < 0 ||
+        (WideCharCount && (WideCharString == NULL ||
+        (PVOID)MultiByteString == (PVOID)WideCharString)))
     {
         SetLastError(ERROR_INVALID_PARAMETER);
         return 0;


Reply via email to