Proper kernel
This commit is contained in:
61
string_utils.c
Normal file
61
string_utils.c
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "string_utils.h"
|
||||
|
||||
BOOLEAN is_space16(CHAR16 Ch)
|
||||
{
|
||||
return (Ch == L' ' || Ch == L'\t');
|
||||
}
|
||||
|
||||
CHAR16 ascii_lower16(CHAR16 Ch)
|
||||
{
|
||||
if (Ch >= L'A' && Ch <= L'Z') {
|
||||
return (CHAR16)(Ch + 32);
|
||||
}
|
||||
return Ch;
|
||||
}
|
||||
|
||||
BOOLEAN ascii_streq_ci(const CHAR16 *A, const CHAR16 *B)
|
||||
{
|
||||
if (A == NULL || B == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
while (*A != L'\0' && *B != L'\0') {
|
||||
if (ascii_lower16(*A) != ascii_lower16(*B)) {
|
||||
return FALSE;
|
||||
}
|
||||
A++;
|
||||
B++;
|
||||
}
|
||||
|
||||
return (*A == L'\0' && *B == L'\0');
|
||||
}
|
||||
|
||||
void trim_spaces_inplace(CHAR16 *Cmd)
|
||||
{
|
||||
UINTN start = 0;
|
||||
UINTN end = 0;
|
||||
UINTN i = 0;
|
||||
|
||||
if (Cmd == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (Cmd[start] != L'\0' && is_space16(Cmd[start])) {
|
||||
start++;
|
||||
}
|
||||
|
||||
end = start;
|
||||
while (Cmd[end] != L'\0') {
|
||||
end++;
|
||||
}
|
||||
|
||||
while (end > start && is_space16(Cmd[end - 1])) {
|
||||
end--;
|
||||
}
|
||||
|
||||
while (i < (end - start)) {
|
||||
Cmd[i] = Cmd[start + i];
|
||||
i++;
|
||||
}
|
||||
Cmd[i] = L'\0';
|
||||
}
|
||||
Reference in New Issue
Block a user