]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/R8Lib.c
2 Copyright (c) 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
25 Converts the low nibble of a byte to hex unicode character.
28 Nibble - lower nibble of a byte.
31 Hex unicode character.
37 return (CHAR16
)(Nibble
+ L
'0');
40 return (CHAR16
)(Nibble
- 0xA + L
'A');
46 Converts binary buffer to Unicode string.
47 At a minimum, any blob of data could be represented as a hex string.
49 @param Str Pointer to the string.
50 @param HexStringBufferLength Length in bytes of buffer to hold the hex string.
51 Includes tailing '\0' character. If routine return
52 with EFI_SUCCESS, containing length of hex string
53 buffer. If routine return with
54 EFI_BUFFER_TOO_SMALL, containg length of hex
55 string buffer desired.
56 @param Buf Buffer to be converted from.
57 @param Len Length in bytes of the buffer to be converted.
59 @retval EFI_SUCCESS Routine success.
60 @retval EFI_BUFFER_TOO_SMALL The hex string buffer is too small.
66 IN OUT UINTN
*HexStringBufferLength
,
73 // This library interface is simply obsolete.
74 // Include the source code to user code.
81 // Make sure string is either passed or allocate enough.
82 // It takes 2 Unicode characters (4 bytes) to represent 1 byte of the binary buffer.
83 // Plus the Unicode termination character.
86 if (StrLen
> ((*HexStringBufferLength
) - 1)) {
87 *HexStringBufferLength
= StrLen
+ 1;
88 return EFI_BUFFER_TOO_SMALL
;
91 *HexStringBufferLength
= StrLen
+ 1;
97 for (Idx
= 0; Idx
< Len
; Idx
++) {
100 Str
[StrLen
- 1 - Idx
* 2] = NibbleToHexChar (Byte
);
101 Str
[StrLen
- 2 - Idx
* 2] = NibbleToHexChar ((UINT8
)(Byte
>> 4));
111 Converts Unicode string to binary buffer.
112 The conversion may be partial.
113 The first character in the string that is not hex digit stops the conversion.
114 At a minimum, any blob of data could be represented as a hex string.
116 @param Buf Pointer to buffer that receives the data.
117 @param Len Length in bytes of the buffer to hold converted
118 data. If routine return with EFI_SUCCESS,
119 containing length of converted data. If routine
120 return with EFI_BUFFER_TOO_SMALL, containg length
122 @param Str String to be converted from.
123 @param ConvertedStrLen Length of the Hex String consumed.
125 @retval EFI_SUCCESS Routine Success.
126 @retval EFI_BUFFER_TOO_SMALL The buffer is too small to hold converted data.
134 OUT UINTN
*ConvertedStrLen OPTIONAL
139 // This library interface is simply obsolete.
140 // Include the source code to user code.
150 // Find out how many hex characters the string has.
152 for (Idx
= 0, HexCnt
= 0; R8_IsHexDigit (&Digit
, Str
[Idx
]); Idx
++, HexCnt
++);
159 // Two Unicode characters make up 1 buffer byte. Round up.
161 BufferLength
= (HexCnt
+ 1) / 2;
164 // Test if buffer is passed enough.
166 if (BufferLength
> (*Len
)) {
168 return EFI_BUFFER_TOO_SMALL
;
173 for (Idx
= 0; Idx
< HexCnt
; Idx
++) {
175 R8_IsHexDigit (&Digit
, Str
[HexCnt
- 1 - Idx
]);
178 // For odd charaters, write the lower nibble for each buffer byte,
179 // and for even characters, the upper nibble.
181 if ((Idx
& 1) == 0) {
186 Byte
= (UINT8
) (Byte
| Digit
<< 4);
192 if (ConvertedStrLen
!= NULL
) {
193 *ConvertedStrLen
= HexCnt
;
203 Determines if a Unicode character is a hexadecimal digit.
204 The test is case insensitive.
206 @param Digit Pointer to byte that receives the value of the hex
208 @param Char Unicode character to test.
210 @retval TRUE If the character is a hexadecimal digit.
211 @retval FALSE Otherwise.
222 // This library interface is simply obsolete.
223 // Include the source code to user code.
226 if ((Char
>= L
'0') && (Char
<= L
'9')) {
227 *Digit
= (UINT8
) (Char
- L
'0');
231 if ((Char
>= L
'A') && (Char
<= L
'F')) {
232 *Digit
= (UINT8
) (Char
- L
'A' + 0x0A);
236 if ((Char
>= L
'a') && (Char
<= L
'f')) {
237 *Digit
= (UINT8
) (Char
- L
'a' + 0x0A);