From 6748410167aa93df6f52fedc256978c61cdd7abb Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Wed, 26 Mar 2003 15:19:28 +0000 Subject: [PATCH] Implemented RtlIsTextUnicode(). svn path=/trunk/; revision=4434 --- reactos/include/defines.h | 17 ---------- reactos/include/ntos/rtl.h | 27 +++++++++++++++- reactos/lib/ntdll/def/ntdll.def | 4 +-- reactos/lib/ntdll/def/ntdll.edf | 4 +-- reactos/lib/ntdll/rtl/unicode.c | 57 ++++++++++++++++++++++++++++++++- 5 files changed, 86 insertions(+), 23 deletions(-) diff --git a/reactos/include/defines.h b/reactos/include/defines.h index 4c8ab4fe417..b45e216a8fe 100644 --- a/reactos/include/defines.h +++ b/reactos/include/defines.h @@ -1924,23 +1924,6 @@ extern "C" { /* InitializeSecurityDescriptor */ #define SECURITY_DESCRIPTOR_REVISION (1) -/* IsTextUnicode */ -#define IS_TEXT_UNICODE_ASCII16 (1) -#define IS_TEXT_UNICODE_REVERSE_ASCII16 (16) -#define IS_TEXT_UNICODE_STATISTICS (2) -#define IS_TEXT_UNICODE_REVERSE_STATISTICS (32) -#define IS_TEXT_UNICODE_CONTROLS (4) -#define IS_TEXT_UNICODE_REVERSE_CONTROLS (64) -#define IS_TEXT_UNICODE_SIGNATURE (8) -#define IS_TEXT_UNICODE_REVERSE_SIGNATURE (128) -#define IS_TEXT_UNICODE_ILLEGAL_CHARS (256) -#define IS_TEXT_UNICODE_ODD_LENGTH (512) -#define IS_TEXT_UNICODE_NULL_BYTES (4096) -#define IS_TEXT_UNICODE_UNICODE_MASK (15) -#define IS_TEXT_UNICODE_REVERSE_MASK (240) -#define IS_TEXT_UNICODE_NOT_UNICODE_MASK (3840) -#define IS_TEXT_UNICODE_NOT_ASCII_MASK (61440) - /* JournalPlaybackProc, KeyboardProc */ #define HC_GETNEXT (1) #define HC_SKIP (2) diff --git a/reactos/include/ntos/rtl.h b/reactos/include/ntos/rtl.h index d97543ef85e..682e5cfd677 100755 --- a/reactos/include/ntos/rtl.h +++ b/reactos/include/ntos/rtl.h @@ -1,4 +1,4 @@ -/* $Id: rtl.h,v 1.5 2003/02/12 00:39:30 hyperion Exp $ +/* $Id: rtl.h,v 1.6 2003/03/26 15:10:29 ekohl Exp $ * */ @@ -28,6 +28,26 @@ #define RTL_QUERY_REGISTRY_DIRECT (0x00000020) #define RTL_QUERY_REGISTRY_DELETE (0x00000040) + +/* + * PURPOSE: Flags used by RtlIsTextUnicode and IsTextUnicode + */ +#define IS_TEXT_UNICODE_ASCII16 (0x00000001) +#define IS_TEXT_UNICODE_REVERSE_ASCII16 (0x00000010) +#define IS_TEXT_UNICODE_STATISTICS (0x00000002) +#define IS_TEXT_UNICODE_REVERSE_STATISTICS (0x00000020) +#define IS_TEXT_UNICODE_CONTROLS (0x00000004) +#define IS_TEXT_UNICODE_REVERSE_CONTROLS (0x00000040) +#define IS_TEXT_UNICODE_SIGNATURE (0x00000008) +#define IS_TEXT_UNICODE_REVERSE_SIGNATURE (0x00000080) +#define IS_TEXT_UNICODE_ILLEGAL_CHARS (0x00000100) +#define IS_TEXT_UNICODE_ODD_LENGTH (0x00000200) +#define IS_TEXT_UNICODE_NULL_BYTES (0x00001000) +#define IS_TEXT_UNICODE_UNICODE_MASK (0x0000000F) +#define IS_TEXT_UNICODE_REVERSE_MASK (0x000000F0) +#define IS_TEXT_UNICODE_NOT_UNICODE_MASK (0x00000F00) +#define IS_TEXT_UNICODE_NOT_ASCII_MASK (0x0000F000) + /* * VOID * InitializeObjectAttributes ( @@ -1267,6 +1287,11 @@ RtlIsNameLegalDOS8Dot3(IN PUNICODE_STRING UnicodeName, IN PANSI_STRING AnsiName, OUT PBOOLEAN SpacesFound); +ULONG STDCALL +RtlIsTextUnicode (PVOID Buffer, + ULONG Length, + ULONG *Flags); + LARGE_INTEGER STDCALL RtlLargeIntegerAdd ( diff --git a/reactos/lib/ntdll/def/ntdll.def b/reactos/lib/ntdll/def/ntdll.def index 32080f08b2d..258dd55b7b0 100644 --- a/reactos/lib/ntdll/def/ntdll.def +++ b/reactos/lib/ntdll/def/ntdll.def @@ -1,4 +1,4 @@ -; $Id: ntdll.def,v 1.93 2003/03/16 14:16:54 chorns Exp $ +; $Id: ntdll.def,v 1.94 2003/03/26 15:19:28 ekohl Exp $ ; ; ReactOS Operating System ; @@ -457,7 +457,7 @@ RtlIntegerToUnicodeString@12 RtlIsDosDeviceName_U@4 ;RtlIsGenericTableEmpty RtlIsNameLegalDOS8Dot3@12 -;RtlIsTextUnicode +RtlIsTextUnicode@12 RtlIsValidHandle@8 RtlIsValidIndexHandle@12 RtlLargeIntegerAdd@16 diff --git a/reactos/lib/ntdll/def/ntdll.edf b/reactos/lib/ntdll/def/ntdll.edf index 5d8ad4e5a35..b46e115e34a 100644 --- a/reactos/lib/ntdll/def/ntdll.edf +++ b/reactos/lib/ntdll/def/ntdll.edf @@ -1,4 +1,4 @@ -; $Id: ntdll.edf,v 1.82 2003/03/16 14:16:54 chorns Exp $ +; $Id: ntdll.edf,v 1.83 2003/03/26 15:19:28 ekohl Exp $ ; ; ReactOS Operating System ; @@ -456,7 +456,7 @@ RtlIntegerToUnicodeString=RtlIntegerToUnicodeString@12 RtlIsDosDeviceName_U=RtlIsDosDeviceName_U@4 ;RtlIsGenericTableEmpty RtlIsNameLegalDOS8Dot3=RtlIsNameLegalDOS8Dot3@12 -;RtlIsTextUnicode +RtlIsTextUnicode=RtlIsTextUnicode@12 RtlIsValidHandle=RtlIsValidHandle@8 RtlIsValidIndexHandle=RtlIsValidIndexHandle@12 RtlLargeIntegerAdd=RtlLargeIntegerAdd@16 diff --git a/reactos/lib/ntdll/rtl/unicode.c b/reactos/lib/ntdll/rtl/unicode.c index dc0e8e02011..34b99ab5dd3 100644 --- a/reactos/lib/ntdll/rtl/unicode.c +++ b/reactos/lib/ntdll/rtl/unicode.c @@ -1,4 +1,4 @@ -/* $Id: unicode.c,v 1.25 2002/12/08 15:57:39 robd Exp $ +/* $Id: unicode.c,v 1.26 2003/03/26 15:16:50 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -873,6 +873,61 @@ RtlIntegerToUnicodeString( } +#define ITU_IMPLEMENTED_TESTS (IS_TEXT_UNICODE_ODD_LENGTH|IS_TEXT_UNICODE_SIGNATURE) + +ULONG STDCALL +RtlIsTextUnicode (PVOID Buffer, + ULONG Length, + ULONG *Flags) +{ + PWSTR s = Buffer; + ULONG in_flags = (ULONG)-1; + ULONG out_flags = 0; + + if (Length == 0) + goto done; + + if (Flags != 0) + in_flags = *Flags; + + /* + * Apply various tests to the text string. According to the + * docs, each test "passed" sets the corresponding flag in + * the output flags. But some of the tests are mutually + * exclusive, so I don't see how you could pass all tests ... + */ + + /* Check for an odd length ... pass if even. */ + if (!(Length & 1)) + out_flags |= IS_TEXT_UNICODE_ODD_LENGTH; + + /* Check for the BOM (byte order mark). */ + if (*s == 0xFEFF) + out_flags |= IS_TEXT_UNICODE_SIGNATURE; + +#if 0 + /* Check for the reverse BOM (byte order mark). */ + if (*s == 0xFFFE) + out_flags |= IS_TEXT_UNICODE_REVERSE_SIGNATURE; +#endif + + /* FIXME: Add more tests */ + + /* + * Check whether the string passed all of the tests. + */ + in_flags &= ITU_IMPLEMENTED_TESTS; + if ((out_flags & in_flags) != in_flags) + Length = 0; + +done: + if (Flags != 0) + *Flags = out_flags; + + return Length; +} + + NTSTATUS STDCALL RtlLargeIntegerToChar(