From 5c8f4735412dc35cfbbec2ef2d4fb357c377a517 Mon Sep 17 00:00:00 2001 From: PMheart <17109513+PMheart@users.noreply.github.com> Date: Fri, 11 Dec 2020 18:12:14 +0800 Subject: [PATCH] OcStringLib: Add OcAsciiStriStr API --- Include/Acidanthera/Library/OcStringLib.h | 32 ++++++++++++++++++ Library/OcStringLib/OcAsciiLib.c | 41 +++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/Include/Acidanthera/Library/OcStringLib.h b/Include/Acidanthera/Library/OcStringLib.h index ccc0c6bb..b69a5dde 100755 --- a/Include/Acidanthera/Library/OcStringLib.h +++ b/Include/Acidanthera/Library/OcStringLib.h @@ -234,6 +234,38 @@ OcStrniCmp ( IN UINTN Length ); +/** + Returns the first occurrence of a Null-terminated ASCII sub-string + in a Null-terminated ASCII string through a case insensitive comparison. + + This function scans the contents of the Null-terminated ASCII string + specified by String and returns the first occurrence of SearchString. + If SearchString is not found in String, then NULL is returned. If + 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 + characters, not including the Null-terminator, then ASSERT(). + + @param String The pointer to a Null-terminated ASCII string. + @param SearchString The pointer to a Null-terminated ASCII string to search for. + + @retval NULL If the SearchString does not appear in String. + @return others If there is a match. + +**/ +CHAR8 * +EFIAPI +OcAsciiStriStr ( + IN CONST CHAR8 *String, + IN CONST CHAR8 *SearchString + ); + /** Returns the first occurrence of a Null-terminated Unicode sub-string in a Null-terminated Unicode string through a case insensitive comparison. diff --git a/Library/OcStringLib/OcAsciiLib.c b/Library/OcStringLib/OcAsciiLib.c index 671c722e..41eb5fd7 100755 --- a/Library/OcStringLib/OcAsciiLib.c +++ b/Library/OcStringLib/OcAsciiLib.c @@ -206,3 +206,44 @@ OcAsciiEndsWith ( return StringLength >= SearchStringLength && AsciiStrnCmp (&String[StringLength - SearchStringLength], SearchString, SearchStringLength) == 0; } + +CHAR8 * +EFIAPI +OcAsciiStriStr ( + IN CONST CHAR8 *String, + IN CONST CHAR8 *SearchString + ) +{ + CONST CHAR8 *FirstMatch; + CONST CHAR8 *SearchStringTmp; + + ASSERT (AsciiStrSize (String) != 0); + ASSERT (AsciiStrSize (SearchString) != 0); + + if (*SearchString == '\0') { + return (CHAR8 *) String; + } + + while (*String != '\0') { + SearchStringTmp = SearchString; + FirstMatch = String; + + while ((AsciiCharToUpper (*String) == AsciiCharToUpper (*SearchStringTmp)) + && (*String != '\0')) { + String++; + SearchStringTmp++; + } + + if (*SearchStringTmp == '\0') { + return (CHAR8 *) FirstMatch; + } + + if (*String == '\0') { + return NULL; + } + + String = FirstMatch + 1; + } + + return NULL; +}