Simple RtlIsTextUnicode() patch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

this is a simple RtlIsTextUnicode() improvement patch.

Changelog:
    Dmitry Timoshkov <dmitry@codeweavers.com>
    Apply only specified tests.
    Implement IS_TEXT_UNICODE_REVERSE_SIGNATURE, IS_TEXT_UNICODE_STATISTICS
    and IS_TEXT_UNICODE_NULL_BYTES tests.
    Revert IS_TEXT_UNICODE_ODD_LENGTH test.

--- cvs/hq/wine/dlls/ntdll/rtlstr.c	Tue Aug 19 01:33:48 2003
+++ wine/dlls/ntdll/rtlstr.c	Tue Aug 19 08:25:42 2003
@@ -1405,7 +1405,11 @@
 */
 /* Tests that we currently implement */
 #define ITU_IMPLEMENTED_TESTS \
-        (IS_TEXT_UNICODE_SIGNATURE|IS_TEXT_UNICODE_ODD_LENGTH)
+    (IS_TEXT_UNICODE_SIGNATURE | \
+     IS_TEXT_UNICODE_REVERSE_SIGNATURE | \
+     IS_TEXT_UNICODE_ODD_LENGTH | \
+     IS_TEXT_UNICODE_STATISTICS | \
+     IS_TEXT_UNICODE_NULL_BYTES)
 
 /**************************************************************************
  *	RtlIsTextUnicode (NTDLL.@)
@@ -1443,12 +1447,42 @@
 	 */
 
 	/* Check for an odd length ... pass if even. */
-	if (!(len & 1))
+	if ((flags & IS_TEXT_UNICODE_ODD_LENGTH) && (len & 1))
 		out_flags |= IS_TEXT_UNICODE_ODD_LENGTH;
 
-	/* Check for the special unicode marker byte. */
-	if (*s == 0xFEFF)
+	/* Check for the special byte order unicode marks. */
+	if ((flags & IS_TEXT_UNICODE_SIGNATURE) && *s == 0xFEFF)
 		out_flags |= IS_TEXT_UNICODE_SIGNATURE;
+
+    if ((flags & IS_TEXT_UNICODE_REVERSE_SIGNATURE) && *s == 0xFFFE)
+        out_flags |= IS_TEXT_UNICODE_REVERSE_SIGNATURE;
+
+    /* apply some statistical analysis */
+    if (flags & IS_TEXT_UNICODE_STATISTICS)
+    {
+        DWORD i, stats = 0;
+        /* FIXME: checks only for ASCII characters in the unicode stream */
+        for (i = 0; i < len / sizeof(WCHAR); i++)
+        {
+            if (s[i] <= 255) stats++;
+        }
+        if (stats > len / sizeof(WCHAR) / 2)
+            out_flags |= IS_TEXT_UNICODE_STATISTICS;
+    }
+
+    /* Check for unicode NULL chars */
+    if (flags & IS_TEXT_UNICODE_NULL_BYTES)
+    {
+        DWORD i;
+        for (i = 0; i < len / sizeof(WCHAR); i++)
+        {
+            if (!s[i])
+            {
+                out_flags |= IS_TEXT_UNICODE_NULL_BYTES;
+                break;
+            }
+        }
+    }
 
 	/*
 	 * Check whether the string passed all of the tests.





[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux