]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg/Level2Command: Use UnicodeCollation in StrinCmp
authorRuiyu Ni <ruiyu.ni@intel.com>
Fri, 26 Jan 2018 08:43:22 +0000 (22:36 -3407)
committerRuiyu Ni <ruiyu.ni@intel.com>
Mon, 29 Jan 2018 01:41:48 +0000 (09:41 +0800)
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c
ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h

index 9ae81763f72fd585769ce1943a200b55d8e56239..d5dc9804d4dc33c148bf575e0dc0ee00d6e9f2bb 100644 (file)
@@ -3,7 +3,7 @@
 \r
   (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -102,7 +102,7 @@ IsCurrentFileSystem (
   if (((UINTN) Splitter1 - (UINTN) FullPath) != ((UINTN) Splitter2 - (UINTN) Cwd)) {\r
     return FALSE;\r
   } else {\r
-    if (StrniCmp (FullPath, Cwd, ((UINTN) Splitter1 - (UINTN) FullPath) / sizeof (CHAR16)) == NULL) {\r
+    if (StrniCmp (FullPath, Cwd, ((UINTN) Splitter1 - (UINTN) FullPath) / sizeof (CHAR16)) == 0) {\r
       return TRUE;\r
     } else {\r
       return FALSE;\r
index b8f6d310f66b9a417590f6a05990ca75ff2fc7a2..ae7528ddcf6ba6bfba37bb59a4b0f109fc33ea47 100644 (file)
@@ -2,7 +2,7 @@
   Main file for cp shell level 2 function.\r
 \r
   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -510,7 +510,7 @@ ValidateAndCopyFiles(
 \r
     if ( !EFI_ERROR(ShellIsDirectory(Node->FullName))\r
       && !EFI_ERROR(ShellIsDirectory(DestPath))\r
-      && StrniCmp(Node->FullName, DestPath, StrLen(DestPath)) == NULL\r
+      && StrniCmp(Node->FullName, DestPath, StrLen(DestPath)) == 0\r
       ){\r
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_PARENT), gShellLevel2HiiHandle, L"cp");  \r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
index 5383cffe879c401c15a93e151ab9f4a83e377d72..0b7551a239e995eaeaf8d1e7aa1d822cbf2ed745 100644 (file)
@@ -2,7 +2,7 @@
   Main file for time, timezone, and date shell level 2 and shell level 3 functions.\r
 \r
   (C) Copyright 2012-2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -550,7 +550,7 @@ ShellCommandRunTime (
           // perform level 3 operation here.\r
           //\r
           if ((TempLocation = ShellCommandLineGetValue(Package, L"-tz")) != NULL) {\r
-            if (StrniCmp (TempLocation, L"_local", StrLen (TempLocation)) == NULL) {\r
+            if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16 *)TempLocation, L"_local") == 0) {\r
               Tz = EFI_UNSPECIFIED_TIMEZONE;\r
             } else if (TempLocation[0] == L'-') {\r
 \r
@@ -713,7 +713,7 @@ CheckAndSetTimeZone (
     return (SHELL_INVALID_PARAMETER);\r
   }\r
 \r
-  if (StrniCmp (TimeZoneString, L"_local", StrLen (TimeZoneString)) == NULL) {\r
+  if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16 *)TimeZoneString, L"_local") == 0) {\r
     Status = gRT->GetTime (&TheTime, NULL);\r
     if (EFI_ERROR (Status)) {\r
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);\r
index e9ce6318922422225365675c8695858ffc629d28..36bc3552b57936313c36e1ba85e84f326d4010fc 100644 (file)
@@ -22,7 +22,7 @@
   * functions are non-interactive only\r
 \r
   Copyright (c) 2014 Hewlett-Packard Development Company, L.P.\r
-  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -260,19 +260,6 @@ VerifyIntermediateDirectories (
   return (Status);\r
 }\r
 \r
-/**\r
-  Be lazy and borrow from baselib.\r
-\r
-  @param[in] Char   The character to convert to upper case.\r
-\r
-  @return Char as an upper case character.\r
-**/\r
-CHAR16\r
-EFIAPI\r
-InternalCharToUpper (\r
-  IN      CHAR16                    Char\r
-  );\r
-\r
 /**\r
   String comparison without regard to case for a limited number of characters.\r
 \r
@@ -280,31 +267,47 @@ InternalCharToUpper (
   @param[in] Target   The second item to compare.\r
   @param[in] Count    How many characters to compare.\r
 \r
-  @retval NULL Source and Target are identical strings without regard to case.\r
-  @return The location in Source where there is a difference.\r
+  @retval 0    Source and Target are identical strings without regard to case.\r
+  @retval !=0  Source is not identical to Target.\r
+  \r
 **/\r
-CONST CHAR16*\r
+INTN\r
 StrniCmp(\r
   IN CONST CHAR16 *Source,\r
   IN CONST CHAR16 *Target,\r
   IN CONST UINTN  Count\r
   )\r
 {\r
-  UINTN   LoopCount;\r
-  CHAR16  Char1;\r
-  CHAR16  Char2;\r
-\r
-  ASSERT(Source != NULL);\r
-  ASSERT(Target != NULL);\r
-\r
-  for (LoopCount = 0 ; LoopCount < Count ; LoopCount++) {\r
-    Char1 = InternalCharToUpper(Source[LoopCount]);\r
-    Char2 = InternalCharToUpper(Target[LoopCount]);\r
-    if (Char1 != Char2) {\r
-      return (&Source[LoopCount]);\r
-    }\r
+  CHAR16                    *SourceCopy;\r
+  CHAR16                    *TargetCopy;\r
+  UINTN                     SourceLength;\r
+  UINTN                     TargetLength;\r
+  INTN                      Result;\r
+\r
+  if (Count == 0) {\r
+    return 0;\r
+  }\r
+\r
+  SourceLength = StrLen (Source);\r
+  TargetLength = StrLen (Target);\r
+  SourceLength = MIN (SourceLength, Count);\r
+  TargetLength = MIN (TargetLength, Count);\r
+  SourceCopy = AllocateCopyPool ((SourceLength + 1) * sizeof (CHAR16), Source);\r
+  if (SourceCopy == NULL) {\r
+    return -1;\r
+  }\r
+  TargetCopy = AllocateCopyPool ((TargetLength + 1) * sizeof (CHAR16), Target);\r
+  if (TargetCopy == NULL) {\r
+    FreePool (SourceCopy);\r
+    return -1;\r
   }\r
-  return (NULL);\r
+  \r
+  SourceCopy[SourceLength] = L'\0';\r
+  TargetCopy[TargetLength] = L'\0';\r
+  Result = gUnicodeCollation->StriColl (gUnicodeCollation, SourceCopy, TargetCopy);\r
+  FreePool (SourceCopy);\r
+  FreePool (TargetCopy);\r
+  return Result;\r
 }\r
 \r
 \r
index 857487fd809341aad7b4adf4894dd9f9b08dde22..fef6adc3e1b52a774ae7c4c797fb7707a3c657c7 100644 (file)
@@ -280,16 +280,17 @@ VerifyIntermediateDirectories (
   );\r
 \r
 /**\r
-  CaseInsensitive length limited string comparison.\r
+  String comparison without regard to case for a limited number of characters.\r
 \r
-  @param[in] Source   Pointer to first string.\r
-  @param[in] Target   Pointer to second string.\r
-  @param[in] Count    Number of characters to compare.\r
+  @param[in] Source   The first item to compare.\r
+  @param[in] Target   The second item to compare.\r
+  @param[in] Count    How many characters to compare.\r
 \r
-  @retval 0   The strings are the same.\r
-  @return     non-zero if the strings are different.\r
+  @retval 0    Source and Target are identical strings without regard to case.\r
+  @retval !=0  Source is not identical to Target.\r
+  \r
 **/\r
-CONST CHAR16*\r
+INTN\r
 StrniCmp(\r
   IN CONST CHAR16 *Source,\r
   IN CONST CHAR16 *Target,\r