adding new parameter to search and replace function to allow for easy skipping of...
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 13 Jan 2010 16:46:33 +0000 (16:46 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 13 Jan 2010 16:46:33 +0000 (16:46 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9726 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Include/Library/ShellLib.h
ShellPkg/Library/UefiShellLib/UefiShellLib.c

index ecab001d4fac5dfb94ace43188639d1e887daf39..3d2fbe27af8b0264c432564048140df6cbd7f881 100644 (file)
@@ -1033,6 +1033,8 @@ StrnCatGrow (
   @param[in] NewSize                  Size in bytes of NewString.\r
   @param[in] FindTarget               String to look for.\r
   @param[in] ReplaceWith              String to replace FindTarget with.\r
+  @param[in] SkipPreCarrot            If TRUE will skip a FindTarget that has a '^'\r
+                                      immediately before it.\r
 \r
   @retval EFI_INVALID_PARAMETER       SourceString was NULL.\r
   @retval EFI_INVALID_PARAMETER       NewString was NULL.\r
@@ -1042,19 +1044,25 @@ StrnCatGrow (
   @retval EFI_INVALID_PARAMETER       SourceString had length < 1.\r
   @retval EFI_BUFFER_TOO_SMALL        NewSize was less than the minimum size to hold \r
                                       the new string (truncation occurred).\r
-  @retval EFI_SUCCESS                 the string was sucessfully copied with replacement.\r
+  @retval EFI_SUCCESS                 The string was sucessfully copied with replacement.\r
 **/\r
 \r
 EFI_STATUS\r
 EFIAPI\r
-ShellLibCopySearchAndReplace(\r
+ShellCopySearchAndReplace2(\r
   IN CHAR16 CONST                     *SourceString,\r
   IN CHAR16                           *NewString,\r
   IN UINTN                            NewSize,\r
   IN CONST CHAR16                     *FindTarget,\r
-  IN CONST CHAR16                     *ReplaceWith\r
+  IN CONST CHAR16                     *ReplaceWith,\r
+  IN CONST BOOLEAN                    SkipPreCarrot\r
   );\r
 \r
+///\r
+/// make upgrades easier from old version\r
+///\r
+#define ShellLibCopySearchAndReplace(a,b,c,d,e) ShellCopySearchAndReplace2(a,b,c,d,e,FALSE)\r
+\r
 /**\r
   Check if a Unicode character is a hexadecimal character.\r
 \r
@@ -1070,7 +1078,7 @@ ShellLibCopySearchAndReplace(
 **/\r
 BOOLEAN\r
 EFIAPI\r
-ShellLibIsHexaDecimalDigitCharacter (\r
+ShellIsHexaDecimalDigitCharacter (\r
   IN      CHAR16                    Char\r
   );\r
 \r
index e1aaa9db80c818b6ff4b10fb493b2ce91a4d9aae..369bb81a58ed3bd8d1625578bfdc06aae4659b87 100644 (file)
@@ -53,7 +53,7 @@ STATIC CHAR16                        *mPostReplaceFormat2;
 **/\r
 BOOLEAN\r
 EFIAPI\r
-ShellLibIsHexaDecimalDigitCharacter (\r
+ShellIsHexaDecimalDigitCharacter (\r
   IN      CHAR16                    Char\r
   ) {\r
   return (BOOLEAN) ((Char >= L'0' && Char <= L'9') || (Char >= L'A' && Char <= L'F') || (Char >= L'a' && Char <= L'f'));\r
@@ -1684,7 +1684,7 @@ InternalIsFlag (
   //\r
   // If we accept numbers then dont return TRUE. (they will be values)\r
   //\r
-  if (((Name[0] == L'-' || Name[0] == L'+') && ShellLibIsHexaDecimalDigitCharacter(Name[1])) && AlwaysAllowNumbers != FALSE) {\r
+  if (((Name[0] == L'-' || Name[0] == L'+') && ShellIsHexaDecimalDigitCharacter(Name[1])) && AlwaysAllowNumbers != FALSE) {\r
     return (FALSE);\r
   }\r
 \r
@@ -2249,26 +2249,29 @@ ShellCommandLineCheckDuplicate (
   @param[in] NewSize                  Size in bytes of NewString\r
   @param[in] FindTarget               String to look for\r
   @param[in[ ReplaceWith              String to replace FindTarget with\r
-\r
-  @retval EFI_INVALID_PARAMETER       SourceString was NULL\r
-  @retval EFI_INVALID_PARAMETER       NewString was NULL\r
-  @retval EFI_INVALID_PARAMETER       FindTarget was NULL\r
-  @retval EFI_INVALID_PARAMETER       ReplaceWith was NULL\r
-  @retval EFI_INVALID_PARAMETER       FindTarget had length < 1\r
-  @retval EFI_INVALID_PARAMETER       SourceString had length < 1\r
+  @param[in] SkipPreCarrot            If TRUE will skip a FindTarget that has a '^'\r
+                                      immediately before it.\r
+\r
+  @retval EFI_INVALID_PARAMETER       SourceString was NULL.\r
+  @retval EFI_INVALID_PARAMETER       NewString was NULL.\r
+  @retval EFI_INVALID_PARAMETER       FindTarget was NULL.\r
+  @retval EFI_INVALID_PARAMETER       ReplaceWith was NULL.\r
+  @retval EFI_INVALID_PARAMETER       FindTarget had length < 1.\r
+  @retval EFI_INVALID_PARAMETER       SourceString had length < 1.\r
   @retval EFI_BUFFER_TOO_SMALL        NewSize was less than the minimum size to hold \r
-                                      the new string (truncation occurred)\r
-  @retval EFI_SUCCESS                 the string was sucessfully copied with replacement\r
+                                      the new string (truncation occurred).\r
+  @retval EFI_SUCCESS                 the string was sucessfully copied with replacement.\r
 **/\r
 \r
 EFI_STATUS\r
 EFIAPI\r
-ShellLibCopySearchAndReplace(\r
+ShellCopySearchAndReplace2(\r
   IN CHAR16 CONST                     *SourceString,\r
   IN CHAR16                           *NewString,\r
   IN UINTN                            NewSize,\r
   IN CONST CHAR16                     *FindTarget,\r
-  IN CONST CHAR16                     *ReplaceWith\r
+  IN CONST CHAR16                     *ReplaceWith,\r
+  IN CONST BOOLEAN                    SkipPreCarrot\r
   ) \r
 {\r
   UINTN Size;\r
@@ -2283,7 +2286,13 @@ ShellLibCopySearchAndReplace(
   }\r
   NewString = SetMem16(NewString, NewSize, CHAR_NULL);\r
   while (*SourceString != CHAR_NULL) {\r
-    if (StrnCmp(SourceString, FindTarget, StrLen(FindTarget)) == 0) {\r
+    //\r
+    // if we find the FindTarget and either Skip == FALSE or Skip == TRUE and we \r
+    // dont have a carrot do a replace...\r
+    //\r
+    if (StrnCmp(SourceString, FindTarget, StrLen(FindTarget)) == 0 \r
+      && ((SkipPreCarrot && *(SourceString-1) != L'^') || SkipPreCarrot == FALSE)\r
+      ){\r
       SourceString += StrLen(FindTarget);\r
       Size = StrSize(NewString);\r
       if ((Size + (StrLen(ReplaceWith)*sizeof(CHAR16))) > NewSize) {\r