Implement RtlWideStringCompare() and RtlWideStringTokenize() routines
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
This commit is contained in:
parent
ba1efee47e
commit
3f372f19e3
@ -9,7 +9,8 @@ include_directories(
|
||||
# Specify list of source code files
|
||||
list(APPEND XTKLIB_SOURCE
|
||||
${XTKLIB_SOURCE_DIR}/hl/cport.c
|
||||
${XTKLIB_SOURCE_DIR}/hl/${ARCH}/cpufunc.c)
|
||||
${XTKLIB_SOURCE_DIR}/hl/${ARCH}/cpufunc.c
|
||||
${XTKLIB_SOURCE_DIR}/rtl/widestr.c)
|
||||
|
||||
# Add library
|
||||
add_library(xtklib ${XTKLIB_SOURCE})
|
||||
|
26
sdk/xtklib/includes/librtl.h
Normal file
26
sdk/xtklib/includes/librtl.h
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: sdk/xtklib/includes/librtl.h
|
||||
* DESCRIPTION: Kernel mode runtime library
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#ifndef __XTKLIB_LIBRTL_H
|
||||
#define __XTKLIB_LIBRTL_H
|
||||
|
||||
#include "xtdefs.h"
|
||||
#include "xttypes.h"
|
||||
|
||||
|
||||
UINT64
|
||||
RtlWideStringCompare(IN CONST PWCHAR String1,
|
||||
IN CONST PWCHAR String2,
|
||||
IN CONST ULONG Length);
|
||||
|
||||
PWCHAR
|
||||
RtlWideStringTokenize(IN PWCHAR String,
|
||||
IN CONST PWCHAR Delimiter,
|
||||
IN OUT PWCHAR *SavePtr);
|
||||
|
||||
#endif /* __XTKLIB_LIBRTL_H */
|
@ -7,3 +7,4 @@
|
||||
*/
|
||||
|
||||
#include "libhl.h"
|
||||
#include "librtl.h"
|
||||
|
122
sdk/xtklib/rtl/widestr.c
Normal file
122
sdk/xtklib/rtl/widestr.c
Normal file
@ -0,0 +1,122 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: sdk/xtrtlib/widestr.c
|
||||
* DESCRIPTION: Wide string support
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include "xtkmapi.h"
|
||||
|
||||
|
||||
/**
|
||||
* Compares at most specified number of characters of two C wide strings.
|
||||
*
|
||||
* @param String1
|
||||
* Wide string to be compared.
|
||||
*
|
||||
* @param String2
|
||||
* Wide string to be compared.
|
||||
*
|
||||
* @param Length
|
||||
* Maximum number of characters to compare.
|
||||
*
|
||||
* @return Integral value indicating the relationship between the wide strings.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
UINT64
|
||||
RtlWideStringCompare(IN CONST PWCHAR String1,
|
||||
IN CONST PWCHAR String2,
|
||||
IN CONST ULONG Length)
|
||||
{
|
||||
UINT64 Index;
|
||||
|
||||
/* Iterate through the strings */
|
||||
for(Index = 0; Index < Length; Index++) {
|
||||
/* Check if string characters are equal */
|
||||
if(String1[Index] != String2[Index])
|
||||
{
|
||||
/* Different characters found */
|
||||
return String1[Index] < String2[Index] ? -1 : 1;
|
||||
}
|
||||
|
||||
/* Check if end of string reached */
|
||||
if(!String1[Index])
|
||||
{
|
||||
/* Equal strings until the end of String1 */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Strings are equal */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Finds the next token in a null-terminated wide string.
|
||||
*
|
||||
* @param String
|
||||
* Pointer to the null-terminated wide string to tokenize.
|
||||
*
|
||||
* @param Delimiter
|
||||
* Pointer to the null-terminated wide string identifying delimiters.
|
||||
*
|
||||
* @param SavePtr
|
||||
* Pointer to an object used to store routine internal state.
|
||||
*
|
||||
* @return Pointer to the beginning of the next token or NULL if there are no more tokens.
|
||||
*
|
||||
* @since: XT 1.0
|
||||
*/
|
||||
PWCHAR
|
||||
RtlWideStringTokenize(IN PWCHAR String,
|
||||
IN CONST PWCHAR Delimiter,
|
||||
IN OUT PWCHAR *SavePtr)
|
||||
{
|
||||
WCHAR *Span, *Token;
|
||||
UINT64 Char, SpanChar;
|
||||
|
||||
/* Check if there is anything to tokenize */
|
||||
if(String == NULL && (String = *SavePtr) == NULL)
|
||||
{
|
||||
/* Empty string given */
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Check non-delimiter characters */
|
||||
Char = *String++;
|
||||
if(Char == L'\0')
|
||||
{
|
||||
*SavePtr = NULL;
|
||||
return (NULL);
|
||||
}
|
||||
Token = String - 1;
|
||||
|
||||
/* Scan token for delimiters */
|
||||
for(;;)
|
||||
{
|
||||
Char = *String++;
|
||||
Span = (WCHAR *)Delimiter;
|
||||
do
|
||||
{
|
||||
if((SpanChar = *Span++) == Char)
|
||||
{
|
||||
if(Char == L'\0')
|
||||
{
|
||||
String = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
String[-1] = L'\0';
|
||||
}
|
||||
/* Store pointer to the next token */
|
||||
*SavePtr = String;
|
||||
|
||||
/* Return token */
|
||||
return Token;
|
||||
}
|
||||
}
|
||||
while(SpanChar != L'\0');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user