-BOOLEAN StriSubCmp(IN CHAR16 *SmallStr, IN CHAR16 *BigStr) {
- BOOLEAN Found = 0, Terminate = 0;
- UINTN BigIndex = 0, SmallIndex = 0, BigStart = 0;
-
- if (SmallStr && BigStr) {
- while (!Terminate) {
- if (BigStr[BigIndex] == '\0') {
- Terminate = 1;
- }
- if (SmallStr[SmallIndex] == '\0') {
- Found = 1;
- Terminate = 1;
- }
- if ((SmallStr[SmallIndex] & ~0x20) == (BigStr[BigIndex] & ~0x20)) {
- SmallIndex++;
- BigIndex++;
- } else {
- SmallIndex = 0;
- BigStart++;
- BigIndex = BigStart;
- }
- } // while
- } // if
- return Found;
-} // BOOLEAN StriSubCmp()
-
-// Performs a case-insensitive string comparison. This function is necesary
-// because some EFIs have buggy StriCmp() functions that actually perform
-// case-sensitive comparisons.
-// Returns TRUE if strings are identical, FALSE otherwise.
-BOOLEAN MyStriCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString) {
- if (FirstString && SecondString) {
- while ((*FirstString != L'\0') && ((*FirstString & ~0x20) == (*SecondString & ~0x20))) {
- FirstString++;
- SecondString++;
- }
- return (*FirstString == *SecondString);
- } else {
- return FALSE;
- }
-} // BOOLEAN MyStriCmp()
-
-// Convert input string to all-lowercase.
-// DO NOT USE the standard StrLwr() function, since it's broken on some EFIs!
-VOID ToLower(CHAR16 * MyString) {
- UINTN i = 0;
-
- if (MyString) {
- while (MyString[i] != L'\0') {
- if ((MyString[i] >= L'A') && (MyString[i] <= L'Z'))
- MyString[i] = MyString[i] - L'A' + L'a';
- i++;
- } // while
- } // if
-} // VOID ToLower()
-
-// Merges two strings, creating a new one and returning a pointer to it.
-// If AddChar != 0, the specified character is placed between the two original
-// strings (unless the first string is NULL or empty). The original input
-// string *First is de-allocated and replaced by the new merged string.
-// This is similar to StrCat, but safer and more flexible because
-// MergeStrings allocates memory that's the correct size for the
-// new merged string, so it can take a NULL *First and it cleans
-// up the old memory. It should *NOT* be used with a constant
-// *First, though....
-VOID MergeStrings(IN OUT CHAR16 **First, IN CHAR16 *Second, CHAR16 AddChar) {
- UINTN Length1 = 0, Length2 = 0;
- CHAR16* NewString;
-
- if (*First != NULL)
- Length1 = StrLen(*First);
- if (Second != NULL)
- Length2 = StrLen(Second);
- NewString = AllocatePool(sizeof(CHAR16) * (Length1 + Length2 + 2));
- if (NewString != NULL) {
- if ((*First != NULL) && (Length1 == 0)) {
- MyFreePool(*First);
- *First = NULL;
- }
- NewString[0] = L'\0';
- if (*First != NULL) {
- StrCat(NewString, *First);
- if (AddChar) {
- NewString[Length1] = AddChar;
- NewString[Length1 + 1] = '\0';
- } // if (AddChar)
- } // if (*First != NULL)
- if (Second != NULL)
- StrCat(NewString, Second);
- MyFreePool(*First);
- *First = NewString;
- } else {
- Print(L"Error! Unable to allocate memory in MergeStrings()!\n");
- } // if/else
-} // VOID MergeStrings()
-
-// Similar to MergeStrings, but breaks the input string into word chunks and
-// merges each word separately. Words are defined as string fragments separated
-// by ' ', '_', or '-'.
-VOID MergeWords(CHAR16 **MergeTo, CHAR16 *SourceString, CHAR16 AddChar) {
- CHAR16 *Temp, *Word, *p;
- BOOLEAN LineFinished = FALSE;
-
- if (SourceString) {
- Temp = Word = p = StrDuplicate(SourceString);
- if (Temp) {
- while (!LineFinished) {
- if ((*p == L' ') || (*p == L'_') || (*p == L'-') || (*p == L'\0')) {
- if (*p == L'\0')
- LineFinished = TRUE;
- *p = L'\0';
- if (*Word != L'\0')
- MergeStrings(MergeTo, Word, AddChar);
- Word = p + 1;
- } // if
- p++;
- } // while
- MyFreePool(Temp);
- } else {
- Print(L"Error! Unable to allocate memory in MergeWords()!\n");
- } // if/else
- } // if
-} // VOID MergeWords()
-