summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
b2d43cc)
- Rewrite RtlFindCharInUnicodeString. Fixes timeout in ntdll:rtlstr test.
svn path=/trunk/; revision=54091
NTAPI
RtlFindCharInUnicodeString(
IN ULONG Flags,
NTAPI
RtlFindCharInUnicodeString(
IN ULONG Flags,
- IN PUNICODE_STRING SearchString,
+ IN PCUNICODE_STRING SearchString,
IN PCUNICODE_STRING MatchString,
OUT PUSHORT Position
);
IN PCUNICODE_STRING MatchString,
OUT PUSHORT Position
);
//
// RtlFindCharInUnicodeString Flags
//
//
// RtlFindCharInUnicodeString Flags
//
+#define RTL_FIND_CHAR_IN_UNICODE_STRING_START_AT_END 1
+#define RTL_FIND_CHAR_IN_UNICODE_STRING_COMPLEMENT_CHAR_SET 2
#define RTL_FIND_CHAR_IN_UNICODE_STRING_CASE_INSENSITIVE 4
//
#define RTL_FIND_CHAR_IN_UNICODE_STRING_CASE_INSENSITIVE 4
//
return STATUS_NOT_IMPLEMENTED;
}
return STATUS_NOT_IMPLEMENTED;
}
+static
+BOOLEAN
+RtlpIsCharInUnicodeString(
+ IN WCHAR Char,
+ IN PCUNICODE_STRING MatchString,
+ IN BOOLEAN CaseInSensitive)
+{
+ USHORT i;
+
+ if (CaseInSensitive)
+ Char = RtlUpcaseUnicodeChar(Char);
+
+ for (i = 0; i < MatchString->Length / sizeof(WCHAR); i++)
+ {
+ WCHAR OtherChar = MatchString->Buffer[i];
+ if (CaseInSensitive)
+ OtherChar = RtlUpcaseUnicodeChar(OtherChar);
+
+ if (Char == OtherChar)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
NTAPI
RtlFindCharInUnicodeString(
IN ULONG Flags,
NTAPI
RtlFindCharInUnicodeString(
IN ULONG Flags,
- IN PUNICODE_STRING SearchString,
+ IN PCUNICODE_STRING SearchString,
IN PCUNICODE_STRING MatchString,
OUT PUSHORT Position)
{
IN PCUNICODE_STRING MatchString,
OUT PUSHORT Position)
{
+ BOOLEAN Found;
+ const BOOLEAN WantToFind = (Flags & RTL_FIND_CHAR_IN_UNICODE_STRING_COMPLEMENT_CHAR_SET) == 0;
+ const BOOLEAN CaseInSensitive = (Flags & RTL_FIND_CHAR_IN_UNICODE_STRING_CASE_INSENSITIVE) != 0;
+ INT Length;
+ INT i;
- switch (Flags)
- {
- case 0:
- {
- for (i = 0; i < SearchString->Length / sizeof(WCHAR); i++)
- {
- for (j = 0; j < MatchString->Length / sizeof(WCHAR); j++)
- {
- if (SearchString->Buffer[i] == MatchString->Buffer[j])
- {
- *Position = (i + 1) * sizeof(WCHAR);
- return STATUS_SUCCESS;
- }
- }
- }
+ DPRINT("RtlFindCharInUnicodeString(%u, '%wZ', '%wZ', %p)\n",
+ Flags, SearchString, MatchString, Position);
- *Position = 0;
- return STATUS_NOT_FOUND;
- }
+ /* Parameter checks */
+ if (Position == NULL)
+ return STATUS_INVALID_PARAMETER;
- case 1:
- {
- for (i = SearchString->Length / sizeof(WCHAR) - 1; (i + 1) > 0; i--)
- {
- for (j = 0; j < MatchString->Length / sizeof(WCHAR); j++)
- {
- if (SearchString->Buffer[i] == MatchString->Buffer[j])
- {
- *Position = i * sizeof(WCHAR);
- return STATUS_SUCCESS;
- }
- }
- }
- *Position = 0;
- return STATUS_NOT_FOUND;
- }
+ if (Flags & ~(RTL_FIND_CHAR_IN_UNICODE_STRING_START_AT_END |
+ RTL_FIND_CHAR_IN_UNICODE_STRING_COMPLEMENT_CHAR_SET |
+ RTL_FIND_CHAR_IN_UNICODE_STRING_CASE_INSENSITIVE))
+ return STATUS_INVALID_PARAMETER;
+ /* Search */
+ Length = SearchString->Length / sizeof(WCHAR);
+ if (Flags & RTL_FIND_CHAR_IN_UNICODE_STRING_START_AT_END)
+ {
+ for (i = Length - 1; i >= 0; i--)
- for (i = 0; i < SearchString->Length / sizeof(WCHAR); i++)
+ Found = RtlpIsCharInUnicodeString(SearchString->Buffer[i], MatchString, CaseInSensitive);
+ if (Found == WantToFind)
- j = 0;
-
- while (j < MatchString->Length / sizeof(WCHAR) &&
- SearchString->Buffer[i] != MatchString->Buffer[j])
- {
- j++;
- }
-
- if (j >= MatchString->Length / sizeof(WCHAR))
- {
- *Position = (i + 1) * sizeof(WCHAR);
- return STATUS_SUCCESS;
- }
+ *Position = i * sizeof(WCHAR);
+ return STATUS_SUCCESS;
-
- *Position = 0;
- return STATUS_NOT_FOUND;
+ }
+ else
+ {
+ for (i = 0; i < Length; i++)
- for (i = SearchString->Length / sizeof(WCHAR) - 1; (i + 1) > 0; i--)
+ Found = RtlpIsCharInUnicodeString(SearchString->Buffer[i], MatchString, CaseInSensitive);
+ if (Found == WantToFind)
- j = 0;
-
- while (j < MatchString->Length / sizeof(WCHAR) &&
- SearchString->Buffer[i] != MatchString->Buffer[j])
- {
- j++;
- }
-
- if (j >= MatchString->Length / sizeof(WCHAR))
- {
- *Position = i * sizeof(WCHAR);
- return STATUS_SUCCESS;
- }
+ *Position = (i + 1) * sizeof(WCHAR);
+ return STATUS_SUCCESS;
-
- *Position = 0;
- return STATUS_NOT_FOUND;