Extend RTL with substring search and character case functions
This commit is contained in:
parent
e4981b52ed
commit
d6999fad2f
@ -161,6 +161,26 @@ RtlFindSetBits(IN PRTL_BITMAP BitMap,
|
||||
IN ULONG_PTR Length,
|
||||
IN ULONG_PTR Index);
|
||||
|
||||
XTAPI
|
||||
PCHAR
|
||||
RtlFindString(IN PCHAR Source,
|
||||
IN PCHAR Search);
|
||||
|
||||
XTAPI
|
||||
PCHAR
|
||||
RtlFindStringInsensitive(IN PCHAR Source,
|
||||
IN PCHAR Search);
|
||||
|
||||
XTAPI
|
||||
PWCHAR
|
||||
RtlFindWideString(IN PWCHAR Source,
|
||||
IN PWCHAR Search);
|
||||
|
||||
XTAPI
|
||||
PWCHAR
|
||||
RtlFindWideStringInsensitive(IN PWCHAR Source,
|
||||
IN PWCHAR Search);
|
||||
|
||||
XTAPI
|
||||
XTSTATUS
|
||||
RtlFormatWideString(IN PRTL_PRINT_CONTEXT Context,
|
||||
@ -255,6 +275,22 @@ RtlTokenizeWideString(IN PWCHAR String,
|
||||
IN CONST PWCHAR Delimiter,
|
||||
IN OUT PWCHAR *SavePtr);
|
||||
|
||||
XTAPI
|
||||
CHAR
|
||||
RtlToLowerCharacter(IN CHAR Character);
|
||||
|
||||
XTAPI
|
||||
WCHAR
|
||||
RtlToLowerWideCharacter(IN WCHAR Character);
|
||||
|
||||
XTAPI
|
||||
CHAR
|
||||
RtlToUpperCharacter(IN CHAR Character);
|
||||
|
||||
XTAPI
|
||||
WCHAR
|
||||
RtlToUpperWideCharacter(IN WCHAR Character);
|
||||
|
||||
XTAPI
|
||||
PCHAR
|
||||
RtlTrimLeftString(IN CONST PCHAR String);
|
||||
|
@ -229,6 +229,131 @@ RtlCopyString(IN PCHAR Destination,
|
||||
Destination[Index] = '\0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the first occurrence of the search string in the source string.
|
||||
*
|
||||
* @param Source
|
||||
* Supplies a pointer to the source string.
|
||||
*
|
||||
* @param Search
|
||||
* Supplies a pointer to the search string.
|
||||
*
|
||||
* @return This routine returns a pointer to the first occurrence of the search string in the source string.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
PCHAR
|
||||
RtlFindString(IN PCHAR Source,
|
||||
IN PCHAR Search)
|
||||
{
|
||||
PCHAR CurrentSource;
|
||||
PCHAR CurrentSearch;
|
||||
|
||||
/* Validate input parameters */
|
||||
if(!Source || !Search)
|
||||
{
|
||||
/* Invalid input parameters, return NULL */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Check if search string is empty */
|
||||
if(*Search == '\0')
|
||||
{
|
||||
/* Return the source string */
|
||||
return Source;
|
||||
}
|
||||
|
||||
/* Iterate through the source string */
|
||||
for(; *Source != '\0'; Source++) {
|
||||
|
||||
/* Initialize pointers */
|
||||
CurrentSource = Source;
|
||||
CurrentSearch = Search;
|
||||
|
||||
/* Check if the substring matches starting at the current position */
|
||||
while(*CurrentSource != '\0' && *CurrentSearch != '\0' && *CurrentSource == *CurrentSearch)
|
||||
{
|
||||
/* Go to the next character */
|
||||
CurrentSource++;
|
||||
CurrentSearch++;
|
||||
}
|
||||
|
||||
/* If we reached the end of Search string, it is a match */
|
||||
if(*CurrentSearch == '\0')
|
||||
{
|
||||
/* Return the source position */
|
||||
return Source;
|
||||
}
|
||||
}
|
||||
|
||||
/* No match found, return NULL */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the first case-insensitive occurrence of the search string in the source string.
|
||||
*
|
||||
* @param Source
|
||||
* Supplies a pointer to the source string.
|
||||
*
|
||||
* @param Search
|
||||
* Supplies a pointer to the search string.
|
||||
*
|
||||
* @return This routine returns a pointer to the first occurrence of the search string in the source string.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
PCHAR
|
||||
RtlFindStringInsensitive(IN PCHAR Source,
|
||||
IN PCHAR Search)
|
||||
{
|
||||
PCHAR CurrentSource;
|
||||
PCHAR CurrentSearch;
|
||||
|
||||
/* Validate input parameters */
|
||||
if(!Source || !Search)
|
||||
{
|
||||
/* Invalid input parameters, return NULL */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Check if search string is empty */
|
||||
if(*Search == '\0')
|
||||
{
|
||||
/* Return the source string */
|
||||
return Source;
|
||||
}
|
||||
|
||||
/* Iterate through the source string */
|
||||
for(; *Source != '\0'; Source++) {
|
||||
|
||||
/* Initialize pointers */
|
||||
CurrentSource = Source;
|
||||
CurrentSearch = Search;
|
||||
|
||||
/* Check if the substring matches starting at the current position */
|
||||
while(*CurrentSource != '\0' && *CurrentSearch != '\0' &&
|
||||
RtlToLowerCharacter(*CurrentSource) == RtlToLowerCharacter(*CurrentSearch))
|
||||
{
|
||||
/* Go to the next character */
|
||||
CurrentSource++;
|
||||
CurrentSearch++;
|
||||
}
|
||||
|
||||
/* If we reached the end of Search string, it is a match */
|
||||
if(*CurrentSearch == '\0')
|
||||
{
|
||||
/* Return the source position */
|
||||
return Source;
|
||||
}
|
||||
}
|
||||
|
||||
/* No match found, return NULL */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverses a characters order in a string. It modifies the original, input variable.
|
||||
*
|
||||
@ -436,6 +561,56 @@ RtlTokenizeString(IN PCHAR String,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a character to lowercase.
|
||||
*
|
||||
* @param Character
|
||||
* Character to be converted.
|
||||
*
|
||||
* @return Converted character or original character if it was not uppercase.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
CHAR
|
||||
RtlToLowerCharacter(IN CHAR Character)
|
||||
{
|
||||
/* Check if character is uppercase */
|
||||
if(Character >= 'A' && Character <= 'Z')
|
||||
{
|
||||
/* Convert character to lowercase */
|
||||
return (CHAR)(Character + ('a' - 'A'));
|
||||
}
|
||||
|
||||
/* Return original character */
|
||||
return Character;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a character to uppercase.
|
||||
*
|
||||
* @param Character
|
||||
* Character to be converted.
|
||||
*
|
||||
* @return Converted character or original character if it was not lowercase.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
CHAR
|
||||
RtlToUpperCharacter(IN CHAR Character)
|
||||
{
|
||||
/* Check if character is lowercase */
|
||||
if(Character >= 'a' && Character <= 'z')
|
||||
{
|
||||
/* Convert character to uppercase */
|
||||
return (CHAR)(Character - ('a' - 'A'));
|
||||
}
|
||||
|
||||
/* Return original character */
|
||||
return Character;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes certain characters from a beginning of the string.
|
||||
*
|
||||
|
@ -230,6 +230,131 @@ RtlCopyWideString(IN PWCHAR Destination,
|
||||
Destination[Index] = L'\0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the first occurrence of the search wide string in the source wide string.
|
||||
*
|
||||
* @param Source
|
||||
* Supplies a pointer to the source wide string.
|
||||
*
|
||||
* @param Search
|
||||
* Supplies a pointer to the search wide string.
|
||||
*
|
||||
* @return This routine returns a pointer to the first occurrence of the search wide string in the source wide string.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
PWCHAR
|
||||
RtlFindWideString(IN PWCHAR Source,
|
||||
IN PWCHAR Search)
|
||||
{
|
||||
PWCHAR CurrentSource;
|
||||
PWCHAR CurrentSearch;
|
||||
|
||||
/* Validate input parameters */
|
||||
if(!Source || !Search)
|
||||
{
|
||||
/* Invalid input parameters, return NULL */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Check if search string is empty */
|
||||
if(*Search == L'\0')
|
||||
{
|
||||
/* Return the source string */
|
||||
return Source;
|
||||
}
|
||||
|
||||
/* Iterate through the source string */
|
||||
for(; *Source != L'\0'; Source++) {
|
||||
|
||||
/* Initialize pointers */
|
||||
CurrentSource = Source;
|
||||
CurrentSearch = Search;
|
||||
|
||||
/* Check if the substring matches starting at the current position */
|
||||
while(*CurrentSource != L'\0' && *CurrentSearch != L'\0' && *CurrentSource == *CurrentSearch)
|
||||
{
|
||||
/* Go to the next character */
|
||||
CurrentSource++;
|
||||
CurrentSearch++;
|
||||
}
|
||||
|
||||
/* If we reached the end of Search string, it is a match */
|
||||
if(*CurrentSearch == L'\0')
|
||||
{
|
||||
/* Return the source position */
|
||||
return Source;
|
||||
}
|
||||
}
|
||||
|
||||
/* No match found, return NULL */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the first case-insensitive occurrence of the search wide string in the source wide string.
|
||||
*
|
||||
* @param Source
|
||||
* Supplies a pointer to the source wide string.
|
||||
*
|
||||
* @param Search
|
||||
* Supplies a pointer to the search wide string.
|
||||
*
|
||||
* @return This routine returns a pointer to the first occurrence of the search wide string in the source wide string.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
PWCHAR
|
||||
RtlFindWideStringInsensitive(IN PWCHAR Source,
|
||||
IN PWCHAR Search)
|
||||
{
|
||||
PWCHAR CurrentSource;
|
||||
PWCHAR CurrentSearch;
|
||||
|
||||
/* Validate input parameters */
|
||||
if(!Source || !Search)
|
||||
{
|
||||
/* Invalid input parameters, return NULL */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Check if search string is empty */
|
||||
if(*Search == L'\0')
|
||||
{
|
||||
/* Return the source string */
|
||||
return Source;
|
||||
}
|
||||
|
||||
/* Iterate through the source string */
|
||||
for(; *Source != L'\0'; Source++) {
|
||||
|
||||
/* Initialize pointers */
|
||||
CurrentSource = Source;
|
||||
CurrentSearch = Search;
|
||||
|
||||
/* Check if the substring matches starting at the current position */
|
||||
while(*CurrentSource != L'\0' && *CurrentSearch != L'\0' &&
|
||||
RtlToLowerWideCharacter(*CurrentSource) == RtlToLowerWideCharacter(*CurrentSearch))
|
||||
{
|
||||
/* Go to the next character */
|
||||
CurrentSource++;
|
||||
CurrentSearch++;
|
||||
}
|
||||
|
||||
/* If we reached the end of Search string, it is a match */
|
||||
if(*CurrentSearch == L'\0')
|
||||
{
|
||||
/* Return the source position */
|
||||
return Source;
|
||||
}
|
||||
}
|
||||
|
||||
/* No match found, return NULL */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a wide string according to the given printf-alike format string.
|
||||
*
|
||||
@ -410,6 +535,56 @@ RtlTokenizeWideString(IN PWCHAR String,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a wide character to lowercase.
|
||||
*
|
||||
* @param Character
|
||||
* Wide character to be converted.
|
||||
*
|
||||
* @return Converted wide character or original character if it was not uppercase.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
WCHAR
|
||||
RtlToLowerWideCharacter(IN WCHAR Character)
|
||||
{
|
||||
/* Check if wide character is uppercase */
|
||||
if(Character >= L'A' && Character <= L'Z')
|
||||
{
|
||||
/* Convert wide character to lowercase */
|
||||
return (WCHAR)(Character + (L'a' - L'A'));
|
||||
}
|
||||
|
||||
/* Return original wide character */
|
||||
return Character;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a wide character to uppercase.
|
||||
*
|
||||
* @param Character
|
||||
* Wide character to be converted.
|
||||
*
|
||||
* @return Converted wide character or original character if it was not lowercase.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
WCHAR
|
||||
RtlToUpperWideCharacter(IN WCHAR Character)
|
||||
{
|
||||
/* Check if wide character is lowercase */
|
||||
if(Character >= L'a' && Character <= L'z')
|
||||
{
|
||||
/* Convert wide character to uppercase */
|
||||
return (WCHAR)(Character - (L'a' - L'A'));
|
||||
}
|
||||
|
||||
/* Return original wide character */
|
||||
return Character;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes certain characters from a beginning of the wide string.
|
||||
*
|
||||
|
@ -55,6 +55,10 @@
|
||||
@ stdcall RtlDivideLargeInteger(long long long ptr)
|
||||
@ stdcall RtlFindClearBits(ptr long long)
|
||||
@ stdcall RtlFindSetBits(ptr long long)
|
||||
@ stdcall RtlFindString(str str)
|
||||
@ stdcall RtlFindStringInsensitive(str str)
|
||||
@ stdcall RtlFindWideString(wstr wstr)
|
||||
@ stdcall RtlFindWideStringInsensitive(wstr wstr)
|
||||
@ stdcall RtlInitializeBitMap(ptr ptr long)
|
||||
@ stdcall RtlMoveMemory(ptr ptr long)
|
||||
@ stdcall RtlMultiplyLargeInteger(long long long)
|
||||
@ -74,6 +78,10 @@
|
||||
@ stdcall RtlTestBit(ptr long)
|
||||
@ stdcall RtlTokenizeString(str str str)
|
||||
@ stdcall RtlTokenizeWideString(wstr wstr wstr)
|
||||
@ stdcall RtlToLowerCharacter(long)
|
||||
@ stdcall RtlToLowerWideCharacter(long)
|
||||
@ stdcall RtlToUpperCharacter(long)
|
||||
@ stdcall RtlToUpperWideCharacter(long)
|
||||
@ stdcall RtlTrimLeftString(str)
|
||||
@ stdcall RtlTrimLeftWideString(wstr)
|
||||
@ stdcall RtlTrimRightString(str)
|
||||
|
Loading…
x
Reference in New Issue
Block a user