ShellPkg: Refactor Split search to generic function

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <Jaben.carsey@intel.com>
Signed-off-by: Joe Peterson <joe.peterson@intel.com>
Reviewed-by: Shumin Qiu <shumin.qiu@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hp.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16681 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Jaben Carsey
2015-01-30 16:28:22 +00:00
committed by jcarsey
parent a35ecb7584
commit 00534bc3e2
2 changed files with 56 additions and 31 deletions

View File

@ -189,33 +189,6 @@ IsValidEnvironmentVariableName(
return TRUE;
}
/**
Find a command line contains a split operation
@param[in] CmdLine The command line to parse.
@retval A pointer to the | character in CmdLine or NULL if not present.
**/
CONST CHAR16*
EFIAPI
FindSplit(
IN CONST CHAR16 *CmdLine
)
{
CONST CHAR16 *TempSpot;
TempSpot = NULL;
if (StrStr(CmdLine, L"|") != NULL) {
for (TempSpot = CmdLine ; TempSpot != NULL && *TempSpot != CHAR_NULL ; TempSpot++) {
if (*TempSpot == L'^' && *(TempSpot+1) == L'|') {
TempSpot++;
} else if (*TempSpot == L'|') {
break;
}
}
}
return (TempSpot);
}
/**
Determine if a command line contains a split operation
@ -236,7 +209,7 @@ ContainsSplit(
FirstQuote = FindNextInstance (CmdLine, L"\"", TRUE);
SecondQuote = NULL;
TempSpot = FindSplit(CmdLine);
TempSpot = FindFirstCharacter(CmdLine, L"|", L'^');
if (FirstQuote == NULL ||
TempSpot == NULL ||
@ -259,7 +232,7 @@ ContainsSplit(
continue;
} else {
FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);
TempSpot = FindSplit(TempSpot + 1);
TempSpot = FindFirstCharacter(TempSpot + 1, L"|", L'^');
continue;
}
}
@ -1919,7 +1892,7 @@ VerifySplit(
//
// recurse to verify the next item
//
TempSpot = FindSplit(CmdLine)+1;
TempSpot = FindFirstCharacter(CmdLine, L"|", L'^') + 1;
return (VerifySplit(TempSpot));
}
@ -2921,3 +2894,38 @@ RunScriptFile (
return (Status);
}
/**
Return the pointer to the first occurance of any character from a list of characters
@param[in] String the string to parse
@param[in] CharacterList the list of character to look for
@param[in] EscapeCharacter An escape character to skip
@return the location of the first character in the string
@retval CHAR_NULL no instance of any character in CharacterList was found in String
**/
CONST CHAR16*
EFIAPI
FindFirstCharacter(
IN CONST CHAR16 *String,
IN CONST CHAR16 *CharacterList,
IN CONST CHAR16 EscapeCharacter
)
{
UINT32 WalkChar;
UINT32 WalkStr;
for (WalkStr = 0; WalkStr < StrLen(String); WalkStr++) {
if (String[WalkStr] == EscapeCharacter) {
WalkStr++;
continue;
}
for (WalkChar = 0; WalkChar < StrLen(CharacterList); WalkChar++) {
if (String[WalkStr] == CharacterList[WalkChar]) {
return (&String[WalkStr]);
}
}
}
return (String + StrLen(String));
}