]>
git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/SetupBrowserDxe/R8Lib.c
1ffeb1bb9d4216b1d17f8378ecfb9d1945a2ea95
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.
24 Converts the low nibble of a byte to hex unicode character.
27 Nibble - lower nibble of a byte.
30 Hex unicode character.
36 return (CHAR16
)(Nibble
+ L
'0');
39 return (CHAR16
)(Nibble
- 0xA + L
'A');
45 Converts binary buffer to Unicode string.
46 At a minimum, any blob of data could be represented as a hex string.
48 @param Str Pointer to the string.
49 @param HexStringBufferLength Length in bytes of buffer to hold the hex string.
50 Includes tailing '\0' character. If routine return
51 with EFI_SUCCESS, containing length of hex string
52 buffer. If routine return with
53 EFI_BUFFER_TOO_SMALL, containg length of hex
54 string buffer desired.
55 @param Buf Buffer to be converted from.
56 @param Len Length in bytes of the buffer to be converted.
58 @retval EFI_SUCCESS Routine success.
59 @retval EFI_BUFFER_TOO_SMALL The hex string buffer is too small.
65 IN OUT UINTN
*HexStringBufferLength
,
72 // This library interface is simply obsolete.
73 // Include the source code to user code.
80 // Make sure string is either passed or allocate enough.
81 // It takes 2 Unicode characters (4 bytes) to represent 1 byte of the binary buffer.
82 // Plus the Unicode termination character.
85 if (StrLen
> ((*HexStringBufferLength
) - 1)) {
86 *HexStringBufferLength
= StrLen
+ 1;
87 return EFI_BUFFER_TOO_SMALL
;
90 *HexStringBufferLength
= StrLen
+ 1;
96 for (Idx
= 0; Idx
< Len
; Idx
++) {
99 Str
[StrLen
- 1 - Idx
* 2] = NibbleToHexChar (Byte
);
100 Str
[StrLen
- 2 - Idx
* 2] = NibbleToHexChar ((UINT8
)(Byte
>> 4));
110 Converts Unicode string to binary buffer.
111 The conversion may be partial.
112 The first character in the string that is not hex digit stops the conversion.
113 At a minimum, any blob of data could be represented as a hex string.
115 @param Buf Pointer to buffer that receives the data.
116 @param Len Length in bytes of the buffer to hold converted
117 data. If routine return with EFI_SUCCESS,
118 containing length of converted data. If routine
119 return with EFI_BUFFER_TOO_SMALL, containg length
121 @param Str String to be converted from.
122 @param ConvertedStrLen Length of the Hex String consumed.
124 @retval EFI_SUCCESS Routine Success.
125 @retval EFI_BUFFER_TOO_SMALL The buffer is too small to hold converted data.
133 OUT UINTN
*ConvertedStrLen OPTIONAL
138 // This library interface is simply obsolete.
139 // Include the source code to user code.
149 // Find out how many hex characters the string has.
151 for (Idx
= 0, HexCnt
= 0; R8_IsHexDigit (&Digit
, Str
[Idx
]); Idx
++, HexCnt
++);
158 // Two Unicode characters make up 1 buffer byte. Round up.
160 BufferLength
= (HexCnt
+ 1) / 2;
163 // Test if buffer is passed enough.
165 if (BufferLength
> (*Len
)) {
167 return EFI_BUFFER_TOO_SMALL
;
172 for (Idx
= 0; Idx
< HexCnt
; Idx
++) {
174 R8_IsHexDigit (&Digit
, Str
[HexCnt
- 1 - Idx
]);
177 // For odd charaters, write the lower nibble for each buffer byte,
178 // and for even characters, the upper nibble.
180 if ((Idx
& 1) == 0) {
185 Byte
= (UINT8
) (Byte
| Digit
<< 4);
191 if (ConvertedStrLen
!= NULL
) {
192 *ConvertedStrLen
= HexCnt
;
202 Determines if a Unicode character is a hexadecimal digit.
203 The test is case insensitive.
205 @param Digit Pointer to byte that receives the value of the hex
207 @param Char Unicode character to test.
209 @retval TRUE If the character is a hexadecimal digit.
210 @retval FALSE Otherwise.
221 // This library interface is simply obsolete.
222 // Include the source code to user code.
225 if ((Char
>= L
'0') && (Char
<= L
'9')) {
226 *Digit
= (UINT8
) (Char
- L
'0');
230 if ((Char
>= L
'A') && (Char
<= L
'F')) {
231 *Digit
= (UINT8
) (Char
- L
'A' + 0x0A);
235 if ((Char
>= L
'a') && (Char
<= L
'f')) {
236 *Digit
= (UINT8
) (Char
- L
'a' + 0x0A);