Extend RTL with substring search and character case functions
All checks were successful
Builds / ExectOS (amd64, debug) (push) Successful in 29s
Builds / ExectOS (amd64, release) (push) Successful in 34s
Builds / ExectOS (i686, release) (push) Successful in 32s
Builds / ExectOS (i686, debug) (push) Successful in 29s

This commit is contained in:
2025-09-02 21:51:10 +02:00
parent e4981b52ed
commit d6999fad2f
4 changed files with 394 additions and 0 deletions

View File

@@ -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.
*