mirror of
https://github.com/acidanthera/OpenCorePkg.git
synced 2025-12-08 19:25:01 +00:00
OcStringLib: Add OcAsciiStringNPrintable API
This commit is contained in:
parent
a6b49b38c0
commit
157f386959
@ -366,6 +366,20 @@ OcAsciiStrrChr (
|
||||
IN CHAR8 Char
|
||||
);
|
||||
|
||||
/**
|
||||
Check if a string up to N bytes is ASCII-printable.
|
||||
|
||||
@param[in] String String to be checked.
|
||||
@param[in] Number Number of bytes to scan.
|
||||
|
||||
@retval TRUE If String within Number bytes is all ASCII-printable.
|
||||
**/
|
||||
BOOLEAN
|
||||
OcAsciiStringNPrintable (
|
||||
IN CONST CHAR8 *String,
|
||||
IN UINTN Number
|
||||
);
|
||||
|
||||
/**
|
||||
Returns the first occurrence of a Null-terminated Unicode sub-string
|
||||
in a Null-terminated Unicode string through a case insensitive comparison.
|
||||
|
||||
@ -355,3 +355,42 @@ OcAsciiStrrChr (
|
||||
|
||||
return Save;
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
OcAsciiStringNPrintable (
|
||||
IN CONST CHAR8 *String,
|
||||
IN UINTN Number
|
||||
)
|
||||
{
|
||||
UINTN Index;
|
||||
|
||||
for (Index = 0; Index < Number; ++Index) {
|
||||
//
|
||||
// Terminate search if non-printable character is found.
|
||||
// The next IFs determine the return value.
|
||||
//
|
||||
if (!IsAsciiPrint (String[Index])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// If the loop above can be terminated without errors, Index should equal to ValueSize.
|
||||
// And this is all good.
|
||||
//
|
||||
if (Index == Number) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//
|
||||
// If the last character is not ASCII-printable but is '\0', then it is fine.
|
||||
//
|
||||
if (Index == Number - 1) {
|
||||
return String[Index] == '\0';
|
||||
}
|
||||
|
||||
//
|
||||
// Otherwise, the string is broken.
|
||||
//
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user