]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/String.c
Refine code.
[mirror_edk2.git] / MdePkg / Library / BaseLib / String.c
index 43ba1447b88d77ef2c2c6070660a323d58a130e7..273291a915b281ce1eebeaa611b63074da2a9a24 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
   Unicode and ASCII string primatives.\r
 \r
-  Copyright (c) 2006 - 2009, Intel Corporation<BR>\r
-  All rights reserved. This program and the accompanying materials\r
+  Copyright (c) 2006 - 2010, 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
-  http://opensource.org/licenses/bsd-license.php\r
+  http://opensource.org/licenses/bsd-license.php.\r
 \r
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 #include "BaseLibInternals.h"\r
 \r
-#define QUOTIENT_MAX_UINTN_DIVIDED_BY_10      ((UINTN) -1 / 10)\r
-#define REMAINDER_MAX_UINTN_DIVIDED_BY_10    ((UINTN) -1 % 10)\r
-\r
-#define QUOTIENT_MAX_UINTN_DIVIDED_BY_16      ((UINTN) -1 / 16)\r
-#define REMAINDER_MAX_UINTN_DIVIDED_BY_16    ((UINTN) -1 % 16)\r
-\r
-#define QUOTIENT_MAX_UINT64_DIVIDED_BY_10      ((UINT64) -1 / 10)\r
-#define REMAINDER_MAX_UINT64_DIVIDED_BY_10    ((UINT64) -1 % 10)\r
-\r
-#define QUOTIENT_MAX_UINT64_DIVIDED_BY_16      ((UINT64) -1 / 16)\r
-#define REMAINDER_MAX_UINT64_DIVIDED_BY_16    ((UINT64) -1 % 16)\r
 \r
 /**\r
   Copies one Null-terminated Unicode string to another Null-terminated Unicode\r
@@ -43,8 +32,8 @@
   PcdMaximumUnicodeStringLength Unicode characters, not including the\r
   Null-terminator, then ASSERT().\r
 \r
-  @param  Destination Pointer to a Null-terminated Unicode string.\r
-  @param  Source      Pointer to a Null-terminated Unicode string.\r
+  @param  Destination A pointer to a Null-terminated Unicode string.\r
+  @param  Source      A pointer to a Null-terminated Unicode string.\r
 \r
   @return Destination.\r
 \r
@@ -101,9 +90,9 @@ StrCpy (
   PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  Destination Pointer to a Null-terminated Unicode string.\r
-  @param  Source      Pointer to a Null-terminated Unicode string.\r
-  @param  Length      Maximum number of Unicode characters to copy.\r
+  @param  Destination A pointer to a Null-terminated Unicode string.\r
+  @param  Source      A pointer to a Null-terminated Unicode string.\r
+  @param  Length      The maximum number of Unicode characters to copy.\r
 \r
   @return Destination.\r
 \r
@@ -161,7 +150,7 @@ StrnCpy (
   PcdMaximumUnicodeStringLength Unicode characters, not including the\r
   Null-terminator, then ASSERT().\r
 \r
-  @param  String  Pointer to a Null-terminated Unicode string.\r
+  @param  String  A pointer to a Null-terminated Unicode string.\r
 \r
   @return The length of String.\r
 \r
@@ -202,7 +191,7 @@ StrLen (
   PcdMaximumUnicodeStringLength Unicode characters, not including the\r
   Null-terminator, then ASSERT().\r
 \r
-  @param  String  Pointer to a Null-terminated Unicode string.\r
+  @param  String  A pointer to a Null-terminated Unicode string.\r
 \r
   @return The size of String.\r
 \r
@@ -237,8 +226,8 @@ StrSize (
   than PcdMaximumUnicodeStringLength Unicode characters, not including the\r
   Null-terminator, then ASSERT().\r
 \r
-  @param  FirstString   Pointer to a Null-terminated Unicode string.\r
-  @param  SecondString  Pointer to a Null-terminated Unicode string.\r
+  @param  FirstString   A pointer to a Null-terminated Unicode string.\r
+  @param  SecondString  A pointer to a Null-terminated Unicode string.\r
 \r
   @retval 0      FirstString is identical to SecondString.\r
   @return others FirstString is not identical to SecondString.\r
@@ -288,9 +277,9 @@ StrCmp (
   PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  FirstString   Pointer to a Null-terminated Unicode string.\r
-  @param  SecondString  Pointer to a Null-terminated Unicode string.\r
-  @param  Length        Maximum number of Unicode characters to compare.\r
+  @param  FirstString   A pointer to a Null-terminated Unicode string.\r
+  @param  SecondString  A pointer to a Null-terminated Unicode string.\r
+  @param  Length        The maximum number of Unicode characters to compare.\r
 \r
   @retval 0      FirstString is identical to SecondString.\r
   @return others FirstString is not identical to SecondString.\r
@@ -356,8 +345,8 @@ StrnCmp (
   PcdMaximumUnicodeStringLength Unicode characters, not including the\r
   Null-terminator, then ASSERT().\r
 \r
-  @param  Destination Pointer to a Null-terminated Unicode string.\r
-  @param  Source      Pointer to a Null-terminated Unicode string.\r
+  @param  Destination A pointer to a Null-terminated Unicode string.\r
+  @param  Source      A pointer to a Null-terminated Unicode string.\r
 \r
   @return Destination.\r
 \r
@@ -409,9 +398,9 @@ StrCat (
   and Source results in a Unicode string with more than PcdMaximumUnicodeStringLength\r
   Unicode characters, not including the Null-terminator, then ASSERT().\r
 \r
-  @param  Destination Pointer to a Null-terminated Unicode string.\r
-  @param  Source      Pointer to a Null-terminated Unicode string.\r
-  @param  Length      Maximum number of Unicode characters to concatenate from\r
+  @param  Destination A pointer to a Null-terminated Unicode string.\r
+  @param  Source      A pointer to a Null-terminated Unicode string.\r
+  @param  Length      The maximum number of Unicode characters to concatenate from\r
                       Source.\r
 \r
   @return Destination.\r
@@ -425,7 +414,11 @@ StrnCat (
   IN      UINTN                     Length\r
   )\r
 {\r
-  StrnCpy (Destination + StrLen (Destination), Source, Length);\r
+  UINTN   DestinationLen;\r
+\r
+  DestinationLen = StrLen (Destination);\r
+  StrnCpy (Destination + DestinationLen, Source, Length);\r
+  Destination[DestinationLen + Length] = L'\0';\r
 \r
   //\r
   // Size of the resulting string should never be zero.\r
@@ -454,8 +447,8 @@ StrnCat (
   or String contains more than PcdMaximumUnicodeStringLength Unicode\r
   characters, not including the Null-terminator, then ASSERT().\r
 \r
-  @param  String          Pointer to a Null-terminated Unicode string.\r
-  @param  SearchString    Pointer to a Null-terminated Unicode string to search for.\r
+  @param  String          A pointer to a Null-terminated Unicode string.\r
+  @param  SearchString    A pointer to a Null-terminated Unicode string to search for.\r
 \r
   @retval NULL            If the SearchString does not appear in String.\r
   @return others          If there is a match.\r
@@ -637,7 +630,7 @@ InternalIsHexaDecimalDigitCharacter (
   more than PcdMaximumUnicodeStringLength Unicode characters, not including\r
   the Null-terminator, then ASSERT().\r
 \r
-  @param  String      Pointer to a Null-terminated Unicode string.\r
+  @param  String      A pointer to a Null-terminated Unicode string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -677,10 +670,7 @@ StrDecimalToUintn (
     // If the number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_10) ||\r
-      ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_10) &&\r
-      (*String - L'0') <= REMAINDER_MAX_UINTN_DIVIDED_BY_10)\r
-      );\r
+    ASSERT (Result <= ((((UINTN) ~0) - (*String - L'0')) / 10));\r
 \r
     Result = Result * 10 + (*String - L'0');\r
     String++;\r
@@ -719,7 +709,7 @@ StrDecimalToUintn (
   more than PcdMaximumUnicodeStringLength Unicode characters, not including\r
   the Null-terminator, then ASSERT().\r
 \r
-  @param  String          Pointer to a Null-terminated Unicode string.\r
+  @param  String          A pointer to a Null-terminated Unicode string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -759,10 +749,7 @@ StrDecimalToUint64 (
     // If the number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_10) || \r
-      ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_10) && \r
-      (*String - L'0') <= REMAINDER_MAX_UINT64_DIVIDED_BY_10)\r
-      );\r
+    ASSERT (Result <= DivU64x32 (((UINT64) ~0) - (*String - L'0') , 10));\r
 \r
     Result = MultU64x32 (Result, 10) + (*String - L'0');\r
     String++;\r
@@ -801,7 +788,7 @@ StrDecimalToUint64 (
   PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  String          Pointer to a Null-terminated Unicode string.\r
+  @param  String          A pointer to a Null-terminated Unicode string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -851,10 +838,7 @@ StrHexToUintn (
     // If the Hex Number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_16) ||\r
-      ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_16) && \r
-      (InternalHexCharToUintn (*String) <= REMAINDER_MAX_UINTN_DIVIDED_BY_16))\r
-      );\r
+    ASSERT (Result <= ((((UINTN) ~0) - InternalHexCharToUintn (*String)) >> 4));\r
 \r
     Result = (Result << 4) + InternalHexCharToUintn (*String);\r
     String++;\r
@@ -894,7 +878,7 @@ StrHexToUintn (
   PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  String          Pointer to a Null-terminated Unicode string.\r
+  @param  String          A pointer to a Null-terminated Unicode string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -945,10 +929,7 @@ StrHexToUint64 (
     // If the Hex Number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_16)|| \r
-      ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_16) && \r
-      (InternalHexCharToUintn (*String) <= REMAINDER_MAX_UINT64_DIVIDED_BY_16))\r
-      );\r
+    ASSERT (Result <= RShiftU64 (((UINT64) ~0) - InternalHexCharToUintn (*String) , 4));\r
 \r
     Result = LShiftU64 (Result, 4);\r
     Result = Result + InternalHexCharToUintn (*String);\r
@@ -1030,8 +1011,8 @@ InternalAsciiIsHexaDecimalDigitCharacter (
   than PcdMaximumAsciiStringLength Unicode characters, not including the\r
   Null-terminator, then ASSERT().\r
 \r
-  @param  Source        Pointer to a Null-terminated Unicode string.\r
-  @param  Destination   Pointer to a Null-terminated ASCII string.\r
+  @param  Source        A pointer to a Null-terminated Unicode string.\r
+  @param  Destination   A pointer to a Null-terminated ASCII string.\r
 \r
   @return Destination.\r
 \r
@@ -1097,8 +1078,8 @@ UnicodeStrToAsciiStr (
   PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  Destination Pointer to a Null-terminated ASCII string.\r
-  @param  Source      Pointer to a Null-terminated ASCII string.\r
+  @param  Destination A pointer to a Null-terminated ASCII string.\r
+  @param  Source      A pointer to a Null-terminated ASCII string.\r
 \r
   @return Destination\r
 \r
@@ -1151,9 +1132,9 @@ AsciiStrCpy (
   PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  Destination Pointer to a Null-terminated ASCII string.\r
-  @param  Source      Pointer to a Null-terminated ASCII string.\r
-  @param  Length      Maximum number of ASCII characters to copy.\r
+  @param  Destination A pointer to a Null-terminated ASCII string.\r
+  @param  Source      A pointer to a Null-terminated ASCII string.\r
+  @param  Length      The maximum number of ASCII characters to copy.\r
 \r
   @return Destination\r
 \r
@@ -1210,7 +1191,7 @@ AsciiStrnCpy (
   PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  String  Pointer to a Null-terminated ASCII string.\r
+  @param  String  A pointer to a Null-terminated ASCII string.\r
 \r
   @return The length of String.\r
 \r
@@ -1249,7 +1230,7 @@ AsciiStrLen (
   PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  String  Pointer to a Null-terminated ASCII string.\r
+  @param  String  A pointer to a Null-terminated ASCII string.\r
 \r
   @return The size of String.\r
 \r
@@ -1282,8 +1263,8 @@ AsciiStrSize (
   than PcdMaximumAsciiStringLength ASCII characters, not including the\r
   Null-terminator, then ASSERT().\r
 \r
-  @param  FirstString   Pointer to a Null-terminated ASCII string.\r
-  @param  SecondString  Pointer to a Null-terminated ASCII string.\r
+  @param  FirstString   A pointer to a Null-terminated ASCII string.\r
+  @param  SecondString  A pointer to a Null-terminated ASCII string.\r
 \r
   @retval ==0      FirstString is identical to SecondString.\r
   @retval !=0      FirstString is not identical to SecondString.\r
@@ -1325,7 +1306,7 @@ AsciiStrCmp (
 **/\r
 CHAR8\r
 EFIAPI\r
