2 * PROJECT: .inf file parser
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PROGRAMMER: Royce Mitchell III
6 * Ge van Geldorp <gvg@reactos.org>
9 /* INCLUDES *****************************************************************/
18 RtlMultiByteToUnicodeN(
19 IN PWCHAR UnicodeString
,
29 /* single-byte code page */
30 if (MbSize
> (UnicodeSize
/ sizeof(WCHAR
)))
31 Size
= UnicodeSize
/ sizeof(WCHAR
);
35 if (ResultSize
!= NULL
)
36 *ResultSize
= Size
* sizeof(WCHAR
);
38 WideString
= (PUCHAR
)UnicodeString
;
39 for (i
= 0; i
< Size
; i
++)
41 WideString
[2 * i
+ 0] = (UCHAR
)MbString
[i
];
42 WideString
[2 * i
+ 1] = 0;
45 return STATUS_SUCCESS
;
51 RtlIsTextUnicode( PVOID buf
, INT len
, INT
*pf
)
53 static const WCHAR std_control_chars
[] = {'\r','\n','\t',' ',0x3000,0};
54 static const WCHAR byterev_control_chars
[] = {0x0d00,0x0a00,0x0900,0x2000,0};
57 unsigned int flags
= MAXULONG
, out_flags
= 0;
59 if (len
< sizeof(WCHAR
))
61 /* FIXME: MSDN documents IS_TEXT_UNICODE_BUFFER_TOO_SMALL but there is no such thing... */
66 flags
= (unsigned int)*pf
;
68 * Apply various tests to the text string. According to the
69 * docs, each test "passed" sets the corresponding flag in
70 * the output flags. But some of the tests are mutually
71 * exclusive, so I don't see how you could pass all tests ...
74 /* Check for an odd length ... pass if even. */
75 if (len
& 1) out_flags
|= IS_TEXT_UNICODE_ODD_LENGTH
;
77 if (((char *)buf
)[len
- 1] == 0)
78 len
--; /* Windows seems to do something like that to avoid e.g. false IS_TEXT_UNICODE_NULL_BYTES */
80 len
/= (INT
)sizeof(WCHAR
);
81 /* Windows only checks the first 256 characters */
82 if (len
> 256) len
= 256;
84 /* Check for the special byte order unicode marks. */
85 if (*s
== 0xFEFF) out_flags
|= IS_TEXT_UNICODE_SIGNATURE
;
86 if (*s
== 0xFFFE) out_flags
|= IS_TEXT_UNICODE_REVERSE_SIGNATURE
;
88 /* apply some statistical analysis */
89 if (flags
& IS_TEXT_UNICODE_STATISTICS
)
92 /* FIXME: checks only for ASCII characters in the unicode stream */
93 for (i
= 0; i
< len
; i
++)
95 if (s
[i
] <= 255) stats
++;
98 out_flags
|= IS_TEXT_UNICODE_STATISTICS
;
101 /* Check for unicode NULL chars */
102 if (flags
& IS_TEXT_UNICODE_NULL_BYTES
)
104 for (i
= 0; i
< len
; i
++)
106 if (!(s
[i
] & 0xff) || !(s
[i
] >> 8))
108 out_flags
|= IS_TEXT_UNICODE_NULL_BYTES
;
114 if (flags
& IS_TEXT_UNICODE_CONTROLS
)
116 for (i
= 0; i
< len
; i
++)
118 if (strchrW(std_control_chars
, s
[i
]))
120 out_flags
|= IS_TEXT_UNICODE_CONTROLS
;
126 if (flags
& IS_TEXT_UNICODE_REVERSE_CONTROLS
)
128 for (i
= 0; i
< len
; i
++)
130 if (strchrW(byterev_control_chars
, s
[i
]))
132 out_flags
|= IS_TEXT_UNICODE_REVERSE_CONTROLS
;
140 out_flags
&= (unsigned int)*pf
;
141 *pf
= (INT
)out_flags
;
143 /* check for flags that indicate it's definitely not valid Unicode */
144 if (out_flags
& (IS_TEXT_UNICODE_REVERSE_MASK
| IS_TEXT_UNICODE_NOT_UNICODE_MASK
)) return FALSE
;
145 /* now check for invalid ASCII, and assume Unicode if so */
146 if (out_flags
& IS_TEXT_UNICODE_NOT_ASCII_MASK
) return TRUE
;
147 /* now check for Unicode flags */
148 if (out_flags
& IS_TEXT_UNICODE_UNICODE_MASK
) return TRUE
;