]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Remove NibbleToHexChar() function from BaseLib
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 1 Dec 2008 02:32:12 +0000 (02:32 +0000)
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 1 Dec 2008 02:32:12 +0000 (02:32 +0000)
Move IsHexDigit, BufToHexString, HexStringToBuf from BaseLib to MdeModulePkg IfrSupportLib. The reason is:
1) IsHexDigit function provides the logic to check Hex Digit and convert it to Decimal value, which is required by IScsi LUN and HII user input. But this logic is not provided by any functions in MdeLib. So, it can't be deleted. It is moved to IfrSupportLib.
2) BufToHexString function converts a array of buffers to hex string. If the buffer length is less than sizeof (UINT64), it can be directly replaced by UnicodeValueToString(). But HII modules may use BufToHexString to convert the buffers whose length > sizeof (UINT64). For example:
.\MdeModulePkg\Universal\HiiDatabaseDxe\ConfigRouting.c line 201, 1148
.\Universal\SetupBrowserDxe\Setup.c line line 1457, 1503
Like this case, it is not easy to use UnicodeValueToString to replace BufToHexString. So, BufToHexString is still kept. Because such usages are in HII modules, this function is moved to IfrSupportLib.
3) HexStringToBuf is moved to IfrSupportLib. The reason is similar to BufToHexString.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@6782 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Include/Library/IfrSupportLib.h
MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
MdeModulePkg/Library/UefiIfrSupportLib/UefiIfrForm.c
MdeModulePkg/Universal/DevicePathDxe/DevicePathFromText.c
MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.c
MdeModulePkg/Universal/SetupBrowserDxe/Expression.c
MdePkg/Include/Library/BaseLib.h
MdePkg/Library/BaseLib/String.c

index 73ddcaab784fffaabc121fa7a3d8538a8ce31556..2caa6f0dca355a8c56f9cf14f6f8d5d2fb646b91 100644 (file)
@@ -764,4 +764,116 @@ IfrLibCreatePopUp2 (
   )\r
 ;\r
 \r
