-
-
Save heatd/2a1b01397c64e7c5999a9610ff672cc3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Returns the first occurrence of a Null-terminated ASCII character | |
in a Null-terminated ASCII string. | |
This function scans the contents of the ASCII string specified by s | |
and returns the first occurrence of c. If c is not found in s, | |
then NULL is returned. If the length of c is zero, then s is returned. | |
@param s The pointer to a Null-terminated ASCII string. | |
@param c The pointer to a Null-terminated ASCII character to search for. | |
@retval NULL If the c does not appear in s. | |
@retval others If there is a match return the first occurrence of c. | |
If the length of c is zero,return s. | |
**/ | |
char * | |
strchr ( | |
const char *s, | |
int c | |
) | |
{ | |
char pattern[2]; | |
pattern[0] = (CHAR8)c; | |
pattern[1] = 0; | |
return AsciiStrStr (s, pattern); | |
} | |
/** | |
Returns the last occurrence of a Null-terminated ASCII character | |
in a Null-terminated ASCII string. | |
This function scans the contents of the ASCII string specified by s | |
and returns the last occurrence of c. If c is not found in s, | |
then NULL is returned. If the length of c is zero, then s is returned. | |
@param s The pointer to a Null-terminated ASCII string. | |
@param c The pointer to a Null-terminated ASCII character to search for. | |
@retval NULL If the c does not appear in s. | |
@retval others If there is a match return the last occurrence of c. | |
If the length of c is zero,return s. | |
**/ | |
char * | |
strrchr ( | |
const char *s, | |
int c | |
) | |
{ | |
char pattern[2]; | |
CONST CHAR8 *LastMatch; | |
CONST CHAR8 *StringTmp; | |
CONST CHAR8 *SearchString; | |
pattern[0] = (CHAR8)c; | |
pattern[1] = 0; | |
SearchString = pattern; | |
// | |
// Return NULL if both strings are less long than PcdMaximumAsciiStringLength | |
// | |
if ((AsciiStrSize (s) == 0) || (AsciiStrSize (SearchString) == 0)) { | |
return NULL; | |
} | |
if (*SearchString == '\0') { | |
return (CHAR8 *)s; | |
} | |
LastMatch = NULL; | |
do { | |
StringTmp = AsciiStrStr (s, SearchString); | |
if (StringTmp == NULL) { | |
break; | |
} | |
LastMatch = StringTmp; | |
s = StringTmp + 1; | |
} while (s != NULL); | |
return (CHAR8 *)LastMatch; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment