diff options
author | lgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524> | 2008-12-01 02:32:12 +0000 |
---|---|---|
committer | lgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524> | 2008-12-01 02:32:12 +0000 |
commit | ac7e320cb8326befd240020db709151884c889bc (patch) | |
tree | 0244f130be9838647093dbabad4ee7d0d7b5348a /MdeModulePkg/Include | |
parent | 48bd50c5a1e4c31818bba1d2ce88f9270b2f2440 (diff) | |
download | edk2-platforms-ac7e320cb8326befd240020db709151884c889bc.tar.xz |
Remove NibbleToHexChar() function from BaseLib
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
Diffstat (limited to 'MdeModulePkg/Include')
-rw-r--r-- | MdeModulePkg/Include/Library/IfrSupportLib.h | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/MdeModulePkg/Include/Library/IfrSupportLib.h b/MdeModulePkg/Include/Library/IfrSupportLib.h index 73ddcaab78..2caa6f0dca 100644 --- a/MdeModulePkg/Include/Library/IfrSupportLib.h +++ b/MdeModulePkg/Include/Library/IfrSupportLib.h @@ -764,4 +764,116 @@ IfrLibCreatePopUp2 ( )
;
+/**
+ Test if a Unicode character is a hexadecimal digit. If true, the input
+ Unicode character is converted to a byte.
+
+ This function tests if a Unicode character is a hexadecimal digit. If true, the input
+ Unicode character is converted to a byte. For example, Unicode character
+ L'A' will be converted to 0x0A.
+
+ If Digit is NULL, then ASSERT.
+
+ @param Digit The output hexadecimal digit.
+
+ @param Char The input Unicode character.
+
+ @retval TRUE Char is in the range of Hexadecimal number. Digit is updated
+ to the byte value of the number.
+ @retval FALSE Char is not in the range of Hexadecimal number. Digit is keep
+ intact.
+
+**/
+BOOLEAN
+EFIAPI
+IsHexDigit (
+ OUT UINT8 *Digit,
+ IN CHAR16 Char
+ )
+;
+
+
+/**
+ Convert binary buffer to a Unicode String in a specified sequence.
+
+ This function converts bytes in the memory block pointed by Buffer to a Unicode String Str.
+ Each byte will be represented by two Unicode characters. For example, byte 0xA1 will
+ be converted into two Unicode character L'A' and L'1'. In the output String, the Unicode Character
+ for the Most Significant Nibble will be put before the Unicode Character for the Least Significant
+ Nibble. The output string for the buffer containing a single byte 0xA1 will be L"A1".
+ For a buffer with multiple bytes, the Unicode character produced by the first byte will be put into the
+ the last character in the output string. The one next to first byte will be put into the
+ character before the last character. This rules applies to the rest of the bytes. The Unicode
+ character by the last byte will be put into the first character in the output string. For example,
+ the input buffer for a 64-bits unsigned integer 0x12345678abcdef1234 will be converted to
+ a Unicode string equal to L"12345678abcdef1234".
+
+ @param String On input, String is pointed to the buffer allocated for the convertion.
+ @param StringLen The Length of String buffer to hold the output String. The length must include the tailing '\0' character.
+ The StringLen required to convert a N bytes Buffer will be a least equal to or greater
+ than 2*N + 1.
+ @param Buffer The pointer to a input buffer.
+ @param BufferSizeInBytes Length in bytes of the input buffer.
+
+
+ @retval EFI_SUCCESS The convertion is successful. All bytes in Buffer has been convert to the corresponding
+ Unicode character and placed into the right place in String.
+ @retval EFI_BUFFER_TOO_SMALL StringSizeInBytes is smaller than 2 * N + 1the number of bytes required to
+ complete the convertion.
+**/
+RETURN_STATUS
+EFIAPI
+BufToHexString (
+ IN OUT CHAR16 *String,
+ IN OUT UINTN *StringLen,
+ IN CONST UINT8 *Buffer,
+ IN UINTN BufferSizeInBytes
+ )
+;
+
+
+/**
+ Convert a Unicode string consisting of hexadecimal characters to a output byte buffer.
+
+ This function converts a Unicode string consisting of characters in the range of Hexadecimal
+ 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
+ at the first non-hexadecimal character or the NULL character. The convertion process can be
+ simply viewed as the reverse operations defined by BufToHexString. Two Unicode characters will be
+ converted into one byte. The first Unicode character represents the Most Significant Nibble and the
+ second Unicode character represents the Least Significant Nibble in the output byte.
+ The first pair of Unicode characters represents the last byte in the output buffer. The second pair of Unicode
+ characters represent the the byte preceding the last byte. This rule applies to the rest pairs of bytes.
+ The last pair represent the first byte in the output buffer.
+
+ For example, a Unciode String L"12345678" will be converted into a buffer wil the following bytes
+ (first byte is the byte in the lowest memory address): "0x78, 0x56, 0x34, 0x12".
+
+ If String has N valid hexadecimal characters for conversion, the caller must make sure Buffer is at least
+ N/2 (if N is even) or (N+1)/2 (if N if odd) bytes.
+
+ @param Buffer The output buffer allocated by the caller.
+ @param BufferSizeInBytes On input, the size in bytes of Buffer. On output, it is updated to
+ contain the size of the Buffer which is actually used for the converstion.
+ For Unicode string with 2*N hexadecimal characters (not including the
+ tailing NULL character), N bytes of Buffer will be used for the output.
+ @param String The input hexadecimal string.
+ @param ConvertedStrLen The number of hexadecimal characters used to produce content in output
+ buffer Buffer.
+
+ @retval RETURN_BUFFER_TOO_SMALL The input BufferSizeInBytes is too small to hold the output. BufferSizeInBytes
+ will be updated to the size required for the converstion.
+ @retval RETURN_SUCCESS The convertion is successful or the first Unicode character from String
+ is hexadecimal. If ConvertedStrLen is not NULL, it is updated
+ to the number of hexadecimal character used for the converstion.
+**/
+RETURN_STATUS
+EFIAPI
+HexStringToBuf (
+ OUT UINT8 *Buffer,
+ IN OUT UINTN *BufferSizeInBytes,
+ IN CONST CHAR16 *String,
+ OUT UINTN *ConvertedStrLen OPTIONAL
+ )
+;
+
#endif
|