+/**\r
+  Test if  a Unicode character is a hexadecimal digit. If true, the input\r
+  Unicode character is converted to a byte. \r
+\r
+  This function tests if a Unicode character is a hexadecimal digit. If true, the input\r
+  Unicode character is converted to a byte. For example, Unicode character\r
+  L'A' will be converted to 0x0A. \r
+\r
+  If Digit is NULL, then ASSERT.\r
+\r
+  @param  Digit       The output hexadecimal digit.\r
+\r
+  @param  Char        The input Unicode character.\r
+\r
+  @retval TRUE        Char is in the range of Hexadecimal number. Digit is updated\r
+                      to the byte value of the number.\r
+  @retval FALSE       Char is not in the range of Hexadecimal number. Digit is keep\r
+                      intact.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsHexDigit (\r
+  OUT UINT8      *Digit,\r
+  IN  CHAR16      Char\r
+  )\r
+;\r
+\r
+\r
+/** \r
+  Convert binary buffer to a Unicode String in a specified sequence. \r
+\r
+  This function converts bytes in the memory block pointed by Buffer to a Unicode String Str. \r
+  Each byte will be represented by two Unicode characters. For example, byte 0xA1 will \r
+  be converted into two Unicode character L'A' and L'1'. In the output String, the Unicode Character \r
+  for the Most Significant Nibble will be put before the Unicode Character for the Least Significant\r
+  Nibble. The output string for the buffer containing a single byte 0xA1 will be L"A1". \r
+  For a buffer with multiple bytes, the Unicode character produced by the first byte will be put into the \r
+  the last character in the output string. The one next to first byte will be put into the\r
+  character before the last character. This rules applies to the rest of the bytes. The Unicode\r
+  character by the last byte will be put into the first character in the output string. For example,\r
+  the input buffer for a 64-bits unsigned integer 0x12345678abcdef1234 will be converted to\r
+  a Unicode string equal to L"12345678abcdef1234".\r
+\r
+  @param String                        On input, String is pointed to the buffer allocated for the convertion.\r
+  @param StringLen                     The Length of String buffer to hold the output String. The length must include the tailing '\0' character.\r
+                                       The StringLen required to convert a N bytes Buffer will be a least equal to or greater \r
+                                       than 2*N + 1.\r
+  @param Buffer                        The pointer to a input buffer.\r
+  @param BufferSizeInBytes             Length in bytes of the input buffer.\r
+  \r
+\r
+  @retval  EFI_SUCCESS                 The convertion is successful. All bytes in Buffer has been convert to the corresponding\r
+                                       Unicode character and placed into the right place in String.\r
+  @retval  EFI_BUFFER_TOO_SMALL        StringSizeInBytes is smaller than 2 * N + 1the number of bytes required to\r
+                                       complete the convertion. \r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+BufToHexString (\r
+  IN OUT       CHAR16               *String,\r
+  IN OUT       UINTN                *StringLen,\r
+  IN     CONST UINT8                *Buffer,\r
+  IN           UINTN                BufferSizeInBytes\r
+  )\r
+;\r
+\r
+\r
+/**\r
+  Convert a Unicode string consisting of hexadecimal characters to a output byte buffer.\r
+\r
+  This function converts a Unicode string consisting of characters in the range of Hexadecimal\r
+  character (L'0' to L'9', L'A' to L'F' and L'a' to L'f') to a output byte buffer. The function will stop\r
+  at the first non-hexadecimal character or the NULL character. The convertion process can be\r
+  simply viewed as the reverse operations defined by BufToHexString. Two Unicode characters will be \r
+  converted into one byte. The first Unicode character represents the Most Significant Nibble and the\r
+  second Unicode character represents the Least Significant Nibble in the output byte. \r
+  The first pair of Unicode characters represents the last byte in the output buffer. The second pair of Unicode \r
+  characters represent the  the byte preceding the last byte. This rule applies to the rest pairs of bytes. \r
+  The last pair represent the first byte in the output buffer. \r
+\r
+  For example, a Unciode String L"12345678" will be converted into a buffer wil the following bytes \r
+  (first byte is the byte in the lowest memory address): "0x78, 0x56, 0x34, 0x12".\r
+\r
+  If String has N valid hexadecimal characters for conversion,  the caller must make sure Buffer is at least \r
+  N/2 (if N is even) or (N+1)/2 (if N if odd) bytes. \r
+\r
+  @param Buffer                      The output buffer allocated by the caller.\r
+  @param BufferSizeInBytes           On input, the size in bytes of Buffer. On output, it is updated to \r
+                                     contain the size of the Buffer which is actually used for the converstion.\r
+                                     For Unicode string with 2*N hexadecimal characters (not including the \r
+                                     tailing NULL character), N bytes of Buffer will be used for the output.\r
+  @param String                      The input hexadecimal string.\r
+  @param ConvertedStrLen             The number of hexadecimal characters used to produce content in output\r
+                                     buffer Buffer.\r
+\r
+  @retval  RETURN_BUFFER_TOO_SMALL   The input BufferSizeInBytes is too small to hold the output. BufferSizeInBytes\r
+                                     will be updated to the size required for the converstion.\r
+  @retval  RETURN_SUCCESS            The convertion is successful or the first Unicode character from String\r
+                                     is hexadecimal. If ConvertedStrLen is not NULL, it is updated\r
+                                     to the number of hexadecimal character used for the converstion.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+HexStringToBuf (\r
+  OUT          UINT8                    *Buffer,   \r
+  IN OUT       UINTN                    *BufferSizeInBytes,\r
+  IN     CONST CHAR16                   *String,\r
+  OUT          UINTN                    *ConvertedStrLen  OPTIONAL\r
+  )\r
+;\r
+\r
 #endif\r
index 4eeab90e05ca5c5aad86ebbb8852c5fee7beb792..1bf7e1f198dc79079f128fb306a4b9695c8edcc1 100644 (file)
@@ -42,6 +42,8 @@ Abstract:
 \r
 EFI_DPC_PROTOCOL *mDpc = NULL;\r
 \r
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mNetLibHexStr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};\r
+\r
 //\r
 // All the supported IP4 maskes in host byte order.\r
 //\r
@@ -1094,8 +1096,8 @@ NetLibGetMacString (
   // Convert the mac address into a unicode string.\r
   //\r
   for (Index = 0; Index < Mode->HwAddressSize; Index++) {\r
-    MacAddress[Index * 2]     = NibbleToHexChar ((UINT8) (Mode->CurrentAddress.Addr[Index] >> 4));\r
-    MacAddress[Index * 2 + 1] = NibbleToHexChar (Mode->CurrentAddress.Addr[Index]);\r
+    MacAddress[Index * 2]     = (CHAR16) mNetLibHexStr[(Mode->CurrentAddress.Addr[Index] >> 4) & 0x0F];\r
+    MacAddress[Index * 2 + 1] = (CHAR16) mNetLibHexStr[Mode->CurrentAddress.Addr[Index] & 0x0F];\r
   }\r
 \r
   MacAddress[Mode->HwAddressSize * 2] = L'\0';\r
index 878898ffeab8e567e44926522db1c4ca21cebf00..15bd2a1950969dd88e3aeb370189c5a30f51c886 100644 (file)
@@ -17,6 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 CONST EFI_FORM_BROWSER2_PROTOCOL      *mFormBrowser2     = NULL;\r
 CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *mIfrSupportLibHiiConfigRouting = NULL;\r
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mIfrSupportLibHexStr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};\r
 \r
 /**\r
   This function locate FormBrowser2 protocols for later usage.\r
@@ -1391,3 +1392,217 @@ SetBrowserData (
   FreePool (ConfigRequest);\r
   return Status;\r
 }\r
+\r
+/**\r
+  Test if  a Unicode character is a hexadecimal digit. If true, the input\r
+  Unicode character is converted to a byte. \r
+\r
+  This function tests if a Unicode character is a hexadecimal digit. If true, the input\r
+  Unicode character is converted to a byte. For example, Unicode character\r
+  L'A' will be converted to 0x0A. \r
+\r
+  If Digit is NULL, then ASSERT.\r
+\r
+  @param  Digit       The output hexadecimal digit.\r
+\r
+  @param  Char        The input Unicode character.\r
+\r
+  @retval TRUE        Char is in the range of Hexadecimal number. Digit is updated\r
+                      to the byte value of the number.\r
+  @retval FALSE       Char is not in the range of Hexadecimal number. Digit is keep\r
+                      intact.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsHexDigit (\r
+  OUT UINT8      *Digit,\r
+  IN  CHAR16      Char\r
+  )\r
+{\r
+  ASSERT (Digit != NULL);\r
+  \r
+  if ((Char >= L'0') && (Char <= L'9')) {\r
+    *Digit = (UINT8) (Char - L'0');\r
+    return TRUE;\r
+  }\r
+\r
+  if ((Char >= L'A') && (Char <= L'F')) {\r
+    *Digit = (UINT8) (Char - L'A' + 0x0A);\r
+    return TRUE;\r
+  }\r
+\r
+  if ((Char >= L'a') && (Char <= L'f')) {\r
+    *Digit = (UINT8) (Char - L'a' + 0x0A);\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+/** \r
+  Convert binary buffer to a Unicode String in a specified sequence. \r
+\r
+  This function converts bytes in the memory block pointed by Buffer to a Unicode String Str. \r
+  Each byte will be represented by two Unicode characters. For example, byte 0xA1 will \r
+  be converted into two Unicode character L'A' and L'1'. In the output String, the Unicode Character \r
+  for the Most Significant Nibble will be put before the Unicode Character for the Least Significant\r
+  Nibble. The output string for the buffer containing a single byte 0xA1 will be L"A1". \r
+  For a buffer with multiple bytes, the Unicode character produced by the first byte will be put into the \r
+  the last character in the output string. The one next to first byte will be put into the\r
+  character before the last character. This rules applies to the rest of the bytes. The Unicode\r
+  character by the last byte will be put into the first character in the output string. For example,\r
+  the input buffer for a 64-bits unsigned integer 0x12345678abcdef1234 will be converted to\r
+  a Unicode string equal to L"12345678abcdef1234".\r
+\r
+  @param String                        On input, String is pointed to the buffer allocated for the convertion.\r
+  @param StringLen                     The Length of String buffer to hold the output String. The length must include the tailing '\0' character.\r
+                                       The StringLen required to convert a N bytes Buffer will be a least equal to or greater \r
+                                       than 2*N + 1.\r
+  @param Buffer                        The pointer to a input buffer.\r
+  @param BufferSizeInBytes             Length in bytes of the input buffer.\r
+\r
+\r
+  @retval  EFI_SUCCESS                 The convertion is successful. All bytes in Buffer has been convert to the corresponding\r
+                                       Unicode character and placed into the right place in String.\r
+  @retval  EFI_BUFFER_TOO_SMALL        StringSizeInBytes is smaller than 2 * N + 1the number of bytes required to\r
+                                       complete the convertion. \r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+BufToHexString (\r
+  IN OUT       CHAR16               *String,\r
+  IN OUT       UINTN                *StringLen,\r
+  IN     CONST UINT8                *Buffer,\r
+  IN           UINTN                BufferSizeInBytes\r
+  )\r
+{\r
+  UINTN       Idx;\r
+  UINT8       Byte;\r
+  UINTN       StrLen;\r
+\r
+  //\r
+  // Make sure string is either passed or allocate enough.\r
+  // It takes 2 Unicode characters (4 bytes) to represent 1 byte of the binary buffer.\r
+  // Plus the Unicode termination character.\r
+  //\r
+  StrLen = BufferSizeInBytes * 2;\r
+  if (StrLen > ((*StringLen) - 1)) {\r
+    *StringLen = StrLen + 1;\r
+    return RETURN_BUFFER_TOO_SMALL;\r
+  }\r
+\r
+  *StringLen = StrLen + 1;\r
+  //\r
+  // Ends the string.\r
+  //\r
+  String[StrLen] = L'\0'; \r
+\r
+  for (Idx = 0; Idx < BufferSizeInBytes; Idx++) {\r
+    Byte = Buffer[Idx];\r
+    String[StrLen - 1 - Idx * 2] = mIfrSupportLibHexStr [Byte & 0xF];\r
+    String[StrLen - 2 - Idx * 2] = mIfrSupportLibHexStr [Byte >> 4];\r
+  }\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Convert a Unicode string consisting of hexadecimal characters to a output byte buffer.\r
+\r
+  This function converts a Unicode string consisting of characters in the range of Hexadecimal\r
+  character (L'0' to L'9', L'A' to L'F' and L'a' to L'f') to a output byte buffer. The function will stop\r
+  at the first non-hexadecimal character or the NULL character. The convertion process can be\r
+  simply viewed as the reverse operations defined by BufToHexString. Two Unicode characters will be \r
+  converted into one byte. The first Unicode character represents the Most Significant Nibble and the\r
+  second Unicode character represents the Least Significant Nibble in the output byte. \r
+  The first pair of Unicode characters represents the last byte in the output buffer. The second pair of Unicode \r
+  characters represent the  the byte preceding the last byte. This rule applies to the rest pairs of bytes. \r
+  The last pair represent the first byte in the output buffer. \r
+\r
+  For example, a Unciode String L"12345678" will be converted into a buffer wil the following bytes \r
+  (first byte is the byte in the lowest memory address): "0x78, 0x56, 0x34, 0x12".\r
+\r
+  If String has N valid hexadecimal characters for conversion,  the caller must make sure Buffer is at least \r
+  N/2 (if N is even) or (N+1)/2 (if N if odd) bytes. \r
+\r
+  @param Buffer                      The output buffer allocated by the caller.\r
+  @param BufferSizeInBytes           On input, the size in bytes of Buffer. On output, it is updated to \r
+                                     contain the size of the Buffer which is actually used for the converstion.\r
+                                     For Unicode string with 2*N hexadecimal characters (not including the \r
+                                     tailing NULL character), N bytes of Buffer will be used for the output.\r
+  @param String                      The input hexadecimal string.\r
+  @param ConvertedStrLen             The number of hexadecimal characters used to produce content in output\r
+                                     buffer Buffer.\r
+\r
+  @retval  RETURN_BUFFER_TOO_SMALL   The input BufferSizeInBytes is too small to hold the output. BufferSizeInBytes\r
+                                     will be updated to the size required for the converstion.\r
+  @retval  RETURN_SUCCESS            The convertion is successful or the first Unicode character from String\r
+                                     is hexadecimal. If ConvertedStrLen is not NULL, it is updated\r
+                                     to the number of hexadecimal character used for the converstion.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+HexStringToBuf (\r
+  OUT          UINT8                    *Buffer,   \r
+  IN OUT       UINTN                    *BufferSizeInBytes,\r
+  IN     CONST CHAR16                   *String,\r
+  OUT          UINTN                    *ConvertedStrLen  OPTIONAL\r
+  )\r
+{\r
+  UINTN       HexCnt;\r
+  UINTN       Idx;\r
+  UINTN       BufferLength;\r
+  UINT8       Digit;\r
+  UINT8       Byte;\r
+\r
+  //\r
+  // Find out how many hex characters the string has.\r
+  //\r
+  for (Idx = 0, HexCnt = 0; IsHexDigit (&Digit, String[Idx]); Idx++, HexCnt++);\r
+\r
+  if (HexCnt == 0) {\r
+    *ConvertedStrLen = 0;\r
+    return RETURN_SUCCESS;\r
+  }\r
+  //\r
+  // Two Unicode characters make up 1 buffer byte. Round up.\r
+  //\r
+  BufferLength = (HexCnt + 1) / 2; \r
+\r
+  //\r
+  // Test if  buffer is passed enough.\r
+  //\r
+  if (BufferLength > (*BufferSizeInBytes)) {\r
+    *BufferSizeInBytes = BufferLength;\r
+    return RETURN_BUFFER_TOO_SMALL;\r
+  }\r
+\r
+  *BufferSizeInBytes = BufferLength;\r
+\r
+  for (Idx = 0; Idx < HexCnt; Idx++) {\r
+\r
+    IsHexDigit (&Digit, String[HexCnt - 1 - Idx]);\r
+\r
+    //\r
+    // For odd charaters, write the lower nibble for each buffer byte,\r
+    // and for even characters, the upper nibble.\r
+    //\r
+    if ((Idx & 1) == 0) {\r
+      Byte = Digit;\r
+    } else {\r
+      Byte = Buffer[Idx / 2];\r
+      Byte &= 0x0F;\r
+      Byte = (UINT8) (Byte | Digit << 4);\r
+    }\r
+\r
+    Buffer[Idx / 2] = Byte;\r
+  }\r
+\r
+  if (ConvertedStrLen != NULL) {\r
+    *ConvertedStrLen = HexCnt;\r
+  }\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
index e183abbfe054d3ab51e7fda75f9a17fc052893b2..dbd371ce705c8160fb52d51c4765d38f5b4bd54a 100644 (file)
@@ -308,19 +308,7 @@ Xtoi (
   IN CHAR16  *Str\r
   )\r
 {\r
-  UINTN   Rvalue;\r
-  UINTN   Length;\r
-\r
-  ASSERT (Str != NULL);\r
-\r
-  //\r
-  // convert hex digits\r
-  //\r
-  Rvalue = 0;\r
-  Length = sizeof (UINTN);\r
-  HexStringToBuf ((UINT8 *) &Rvalue, &Length, Str, NULL);\r
-\r
-  return Rvalue;\r
+  return StrHexToUintn (Str);\r
 }\r
 \r
 /**\r
@@ -337,11 +325,7 @@ Xtoi64 (
   OUT UINT64  *Data\r
   )\r
 {\r
-  UINTN  Length;\r
-\r
-  *Data  = 0;\r
-  Length = sizeof (UINT64);\r
-  HexStringToBuf ((UINT8 *) Data, &Length, Str, NULL);\r
+  *Data = StrHexToUint64 (Str);\r
 }\r
 \r
 /**\r
@@ -524,7 +508,15 @@ StrToBuf (
 \r
   for(Index = 0; Index < StrLength; Index++, Str++) {\r
 \r
-    IsHexDigit (&Digit, *Str);\r
+    if ((*Str >= L'a') && (*Str <= L'f')) {\r
+      Digit = (UINT8) (*Str - L'a' + 0x0A);\r
+    } else if ((*Str >= L'A') && (*Str <= L'F')) {\r
+      Digit = (UINT8) (*Str - L'A' + 0x0A);\r
+    } else if ((*Str >= L'0') && (*Str <= L'9')) {\r
+      Digit = (UINT8) (*Str - L'0');\r
+    } else {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
 \r
     //\r
     // For odd charaters, write the upper nibble for each buffer byte,\r
@@ -546,6 +538,7 @@ StrToBuf (
 \r
 /**\r
   Converts a string to GUID value.\r
+  Guid Format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\r
 \r
   @param Str              The registry format GUID string that contains the GUID value.\r
   @param Guid             A pointer to the converted GUID value.\r
@@ -561,46 +554,51 @@ StrToGuid (
   OUT EFI_GUID *Guid\r
   )\r
 {\r
-  UINTN       BufferLength;\r
-  UINTN       ConvertedStrLen;\r
-  EFI_STATUS  Status;\r
-\r
-  BufferLength = sizeof (Guid->Data1);\r
-  Status = HexStringToBuf ((UINT8 *) &Guid->Data1, &BufferLength, Str, &ConvertedStrLen);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
+  //\r
+  // Get the first UINT32 data\r
+  //\r
+  Guid->Data1 = (UINT32) StrHexToUint64  (Str);\r
+  while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) {\r
+    Str ++;\r
   }\r
-  Str += ConvertedStrLen;\r
+  \r
   if (IS_HYPHEN (*Str)) {\r
     Str++;\r
   } else {\r
     return EFI_UNSUPPORTED;\r
   }\r
-\r
-  BufferLength = sizeof (Guid->Data2);\r
-  Status = HexStringToBuf ((UINT8 *) &Guid->Data2, &BufferLength, Str, &ConvertedStrLen);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
+  \r
+  //\r
+  // Get the second UINT16 data\r
+  //\r
+  Guid->Data2 = (UINT16) StrHexToUint64  (Str);\r
+  while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) {\r
+    Str ++;\r
   }\r
-  Str += ConvertedStrLen;\r
+\r
   if (IS_HYPHEN (*Str)) {\r
     Str++;\r
   } else {\r
     return EFI_UNSUPPORTED;\r
   }\r
-\r
-  BufferLength = sizeof (Guid->Data3);\r
-  Status = HexStringToBuf ((UINT8 *) &Guid->Data3, &BufferLength, Str, &ConvertedStrLen);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
+  \r
+  //\r
+  // Get the third UINT16 data\r
+  //\r
+  Guid->Data3 = (UINT16) StrHexToUint64  (Str);\r
+  while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) {\r
+    Str ++;\r
   }\r
-  Str += ConvertedStrLen;\r
+\r
   if (IS_HYPHEN (*Str)) {\r
     Str++;\r
   } else {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  //\r
+  // Get the followin 8 bytes data\r
+  //  \r
   StrToBuf (&Guid->Data4[0], 2, Str);\r
   //\r
   // Skip 2 byte hex chars\r
index 53de070a2a08da479bbdd08412569a5facd66f88..7cbf362275656aaf15d6305bafc5c6b945964192 100644 (file)
@@ -22,7 +22,7 @@ Abstract:
 \r
 #include "IScsiImpl.h"\r
 \r
-CONST CHAR8  IScsiHexString[] = "0123456789ABCDEFabcdef";\r
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8  IScsiHexString[] = "0123456789ABCDEFabcdef";\r
 \r
 /**\r
   Removes (trims) specified leading and trailing characters from a string.\r
@@ -216,9 +216,9 @@ IScsiLunToUnicodeStr (
       StrCpy (TempStr, L"0-");\r
     } else {\r
       TempStr[0]  = (CHAR16) IScsiHexString[Lun[2 * Index] >> 4];\r
-      TempStr[1]  = (CHAR16) IScsiHexString[Lun[2 * Index] & 0xf];\r
+      TempStr[1]  = (CHAR16) IScsiHexString[Lun[2 * Index] & 0x0F];\r
       TempStr[2]  = (CHAR16) IScsiHexString[Lun[2 * Index + 1] >> 4];\r
-      TempStr[3]  = (CHAR16) IScsiHexString[Lun[2 * Index + 1] & 0xf];\r
+      TempStr[3]  = (CHAR16) IScsiHexString[Lun[2 * Index + 1] & 0x0F];\r
       TempStr[4]  = L'-';\r
       TempStr[5]  = 0;\r
 \r
@@ -388,8 +388,8 @@ IScsiMacAddrToStr (
   UINT32  Index;\r
 \r
   for (Index = 0; Index < Len; Index++) {\r
-    Str[3 * Index]      = NibbleToHexChar ((UINT8) (Mac->Addr[Index] >> 4));\r
-    Str[3 * Index + 1]  = NibbleToHexChar (Mac->Addr[Index]);\r
+    Str[3 * Index]      = (CHAR16) IScsiHexString[(Mac->Addr[Index] >> 4) & 0x0F];\r
+    Str[3 * Index + 1]  = (CHAR16) IScsiHexString[Mac->Addr[Index] & 0x0F];\r
     Str[3 * Index + 2]  = L'-';\r
   }\r
 \r
@@ -441,7 +441,7 @@ IScsiBinToHex (
 \r
   for (Index = 0; Index < BinLength; Index++) {\r
     HexStr[Index * 2 + 2] = IScsiHexString[BinBuffer[Index] >> 4];\r
-    HexStr[Index * 2 + 3] = IScsiHexString[BinBuffer[Index] & 0xf];\r
+    HexStr[Index * 2 + 3] = IScsiHexString[BinBuffer[Index] & 0x0F];\r
   }\r
 \r
   HexStr[Index * 2 + 2] = '\0';\r
index a56c7318b4856d8feb4c692283f0dcb59b7c7bf2..5044fd16425d1b2b25b2bf2158ee01ea6a07192c 100644 (file)
@@ -619,7 +619,6 @@ IfrToUint (
   EFI_HII_VALUE  Value;\r
   CHAR16         *String;\r
   CHAR16         *StringPtr;\r
-  UINTN          BufferSize;\r
 \r
   Status = PopExpression (&Value);\r
   if (EFI_ERROR (Status)) {\r
@@ -636,19 +635,19 @@ IfrToUint (
     if (String == NULL) {\r
       return EFI_NOT_FOUND;\r
     }\r
-\r
+    \r
     IfrStrToUpper (String);\r
     StringPtr = StrStr (String, L"0X");\r
     if (StringPtr != NULL) {\r
       //\r
       // Hex string\r
       //\r
-      BufferSize = sizeof (UINT64);\r
-      Status = HexStringToBuf ((UINT8 *) &Result->Value.u64, &BufferSize, StringPtr + 2, NULL);\r
+      Result->Value.u64 = StrHexToUint64 (String);\r
     } else {\r
       //\r
-      // BUGBUG: Need handle decimal string\r
+      // decimal string\r
       //\r
+      Result->Value.u64 = StrDecimalToUint64 (String);\r
     }\r
     FreePool (String);\r
   } else {\r
index 5c569ce78ae40eb26106db87a07f3738bdeea207..cf4e1896087c111645a6acb14c545495dc56b3ec 100644 (file)
@@ -602,135 +602,6 @@ StrHexToUint64 (
   IN      CONST CHAR16             *String\r
   );\r
 \r
-/**\r
-  Convert a nibble in the low 4 bits of a byte to a Unicode hexadecimal character.\r
-\r
-  This function converts a nibble in the low 4 bits of a byte to a Unicode hexadecimal \r
-  character  For example, the nibble  0x01 and 0x0A will converted to L'1' and L'A' \r
-  respectively.\r
-\r
-  The upper nibble in the input byte will be masked off.\r
-\r
-  @param Nibble     The nibble which is in the low 4 bits of the input byte.\r
-\r
-  @retval  CHAR16   The Unicode hexadecimal character.\r
-  \r
-**/\r
-CHAR16\r
-EFIAPI\r
-NibbleToHexChar (\r
-  IN UINT8      Nibble\r
-  );\r
-\r
-/** \r
-  Convert binary buffer to a Unicode String in a specified sequence. \r
-\r
-  This function converts bytes in the memory block pointed by Buffer to a Unicode String Str. \r
-  Each byte will be represented by two Unicode characters. For example, byte 0xA1 will \r
-  be converted into two Unicode character L'A' and L'1'. In the output String, the Unicode Character \r
-  for the Most Significant Nibble will be put before the Unicode Character for the Least Significant\r
-  Nibble. The output string for the buffer containing a single byte 0xA1 will be L"A1". \r
-  For a buffer with multiple bytes, the Unicode character produced by the first byte will be put into the \r
-  the last character in the output string. The one next to first byte will be put into the\r
-  character before the last character. This rules applies to the rest of the bytes. The Unicode\r
-  character by the last byte will be put into the first character in the output string. For example,\r
-  the input buffer for a 64-bits unsigned integer 0x12345678abcdef1234 will be converted to\r
-  a Unicode string equal to L"12345678abcdef1234".\r
-\r
-  @param String                        On input, String is pointed to the buffer allocated for the convertion.\r
-  @param StringLen                     The Length of String buffer to hold the output String. The length must include the tailing '\0' character.\r
-                                       The StringLen required to convert a N bytes Buffer will be a least equal to or greater \r
-                                       than 2*N + 1.\r
-  @param Buffer                        The pointer to a input buffer.\r
-  @param BufferSizeInBytes             Length in bytes of the input buffer.\r
-  \r
-\r
-  @retval  EFI_SUCCESS                 The convertion is successful. All bytes in Buffer has been convert to the corresponding\r
-                                       Unicode character and placed into the right place in String.\r
-  @retval  EFI_BUFFER_TOO_SMALL        StringSizeInBytes is smaller than 2 * N + 1the number of bytes required to\r
-                                       complete the convertion. \r
-**/\r
-RETURN_STATUS\r
-EFIAPI\r
-BufToHexString (\r
-  IN OUT       CHAR16               *String,\r
-  IN OUT       UINTN                *StringLen,\r
-  IN     CONST UINT8                *Buffer,\r
-  IN           UINTN                BufferSizeInBytes\r
-  );\r
-\r
-\r
-/**\r
-  Convert a Unicode string consisting of hexadecimal characters to a output byte buffer.\r
-\r
-  This function converts a Unicode string consisting of characters in the range of Hexadecimal\r
-  character (L'0' to L'9', L'A' to L'F' and L'a' to L'f') to a output byte buffer. The function will stop\r
-  at the first non-hexadecimal character or the NULL character. The convertion process can be\r
-  simply viewed as the reverse operations defined by BufToHexString. Two Unicode characters will be \r
-  converted into one byte. The first Unicode character represents the Most Significant Nibble and the\r
-  second Unicode character represents the Least Significant Nibble in the output byte. \r
-  The first pair of Unicode characters represents the last byte in the output buffer. The second pair of Unicode \r
-  characters represent the  the byte preceding the last byte. This rule applies to the rest pairs of bytes. \r
-  The last pair represent the first byte in the output buffer. \r
-\r
-  For example, a Unciode String L"12345678" will be converted into a buffer wil the following bytes \r
-  (first byte is the byte in the lowest memory address): "0x78, 0x56, 0x34, 0x12".\r
-\r
-  If String has N valid hexadecimal characters for conversion,  the caller must make sure Buffer is at least \r
-  N/2 (if N is even) or (N+1)/2 (if N if odd) bytes. \r
-\r
-  @param Buffer                      The output buffer allocated by the caller.\r
-  @param BufferSizeInBytes           On input, the size in bytes of Buffer. On output, it is updated to \r
-                                     contain the size of the Buffer which is actually used for the converstion.\r
-                                     For Unicode string with 2*N hexadecimal characters (not including the \r
-                                     tailing NULL character), N bytes of Buffer will be used for the output.\r
-  @param String                      The input hexadecimal string.\r
-  @param ConvertedStrLen             The number of hexadecimal characters used to produce content in output\r
-                                     buffer Buffer.\r
-\r
-  @retval  RETURN_BUFFER_TOO_SMALL   The input BufferSizeInBytes is too small to hold the output. BufferSizeInBytes\r
-                                     will be updated to the size required for the converstion.\r
-  @retval  RETURN_SUCCESS            The convertion is successful or the first Unicode character from String\r
-                                     is hexadecimal. If ConvertedStrLen is not NULL, it is updated\r
-                                     to the number of hexadecimal character used for the converstion.\r
-**/\r
-RETURN_STATUS\r
-EFIAPI\r
-HexStringToBuf (\r
-  OUT          UINT8                    *Buffer,   \r
-  IN OUT       UINTN                    *BufferSizeInBytes,\r
-  IN     CONST CHAR16                   *String,\r
-  OUT          UINTN                    *ConvertedStrLen  OPTIONAL\r
-  );\r
-\r
-\r
-/**\r
-  Test if  a Unicode character is a hexadecimal digit. If true, the input\r
-  Unicode character is converted to a byte. \r
-\r
-  This function tests if a Unicode character is a hexadecimal digit. If true, the input\r
-  Unicode character is converted to a byte. For example, Unicode character\r
-  L'A' will be converted to 0x0A. \r
-\r
-  If Digit is NULL, then ASSERT.\r
-\r
-  @param  Digit       The output hexadecimal digit.\r
-\r
-  @param  Char        The input Unicode character.\r
-\r
-  @retval TRUE        Char is in the range of Hexadecimal number. Digit is updated\r
-                      to the byte value of the number.\r
-  @retval FALSE       Char is not in the range of Hexadecimal number. Digit is keep\r
-                      intact.\r
-  \r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-IsHexDigit (\r
-  OUT UINT8      *Digit,\r
-  IN  CHAR16      Char\r
-  );\r
-\r
 /**\r
   Convert a Null-terminated Unicode string to a Null-terminated\r
   ASCII string and returns the ASCII string.\r
index e056fa06cbe529a323923e53d15d9711bb510e60..fb3211d77c76c4d38da621490cf0e118af0ac4ef 100644 (file)
@@ -2074,250 +2074,3 @@ BcdToDecimal8 (
   ASSERT ((Value & 0xf) < 0xa);\r
   return (UINT8) ((Value >> 4) * 10 + (Value & 0xf));\r
 }\r
-\r
-\r
-/**\r
-  Convert a nibble in the low 4 bits of a byte to a Unicode hexadecimal character.\r
-\r
-  This function converts a nibble in the low 4 bits of a byte to a Unicode hexadecimal \r
-  character  For example, the nibble  0x01 and 0x0A will converted to L'1' and L'A' \r
-  respectively.\r
-\r
-  The upper nibble in the input byte will be masked off.\r
-\r
-  @param Nibble     The nibble which is in the low 4 bits of the input byte.\r
-\r
-  @retval  CHAR16   The Unicode hexadecimal character.\r
-\r
-**/\r
-CHAR16\r
-EFIAPI\r
-NibbleToHexChar (\r
-  IN UINT8      Nibble\r
-  )\r
-{\r
-  Nibble &= 0x0F;\r
-  if (Nibble <= 0x9) {\r
-    return (CHAR16)(Nibble + L'0');\r
-  }\r
-\r
-  return (CHAR16)(Nibble - 0xA + L'A');\r
-}\r
-\r
-/** \r
-  Convert binary buffer to a Unicode String in a specified sequence. \r
-\r
-  This function converts bytes in the memory block pointed by Buffer to a Unicode String Str. \r
-  Each byte will be represented by two Unicode characters. For example, byte 0xA1 will \r
-  be converted into two Unicode character L'A' and L'1'. In the output String, the Unicode Character \r
-  for the Most Significant Nibble will be put before the Unicode Character for the Least Significant\r
-  Nibble. The output string for the buffer containing a single byte 0xA1 will be L"A1". \r
-  For a buffer with multiple bytes, the Unicode character produced by the first byte will be put into the \r
-  the last character in the output string. The one next to first byte will be put into the\r
-  character before the last character. This rules applies to the rest of the bytes. The Unicode\r
-  character by the last byte will be put into the first character in the output string. For example,\r
-  the input buffer for a 64-bits unsigned integer 0x12345678abcdef1234 will be converted to\r
-  a Unicode string equal to L"12345678abcdef1234".\r
-\r
-  @param String                        On input, String is pointed to the buffer allocated for the convertion.\r
-  @param StringLen                     The Length of String buffer to hold the output String. The length must include the tailing '\0' character.\r
-                                       The StringLen required to convert a N bytes Buffer will be a least equal to or greater \r
-                                       than 2*N + 1.\r
-  @param Buffer                        The pointer to a input buffer.\r
-  @param BufferSizeInBytes             Length in bytes of the input buffer.\r
-\r
-\r
-  @retval  EFI_SUCCESS                 The convertion is successful. All bytes in Buffer has been convert to the corresponding\r
-                                       Unicode character and placed into the right place in String.\r
-  @retval  EFI_BUFFER_TOO_SMALL        StringSizeInBytes is smaller than 2 * N + 1the number of bytes required to\r
-                                       complete the convertion. \r
-**/\r
-RETURN_STATUS\r
-EFIAPI\r
-BufToHexString (\r
-  IN OUT       CHAR16               *String,\r
-  IN OUT       UINTN                *StringLen,\r
-  IN     CONST UINT8                *Buffer,\r
-  IN           UINTN                BufferSizeInBytes\r
-  )\r
-{\r
-  UINTN       Idx;\r
-  UINT8       Byte;\r
-  UINTN       StrLen;\r
-\r
-  //\r
-  // Make sure string is either passed or allocate enough.\r
-  // It takes 2 Unicode characters (4 bytes) to represent 1 byte of the binary buffer.\r
-  // Plus the Unicode termination character.\r
-  //\r
-  StrLen = BufferSizeInBytes * 2;\r
-  if (StrLen > ((*StringLen) - 1)) {\r
-    *StringLen = StrLen + 1;\r
-    return RETURN_BUFFER_TOO_SMALL;\r
-  }\r
-\r
-  *StringLen = StrLen + 1;\r
-  //\r
-  // Ends the string.\r
-  //\r
-  String[StrLen] = L'\0'; \r
-\r
-  for (Idx = 0; Idx < BufferSizeInBytes; Idx++) {\r
-\r
-    Byte = Buffer[Idx];\r
-    String[StrLen - 1 - Idx * 2] = NibbleToHexChar (Byte);\r
-    String[StrLen - 2 - Idx * 2] = NibbleToHexChar ((UINT8)(Byte >> 4));\r
-  }\r
-\r
-  return RETURN_SUCCESS;\r
-}\r
-\r
-\r
-/**\r
-  Convert a Unicode string consisting of hexadecimal characters to a output byte buffer.\r
-\r
-  This function converts a Unicode string consisting of characters in the range of Hexadecimal\r
-  character (L'0' to L'9', L'A' to L'F' and L'a' to L'f') to a output byte buffer. The function will stop\r
-  at the first non-hexadecimal character or the NULL character. The convertion process can be\r
-  simply viewed as the reverse operations defined by BufToHexString. Two Unicode characters will be \r
-  converted into one byte. The first Unicode character represents the Most Significant Nibble and the\r
-  second Unicode character represents the Least Significant Nibble in the output byte. \r
-  The first pair of Unicode characters represents the last byte in the output buffer. The second pair of Unicode \r
-  characters represent the  the byte preceding the last byte. This rule applies to the rest pairs of bytes. \r
-  The last pair represent the first byte in the output buffer. \r
-\r
-  For example, a Unciode String L"12345678" will be converted into a buffer wil the following bytes \r
-  (first byte is the byte in the lowest memory address): "0x78, 0x56, 0x34, 0x12".\r
-\r
-  If String has N valid hexadecimal characters for conversion,  the caller must make sure Buffer is at least \r
-  N/2 (if N is even) or (N+1)/2 (if N if odd) bytes. \r
-\r
-  @param Buffer                      The output buffer allocated by the caller.\r
-  @param BufferSizeInBytes           On input, the size in bytes of Buffer. On output, it is updated to \r
-                                     contain the size of the Buffer which is actually used for the converstion.\r
-                                     For Unicode string with 2*N hexadecimal characters (not including the \r
-                                     tailing NULL character), N bytes of Buffer will be used for the output.\r
-  @param String                      The input hexadecimal string.\r
-  @param ConvertedStrLen             The number of hexadecimal characters used to produce content in output\r
-                                     buffer Buffer.\r
-\r
-  @retval  RETURN_BUFFER_TOO_SMALL   The input BufferSizeInBytes is too small to hold the output. BufferSizeInBytes\r
-                                     will be updated to the size required for the converstion.\r
-  @retval  RETURN_SUCCESS            The convertion is successful or the first Unicode character from String\r
-                                     is hexadecimal. If ConvertedStrLen is not NULL, it is updated\r
-                                     to the number of hexadecimal character used for the converstion.\r
-**/\r
-RETURN_STATUS\r
-EFIAPI\r
-HexStringToBuf (\r
-  OUT          UINT8                    *Buffer,   \r
-  IN OUT       UINTN                    *BufferSizeInBytes,\r
-  IN     CONST CHAR16                   *String,\r
-  OUT          UINTN                    *ConvertedStrLen  OPTIONAL\r
-  )\r
-{\r
-  UINTN       HexCnt;\r
-  UINTN       Idx;\r
-  UINTN       BufferLength;\r
-  UINT8       Digit;\r
-  UINT8       Byte;\r
-\r
-  //\r
-  // Find out how many hex characters the string has.\r
-  //\r
-  for (Idx = 0, HexCnt = 0; IsHexDigit (&Digit, String[Idx]); Idx++, HexCnt++);\r
-\r
-  if (HexCnt == 0) {\r
-    *ConvertedStrLen = 0;\r
-    return RETURN_SUCCESS;\r
-  }\r
-  //\r
-  // Two Unicode characters make up 1 buffer byte. Round up.\r
-  //\r
-  BufferLength = (HexCnt + 1) / 2; \r
-\r
-  //\r
-  // Test if  buffer is passed enough.\r
-  //\r
-  if (BufferLength > (*BufferSizeInBytes)) {\r
-    *BufferSizeInBytes = BufferLength;\r
-    return RETURN_BUFFER_TOO_SMALL;\r
-  }\r
-\r
-  *BufferSizeInBytes = BufferLength;\r
-\r
-  for (Idx = 0; Idx < HexCnt; Idx++) {\r
-\r
-    IsHexDigit (&Digit, String[HexCnt - 1 - Idx]);\r
-\r
-    //\r
-    // For odd charaters, write the lower nibble for each buffer byte,\r
-    // and for even characters, the upper nibble.\r
-    //\r
-    if ((Idx & 1) == 0) {\r
-      Byte = Digit;\r
-    } else {\r
-      Byte = Buffer[Idx / 2];\r
-      Byte &= 0x0F;\r
-      Byte = (UINT8) (Byte | Digit << 4);\r
-    }\r
-\r
-    Buffer[Idx / 2] = Byte;\r
-  }\r
-\r
-  if (ConvertedStrLen != NULL) {\r
-    *ConvertedStrLen = HexCnt;\r
-  }\r
-\r
-  return RETURN_SUCCESS;\r
-}\r
-\r
-\r
-/**\r
-  Test if  a Unicode character is a hexadecimal digit. If true, the input\r
-  Unicode character is converted to a byte. \r
-\r
-  This function tests if a Unicode character is a hexadecimal digit. If true, the input\r
-  Unicode character is converted to a byte. For example, Unicode character\r
-  L'A' will be converted to 0x0A. \r
-\r
-  If Digit is NULL, then ASSERT.\r
-\r
-  @param  Digit       The output hexadecimal digit.\r
-\r
-  @param  Char        The input Unicode character.\r
-\r
-  @retval TRUE        Char is in the range of Hexadecimal number. Digit is updated\r
-                      to the byte value of the number.\r
-  @retval FALSE       Char is not in the range of Hexadecimal number. Digit is keep\r
-                      intact.\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-IsHexDigit (\r
-  OUT UINT8      *Digit,\r
-  IN  CHAR16      Char\r
-  )\r
-{\r
-  ASSERT (Digit != NULL);\r
-  \r
-  if ((Char >= L'0') && (Char <= L'9')) {\r
-    *Digit = (UINT8) (Char - L'0');\r
-    return TRUE;\r
-  }\r
-\r
-  if ((Char >= L'A') && (Char <= L'F')) {\r
-    *Digit = (UINT8) (Char - L'A' + 0x0A);\r
-    return TRUE;\r
-  }\r
-\r
-  if ((Char >= L'a') && (Char <= L'f')) {\r
-    *Digit = (UINT8) (Char - L'a' + 0x0A);\r
-    return TRUE;\r
-  }\r
-\r
-  return FALSE;\r
-}\r
-\r
-\r