OcStringLib: Add OcAsciiStrChr and OcAsciiStrrChr API

This commit is contained in:
PMheart 2020-12-13 21:42:47 +08:00
parent a11df6c574
commit cc1ba529c1
2 changed files with 96 additions and 2 deletions

View File

@ -255,9 +255,7 @@ OcStrniCmp (
the length of SearchString is zero, then String is returned.
If String is NULL, then ASSERT().
If String is not aligned on a 8-bit boundary, then ASSERT().
If SearchString is NULL, then ASSERT().
If SearchString is not aligned on a 8-bit boundary, then ASSERT().
If PcdMaximumAsciiStringLength is not zero, and SearchString
or String contains more than PcdMaximumAsciiStringLength ASCII
@ -277,6 +275,52 @@ OcAsciiStriStr (
IN CONST CHAR8 *SearchString
);
/**
Returns a pointer to the first occurrence of Char
in a Null-terminated ASCII string.
If String is NULL, then ASSERT().
If PcdMaximumAsciiStringLength is not zero, and String
contains more than PcdMaximumAsciiStringLength ASCII
characters, not including the Null-terminator, then ASSERT().
@param String The pointer to a Null-terminated ASCII string.
@param Char Character to be located.
@return A pointer to the first occurrence of Char in String.
@retval NULL If Char cannot be found in String.
**/
CHAR8 *
EFIAPI
OcAsciiStrChr (
IN CONST CHAR8 *String,
IN CHAR8 Char
);
/**
Returns a pointer to the last occurrence of Char
in a Null-terminated ASCII string.
If String is NULL, then ASSERT().
If PcdMaximumAsciiStringLength is not zero, and String
contains more than PcdMaximumAsciiStringLength ASCII
characters, not including the Null-terminator, then ASSERT().
@param String The pointer to a Null-terminated ASCII string.
@param Char Character to be located.
@return A pointer to the last occurrence of Char in String.
@retval NULL If Char cannot be found in String.
**/
CHAR8 *
EFIAPI
OcAsciiStrrChr (
IN CONST CHAR8 *String,
IN CHAR8 Char
);
/**
Returns the first occurrence of a Null-terminated Unicode sub-string
in a Null-terminated Unicode string through a case insensitive comparison.

View File

@ -262,3 +262,53 @@ OcAsciiStriStr (
return NULL;
}
CHAR8 *
EFIAPI
OcAsciiStrChr (
IN CONST CHAR8 *String,
IN CHAR8 Char
)
{
ASSERT (AsciiStrSize (String) != 0);
while (*String != '\0') {
//
// Return immediately when matching first occurrence of Char.
//
if (*String == Char) {
return (CHAR8 *) String;
}
++String;
}
return NULL;
}
CHAR8 *
EFIAPI
OcAsciiStrrChr (
IN CONST CHAR8 *String,
IN CHAR8 Char
)
{
CHAR8 *Save;
ASSERT (AsciiStrSize (String) != 0);
Save = NULL;
while (*String != '\0') {
//
// Record the last occurrence of Char.
//
if (*String == Char) {
Save = (CHAR8 *) String;
}
++String;
}
return Save;
}