OUT CHAR16 **String\r
)\r
{\r
- UINT8 StrNum;\r
- UINTN CurrentStrLen;\r
- CHAR8* CharInStr;\r
- EFI_STATUS Status;\r
+ UINTN StrSize;\r
\r
- StrNum = 0;\r
- Status = EFI_NOT_FOUND;\r
- CharInStr = OptionalStrStart;\r
+ if (Index == 0) {\r
+ *String = AllocateZeroPool (sizeof (CHAR16));\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ StrSize = 0;\r
+ do {\r
+ Index--;\r
+ OptionalStrStart += StrSize;\r
+ StrSize = AsciiStrSize (OptionalStrStart);\r
+ } while (OptionalStrStart[StrSize] != 0 && Index != 0);\r
\r
- if (Index != 1) {\r
- CurrentStrLen = 0;\r
+ if ((Index != 0) || (StrSize == 1)) {\r
//\r
- // look for the two consecutive zeros, check the string limit by the way.\r
+ // Meet the end of strings set but Index is non-zero, or\r
+ // Find an empty string\r
//\r
- while (*CharInStr != 0 || *(CharInStr+1) != 0) { \r
- if (*CharInStr == 0) {\r
- StrNum += 1;\r
- CharInStr++;\r
- }\r
- \r
- if (StrNum == Index) {\r
- Status = EFI_SUCCESS;\r
- break;\r
- }\r
- \r
- CurrentStrLen = AsciiStrLen(CharInStr);\r
- \r
- //\r
- // forward the pointer\r
- //\r
- OptionalStrStart = CharInStr;\r
- CharInStr += CurrentStrLen;\r
- }\r
- \r
- if (EFI_ERROR (Status)) {\r
- *String = GetStringById (STRING_TOKEN (STR_MISSING_STRING));\r
- return Status;\r
- }\r
+ *String = GetStringById (STRING_TOKEN (STR_MISSING_STRING));\r
} else {\r
- CurrentStrLen = AsciiStrLen(CharInStr);\r
+ *String = AllocatePool (StrSize * sizeof (CHAR16));\r
+ AsciiStrToUnicodeStr (OptionalStrStart, *String);\r
}\r
\r
- *String = AllocatePool((CurrentStrLen + 1)*sizeof(CHAR16));\r
- AsciiStrToUnicodeStr(OptionalStrStart, *String);\r
-\r
return EFI_SUCCESS;\r
}\r
\r