提交 157f3869 编写于 作者: P PMheart

OcStringLib: Add OcAsciiStringNPrintable API

上级 a6b49b38
......@@ -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;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册