Author: dchapyshev
Date: Sun Sep 18 18:21:30 2016
New Revision: 72730

URL: http://svn.reactos.org/svn/reactos?rev=72730&view=rev
Log:
[KERNEL32] Implement MB_ERR_INVALID_CHARS flag for DBCS codepages

* Fixes 3 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=72730&r1=72729&r2=72730&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 18:21:30 2016
@@ -439,6 +439,7 @@
     PUSHORT MultiByteTable;
     LPCSTR TempString;
     INT TempLength;
+    USHORT WideChar;
 
     /* Get code page table. */
     CodePageEntry = IntGetCodePageEntry(CodePage);
@@ -471,8 +472,48 @@
 
         if (Flags & MB_ERR_INVALID_CHARS)
         {
-            /* FIXME */
-            DPRINT1("IntMultiByteToWideCharCP: MB_ERR_INVALID_CHARS case not 
implemented!\n");
+            TempString = MultiByteString;
+
+            while (TempString < MbsEnd)
+            {
+                DBCSOffset = CodePageTable->DBCSOffsets[*TempString];
+
+                if (DBCSOffset)
+                {
+                    /* If lead byte is presented, but behind it there is no 
symbol */
+                    if (((TempString + 1) == MbsEnd) || (*(TempString + 1) == 
0))
+                    {
+                        SetLastError(ERROR_NO_UNICODE_TRANSLATION);
+                        return 0;
+                    }
+
+                    WideChar = CodePageTable->DBCSOffsets[*(TempString + 1) + 
DBCSOffset];
+
+                    if (WideChar == CodePageTable->UniDefaultChar &&
+                        MAKEWORD(*(TempString + 1), *TempString) != 
CodePageTable->TransUniDefaultChar)
+                    {
+                        SetLastError(ERROR_NO_UNICODE_TRANSLATION);
+                        return 0;
+                    }
+
+                    TempString++;
+                }
+                else
+                {
+                    USHORT WideChar = MultiByteTable[(UCHAR)*TempString];
+
+                    if ((WideChar == CodePageTable->UniDefaultChar &&
+                        *TempString != CodePageTable->TransUniDefaultChar) ||
+                        /* "Private Use" characters */
+                        (WideChar >= 0xE000 && WideChar <= 0xF8FF))
+                    {
+                        SetLastError(ERROR_NO_UNICODE_TRANSLATION);
+                        return 0;
+                    }
+                }
+
+                TempString++;
+            }
         }
         
         /* Does caller query for output buffer size? */
@@ -536,10 +577,10 @@
                  TempLength > 0;
                  TempString++, TempLength--)
             {
-                USHORT WideChar = MultiByteTable[(UCHAR)*TempString];
+                WideChar = MultiByteTable[(UCHAR)*TempString];
 
                 if ((WideChar == CodePageTable->UniDefaultChar &&
-                    *TempString != 
CodePageEntry->CodePageTable.TransUniDefaultChar) ||
+                    *TempString != CodePageTable->TransUniDefaultChar) ||
                     /* "Private Use" characters */
                     (WideChar >= 0xE000 && WideChar <= 0xF8FF))
                 {


Reply via email to