X-Git-Url: https://code.delx.au/refind/blobdiff_plain/bdcf7904f98139ec9e632669cd43005ca527d11c..0864ac754bdb02cb63e8d2323a2ad6b081fdc612:/refind/mystrings.c diff --git a/refind/mystrings.c b/refind/mystrings.c index a5c5823..ca7a6a1 100644 --- a/refind/mystrings.c +++ b/refind/mystrings.c @@ -267,6 +267,19 @@ CHAR16 *FindNumbers(IN CHAR16 *InString) { return (Found); } // CHAR16 *FindNumbers() +// Returns the number of characters that are in common between +// String1 and String2 before they diverge. For instance, if +// String1 is "FooBar" and String2 is "FoodiesBar", this function +// will return "3", since they both start with "Foo". +UINTN NumCharsInCommon(IN CHAR16* String1, IN CHAR16* String2) { + UINTN Count = 0; + if ((String1 == NULL) || (String2 == NULL)) + return 0; + while ((String1[Count] != L'\0') && (String2[Count] != L'\0') && (String1[Count] == String2[Count])) + Count++; + return Count; +} // UINTN NumCharsInCommon() + // Find the #Index element (numbered from 0) in a comma-delimited string // of elements. // Returns the found element, or NULL if Index is out of range or InString @@ -335,6 +348,29 @@ BOOLEAN IsInSubstring(IN CHAR16 *BigString, IN CHAR16 *List) { return Found; } // BOOLEAN IsSubstringIn() +// Replace *SearchString in **MainString with *ReplString. +// Returns TRUE if replacement was done, FALSE otherwise. +BOOLEAN ReplaceSubstring(IN OUT CHAR16 **MainString, IN CHAR16 *SearchString, IN CHAR16 *ReplString) { + BOOLEAN WasReplaced = FALSE; + CHAR16 *FoundSearchString, *NewString, *EndString; + + FoundSearchString = MyStrStr(*MainString, SearchString); + if (FoundSearchString) { + NewString = AllocateZeroPool(sizeof(CHAR16) * StrLen(*MainString)); + if (NewString) { + EndString = &(FoundSearchString[StrLen(SearchString)]); + FoundSearchString[0] = L'\0'; + StrCpy(NewString, *MainString); + MergeStrings(&NewString, ReplString, L'\0'); + MergeStrings(&NewString, EndString, L'\0'); + MyFreePool(MainString); + *MainString = NewString; + WasReplaced = TRUE; + } // if + } // if + return WasReplaced; +} // BOOLEAN ReplaceSubstring() + // Returns TRUE if *Input contains nothing but valid hexadecimal characters, // FALSE otherwise. Note that a leading "0x" is NOT acceptable in the input! BOOLEAN IsValidHex(CHAR16 *Input) { @@ -456,3 +492,15 @@ EFI_GUID StringAsGuid(CHAR16 * InString) { return Guid; } // EFI_GUID StringAsGuid() + +// Delete the STRING_LIST pointed to by *StringList. +VOID DeleteStringList(STRING_LIST *StringList) { + STRING_LIST *Current = StringList, *Previous; + + while (Current != NULL) { + MyFreePool(Current->Value); + Previous = Current; + Current = Current->Next; + MyFreePool(Previous); + } +} // VOID DeleteStringList()