Implement RtlTrimLeftString(), RtlTrimRightString() and RtlTrimString() routines
All checks were successful
Builds / ExectOS (amd64) (push) Successful in 32s
Builds / ExectOS (i686) (push) Successful in 27s

This commit is contained in:
Rafal Kupiec 2023-12-09 20:17:08 +01:00
parent 87dceb0ba7
commit b57ee630fd
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
3 changed files with 95 additions and 0 deletions

View File

@ -131,6 +131,18 @@ RtlTokenizeWideString(IN PWCHAR String,
IN CONST PWCHAR Delimiter, IN CONST PWCHAR Delimiter,
IN OUT PWCHAR *SavePtr); IN OUT PWCHAR *SavePtr);
XTCDECL
PCHAR
RtlTrimLeftString(IN CONST PCHAR String);
XTCDECL
PCHAR
RtlTrimRightString(IN CONST PCHAR String);
XTCDECL
PCHAR
RtlTrimString(IN CONST PCHAR String);
XTCDECL XTCDECL
SIZE_T SIZE_T
RtlWideStringLength(IN CONST PWCHAR String, RtlWideStringLength(IN CONST PWCHAR String,

View File

@ -218,3 +218,83 @@ RtlStringToWideString(OUT PWCHAR Destination,
return Length - Count; return Length - Count;
} }
/**
* Removes certain characters from a beginning of the string.
*
* @param String
* Pointer to the null-terminated string to be trimmed.
*
* @return This routine returns a pointer to the left-trimmed string.
*
* @since XT 1.0
*/
XTCDECL
PCHAR
RtlTrimLeftString(IN CONST PCHAR String)
{
PCHAR Start;
/* Initialize pointer */
Start = String;
/* Skip all leading whitespaces */
while(*Start == ' ' || *Start == '\n' || *Start == '\t' || *Start == '\r' || *Start == '\v' || *Start == '\f')
{
/* Advance to the next character */
Start++;
}
/* Return left-trimmed string */
return Start;
}
/**
* Removes certain characters from the end of the string.
*
* @param String
* Pointer to the null-terminated string to be trimmed.
*
* @return This routine returns a pointer to the right-trimmed string.
*
* @since XT 1.0
*/
XTCDECL
PCHAR
RtlTrimRightString(IN CONST PCHAR String)
{
PCHAR End;
/* Find end of the string */
End = String + RtlStringLength(String, 0);
/* Skip all trailing whitespaces */
while((End != String) && (*End == ' ' || *End == '\n' || *End == '\t' || *End == '\r' || *End == '\v' || *End == '\f'))
{
/* Move to the previous character */
End--;
}
/* Terminate the string */
*End = 0;
/* Return right-trimmed string */
return String;
}
/**
* Removes certain characters from the beginning and the end of the string.
*
* @param String
* Pointer to the null-terminated string to be trimmed.
*
* @return This routine returns a pointer to the trimmed string.
*
* @since XT 1.0
*/
XTCDECL
PCHAR
RtlTrimString(IN CONST PCHAR String)
{
return RtlTrimLeftString(RtlTrimRightString(String));
}

View File

@ -40,6 +40,9 @@
@ cdecl RtlCompareWideStringInsensitive(wstr wstr long) @ cdecl RtlCompareWideStringInsensitive(wstr wstr long)
@ cdecl RtlConcatenateWideString(wstr wstr long) @ cdecl RtlConcatenateWideString(wstr wstr long)
@ cdecl RtlTokenizeWideString(wstr wstr wstr) @ cdecl RtlTokenizeWideString(wstr wstr wstr)
@ cdecl RtlTrimLeftString(str)
@ cdecl RtlTrimRightString(str)
@ cdecl RtlTrimString(str)
@ cdecl RtlWideStringLength(wstr long) @ cdecl RtlWideStringLength(wstr long)
@ stdcall RtlWriteRegisterByte(ptr long) @ stdcall RtlWriteRegisterByte(ptr long)
@ stdcall RtlWriteRegisterLong(ptr long) @ stdcall RtlWriteRegisterLong(ptr long)