]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: refactor out leading and trailing space trimming
authorJaben Carsey <jaben.carsey@intel.com>
Thu, 12 Dec 2013 18:42:18 +0000 (18:42 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 12 Dec 2013 18:42:18 +0000 (18:42 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14972 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Application/Shell/Shell.c

index 25c519c31561c7de37cc359edda355c23df188d0..7af8153b4d560bcc4a211b599ff4ffbb73179560 100644 (file)
@@ -70,6 +70,36 @@ STATIC CONST CHAR16 mScriptExtension[]      = L".NSH";
 STATIC CONST CHAR16 mExecutableExtensions[] = L".NSH;.EFI";\r
 STATIC CONST CHAR16 mStartupScript[]        = L"startup.nsh";\r
 \r
+/**\r
+  Cleans off leading and trailing spaces and tabs\r
+\r
+  @param[in] String pointer to the string to trim them off\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TrimSpaces(\r
+  IN CHAR16 **String\r
+  )\r
+{\r
+  ASSERT(String != NULL);\r
+  ASSERT(*String!= NULL);\r
+  //\r
+  // Remove any spaces and tabs at the beginning of the (*String).\r
+  //\r
+  while (((*String)[0] == L' ') || ((*String)[0] == L'\t')) {\r
+    CopyMem((*String), (*String)+1, StrSize((*String)) - sizeof((*String)[0]));\r
+  }\r
+\r
+  //\r
+  // Remove any spaces at the end of the (*String).\r
+  //\r
+  while ((*String)[StrLen((*String))-1] == L' ') {\r
+    (*String)[StrLen((*String))-1] = CHAR_NULL;\r
+  }\r
+\r
+  return (EFI_SUCCESS);\r
+}\r
+\r
 /**\r
   Find a command line contains a split operation\r
 \r
@@ -1460,12 +1490,7 @@ RunCommand(
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
 \r
-  //\r
-  // Remove any spaces and tabs at the beginning of the string.\r
-  //\r
-  while ((CleanOriginal[0] == L' ') || (CleanOriginal[0] == L'\t')) {\r
-    CopyMem(CleanOriginal, CleanOriginal+1, StrSize(CleanOriginal) - sizeof(CleanOriginal[0]));\r
-  }\r
+  TrimSpaces(&CleanOriginal);\r
 \r
   //\r
   // Handle case that passed in command line is just 1 or more " " characters.\r
@@ -1478,13 +1503,6 @@ RunCommand(
     return (EFI_SUCCESS);\r
   }\r
 \r
-  //\r
-  // Remove any spaces at the end of the string.\r
-  //\r
-  while (CleanOriginal[StrLen(CleanOriginal)-1] == L' ') {\r
-    CleanOriginal[StrLen(CleanOriginal)-1] = CHAR_NULL;\r
-  }\r
-\r
   CommandName = NULL;\r
   if (StrStr(CleanOriginal, L" ") == NULL){\r
     StrnCatGrow(&CommandName, NULL, CleanOriginal, 0);\r
@@ -1530,12 +1548,7 @@ RunCommand(
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
 \r
-  while (PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] == L' ') {\r
-    PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] = CHAR_NULL;\r
-  }\r
-  while (PostVariableCmdLine[0] == L' ') {\r
-    CopyMem(PostVariableCmdLine, PostVariableCmdLine+1, StrSize(PostVariableCmdLine) - sizeof(PostVariableCmdLine[0]));\r
-  }\r
+  TrimSpaces(&PostVariableCmdLine);\r
 \r
   //\r
   // We dont do normal processing with a split command line (output from one command input to another)\r
@@ -1583,13 +1596,8 @@ RunCommand(
         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle);\r
       }\r
     } else {\r
-      while (PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] == L' ') {\r
-        PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] = CHAR_NULL;\r
-      }\r
-      while (PostVariableCmdLine[0] == L' ') {\r
-        CopyMem(PostVariableCmdLine, PostVariableCmdLine+1, StrSize(PostVariableCmdLine) - sizeof(PostVariableCmdLine[0]));\r
-      }\r
-\r
+      TrimSpaces(&PostVariableCmdLine);\r
+    \r
       //\r
       // get the argc and argv updated for internal commands\r
       //\r