-AsciiToUpper (\r
+InternalBaseLibAsciiToUpper (\r
   IN      CHAR8                     Chr\r
   )\r
 {\r
@@ -1355,7 +1336,7 @@ InternalAsciiHexCharToUintn (
     return Char - '0';\r
   }\r
 \r
-  return (UINTN) (10 + AsciiToUpper (Char) - 'A');\r
+  return (UINTN) (10 + InternalBaseLibAsciiToUpper (Char) - 'A');\r
 }\r
 \r
 \r
@@ -1379,8 +1360,8 @@ InternalAsciiHexCharToUintn (
   than PcdMaximumAsciiStringLength ASCII characters, not including the\r
   Null-terminator, then ASSERT().\r
 \r
-  @param  FirstString   Pointer to a Null-terminated ASCII string.\r
-  @param  SecondString  Pointer to a Null-terminated ASCII string.\r
+  @param  FirstString   A pointer to a Null-terminated ASCII string.\r
+  @param  SecondString  A pointer to a Null-terminated ASCII string.\r
 \r
   @retval ==0    FirstString is identical to SecondString using case insensitive\r
                  comparisons.\r
@@ -1404,13 +1385,13 @@ AsciiStriCmp (
   ASSERT (AsciiStrSize (FirstString));\r
   ASSERT (AsciiStrSize (SecondString));\r
 \r
-  UpperFirstString  = AsciiToUpper (*FirstString);\r
-  UpperSecondString = AsciiToUpper (*SecondString);\r
+  UpperFirstString  = InternalBaseLibAsciiToUpper (*FirstString);\r
+  UpperSecondString = InternalBaseLibAsciiToUpper (*SecondString);\r
   while ((*FirstString != '\0') && (UpperFirstString == UpperSecondString)) {\r
     FirstString++;\r
     SecondString++;\r
-    UpperFirstString  = AsciiToUpper (*FirstString);\r
-    UpperSecondString = AsciiToUpper (*SecondString);\r
+    UpperFirstString  = InternalBaseLibAsciiToUpper (*FirstString);\r
+    UpperSecondString = InternalBaseLibAsciiToUpper (*SecondString);\r
   }\r
 \r
   return UpperFirstString - UpperSecondString;\r
@@ -1438,9 +1419,9 @@ AsciiStriCmp (
   PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  FirstString   Pointer to a Null-terminated ASCII string.\r
-  @param  SecondString  Pointer to a Null-terminated ASCII string.\r
-  @param  Length        Maximum number of ASCII characters for compare.\r
+  @param  FirstString   A pointer to a Null-terminated ASCII string.\r
+  @param  SecondString  A pointer to a Null-terminated ASCII string.\r
+  @param  Length        The maximum number of ASCII characters for compare.\r
   \r
   @retval ==0       FirstString is identical to SecondString.\r
   @retval !=0       FirstString is not identical to SecondString.\r
@@ -1499,8 +1480,8 @@ AsciiStrnCmp (
   Source results in a ASCII string with more than PcdMaximumAsciiStringLength\r
   ASCII characters, then ASSERT().\r
 \r
-  @param  Destination Pointer to a Null-terminated ASCII string.\r
-  @param  Source      Pointer to a Null-terminated ASCII string.\r
+  @param  Destination A pointer to a Null-terminated ASCII string.\r
+  @param  Source      A pointer to a Null-terminated ASCII string.\r
 \r
   @return Destination\r
 \r
@@ -1550,9 +1531,9 @@ AsciiStrCat (
   Source results in a ASCII string with more than PcdMaximumAsciiStringLength\r
   ASCII characters, not including the Null-terminator, then ASSERT().\r
 \r
-  @param  Destination Pointer to a Null-terminated ASCII string.\r
-  @param  Source      Pointer to a Null-terminated ASCII string.\r
-  @param  Length      Maximum number of ASCII characters to concatenate from\r
+  @param  Destination A pointer to a Null-terminated ASCII string.\r
+  @param  Source      A pointer to a Null-terminated ASCII string.\r
+  @param  Length      The maximum number of ASCII characters to concatenate from\r
                       Source.\r
 \r
   @return Destination\r
@@ -1566,7 +1547,11 @@ AsciiStrnCat (
   IN      UINTN                     Length\r
   )\r
 {\r
-  AsciiStrnCpy (Destination + AsciiStrLen (Destination), Source, Length);\r
+  UINTN   DestinationLen;\r
+\r
+  DestinationLen = AsciiStrLen (Destination);\r
+  AsciiStrnCpy (Destination + DestinationLen, Source, Length);\r
+  Destination[DestinationLen + Length] = '\0';\r
 \r
   //\r
   // Size of the resulting string should never be zero.\r
@@ -1592,8 +1577,8 @@ AsciiStrnCat (
   String contains more than PcdMaximumAsciiStringLength Unicode characters\r
   not including the Null-terminator, then ASSERT().\r
 \r
-  @param  String          Pointer to a Null-terminated ASCII string.\r
-  @param  SearchString    Pointer to a Null-terminated ASCII string to search for.\r
+  @param  String          A pointer to a Null-terminated ASCII string.\r
+  @param  SearchString    A pointer to a Null-terminated ASCII string to search for.\r
 \r
   @retval NULL            If the SearchString does not appear in String.\r
   @retval others          If there is a match return the first occurrence of SearchingString.\r
@@ -1669,7 +1654,7 @@ AsciiStrStr (
   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  String          Pointer to a Null-terminated ASCII string.\r
+  @param  String          A pointer to a Null-terminated ASCII string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -1708,10 +1693,7 @@ AsciiStrDecimalToUintn (
     // If the number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_10) ||\r
-      ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_10) && \r
-      (*String - '0') <= REMAINDER_MAX_UINTN_DIVIDED_BY_10)\r
-      );\r
+    ASSERT (Result <= ((((UINTN) ~0) - (*String - L'0')) / 10));\r
 \r
     Result = Result * 10 + (*String - '0');\r
     String++;\r
@@ -1746,7 +1728,7 @@ AsciiStrDecimalToUintn (
   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  String          Pointer to a Null-terminated ASCII string.\r
+  @param  String          A pointer to a Null-terminated ASCII string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -1785,10 +1767,7 @@ AsciiStrDecimalToUint64 (
     // If the number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_10) || \r
-      ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_10) && \r
-      (*String - '0') <= REMAINDER_MAX_UINT64_DIVIDED_BY_10)\r
-      );\r
+    ASSERT (Result <= DivU64x32 (((UINT64) ~0) - (*String - L'0') , 10));\r
 \r
     Result = MultU64x32 (Result, 10) + (*String - '0');\r
     String++;\r
@@ -1826,7 +1805,7 @@ AsciiStrDecimalToUint64 (
   and String contains more than PcdMaximumAsciiStringLength ASCII characters not including\r
   the Null-terminator, then ASSERT().\r
 \r
-  @param  String          Pointer to a Null-terminated ASCII string.\r
+  @param  String          A pointer to a Null-terminated ASCII string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -1858,7 +1837,7 @@ AsciiStrHexToUintn (
     String++;\r
   }\r
 \r
-  if (AsciiToUpper (*String) == 'X') {\r
+  if (InternalBaseLibAsciiToUpper (*String) == 'X') {\r
     ASSERT (*(String - 1) == '0');\r
     if (*(String - 1) != '0') {\r
       return 0;\r
@@ -1876,10 +1855,7 @@ AsciiStrHexToUintn (
     // If the Hex Number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
-     ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_16) ||\r
-       ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_16) && \r
-       (InternalAsciiHexCharToUintn (*String) <= REMAINDER_MAX_UINTN_DIVIDED_BY_16))\r
-       );\r
+    ASSERT (Result <= ((((UINTN) ~0) - InternalHexCharToUintn (*String)) >> 4));\r
 \r
     Result = (Result << 4) + InternalAsciiHexCharToUintn (*String);\r
     String++;\r
@@ -1918,7 +1894,7 @@ AsciiStrHexToUintn (
   and String contains more than PcdMaximumAsciiStringLength ASCII characters not including\r
   the Null-terminator, then ASSERT().\r
 \r
-  @param  String          Pointer to a Null-terminated ASCII string.\r
+  @param  String          A pointer to a Null-terminated ASCII string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -1953,7 +1929,7 @@ AsciiStrHexToUint64 (
     String++;\r
   }\r
 \r
-  if (AsciiToUpper (*String) == 'X') {\r
+  if (InternalBaseLibAsciiToUpper (*String) == 'X') {\r
     ASSERT (*(String - 1) == '0');\r
     if (*(String - 1) != '0') {\r
       return 0;\r
@@ -1971,10 +1947,7 @@ AsciiStrHexToUint64 (
     // If the Hex Number represented by String overflows according \r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_16) ||\r
-      ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_16) && \r
-      (InternalAsciiHexCharToUintn (*String) <= REMAINDER_MAX_UINT64_DIVIDED_BY_16))\r
-      );\r
+    ASSERT (Result <= RShiftU64 (((UINT64) ~0) - InternalHexCharToUintn (*String) , 4));\r
 \r
     Result = LShiftU64 (Result, 4);\r
     Result = Result + InternalAsciiHexCharToUintn (*String);\r
@@ -2006,8 +1979,8 @@ AsciiStrHexToUint64 (
   PcdMaximumUnicodeStringLength ASCII characters not including the\r
   Null-terminator, then ASSERT().\r
 \r
-  @param  Source        Pointer to a Null-terminated ASCII string.\r
-  @param  Destination   Pointer to a Null-terminated Unicode string.\r
+  @param  Source        A pointer to a Null-terminated ASCII string.\r
+  @param  Destination   A pointer to a Null-terminated Unicode string.\r
 \r
   @return Destination.\r
 \r