]>
git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/HiiDatabaseDxe/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.
15 #include "HiiDatabase.h"
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');
44 Compare whether two names of languages are identical.
46 @param Language1 Name of language 1
47 @param Language2 Name of language 2
50 @retval FALSE not same
54 R8_EfiLibCompareLanguage (
61 // This library interface is simply obsolete.
62 // Include the source code to user code.
66 for (Index
= 0; (Language1
[Index
] != 0) && (Language2
[Index
] != 0); Index
++) {
67 if (Language1
[Index
] != Language2
[Index
]) {
72 if (((Language1
[Index
] == 0) && (Language2
[Index
] == 0)) ||
73 ((Language1
[Index
] == 0) && (Language2
[Index
] != ';')) ||
74 ((Language1
[Index
] == ';') && (Language2
[Index
] != 0)) ||
75 ((Language1
[Index
] == ';') && (Language2
[Index
] != ';'))) {
86 Converts binary buffer to Unicode string.
87 At a minimum, any blob of data could be represented as a hex string.
89 @param Str Pointer to the string.
90 @param HexStringBufferLength Length in bytes of buffer to hold the hex string.
91 Includes tailing '\0' character. If routine return
92 with EFI_SUCCESS, containing length of hex string
93 buffer. If routine return with
94 EFI_BUFFER_TOO_SMALL, containg length of hex
95 string buffer desired.
96 @param Buf Buffer to be converted from.
97 @param Len Length in bytes of the buffer to be converted.
99 @retval EFI_SUCCESS Routine success.
100 @retval EFI_BUFFER_TOO_SMALL The hex string buffer is too small.
106 IN OUT UINTN
*HexStringBufferLength
,
113 // This library interface is simply obsolete.
114 // Include the source code to user code.
121 // Make sure string is either passed or allocate enough.
122 // It takes 2 Unicode characters (4 bytes) to represent 1 byte of the binary buffer.
123 // Plus the Unicode termination character.
126 if (StrLen
> ((*HexStringBufferLength
) - 1)) {
127 *HexStringBufferLength
= StrLen
+ 1;
128 return EFI_BUFFER_TOO_SMALL
;
131 *HexStringBufferLength
= StrLen
+ 1;
137 for (Idx
= 0; Idx
< Len
; Idx
++) {
140 Str
[StrLen
- 1 - Idx
* 2] = NibbleToHexChar (Byte
);
141 Str
[StrLen
- 2 - Idx
* 2] = NibbleToHexChar ((UINT8
)(Byte
>> 4));
151 Converts Unicode string to binary buffer.
152 The conversion may be partial.
153 The first character in the string that is not hex digit stops the conversion.
154 At a minimum, any blob of data could be represented as a hex string.
156 @param Buf Pointer to buffer that receives the data.
157 @param Len Length in bytes of the buffer to hold converted
158 data. If routine return with EFI_SUCCESS,
159 containing length of converted data. If routine
160 return with EFI_BUFFER_TOO_SMALL, containg length
162 @param Str String to be converted from.
163 @param ConvertedStrLen Length of the Hex String consumed.
165 @retval EFI_SUCCESS Routine Success.
166 @retval EFI_BUFFER_TOO_SMALL The buffer is too small to hold converted data.
174 OUT UINTN
*ConvertedStrLen OPTIONAL
179 // This library interface is simply obsolete.
180 // Include the source code to user code.
190 // Find out how many hex characters the string has.
192 for (Idx
= 0, HexCnt
= 0; R8_IsHexDigit (&Digit
, Str
[Idx
]); Idx
++, HexCnt
++);
199 // Two Unicode characters make up 1 buffer byte. Round up.
201 BufferLength
= (HexCnt
+ 1) / 2;
204 // Test if buffer is passed enough.
206 if (BufferLength
> (*Len
)) {
208 return EFI_BUFFER_TOO_SMALL
;
213 for (Idx
= 0; Idx
< HexCnt
; Idx
++) {
215 R8_IsHexDigit (&Digit
, Str
[HexCnt
- 1 - Idx
]);
218 // For odd charaters, write the lower nibble for each buffer byte,
219 // and for even characters, the upper nibble.
221 if ((Idx
& 1) == 0) {
226 Byte
= (UINT8
) (Byte
| Digit
<< 4);
232 if (ConvertedStrLen
!= NULL
) {
233 *ConvertedStrLen
= HexCnt
;
243 Determines if a Unicode character is a hexadecimal digit.
244 The test is case insensitive.
246 @param Digit Pointer to byte that receives the value of the hex
248 @param Char Unicode character to test.
250 @retval TRUE If the character is a hexadecimal digit.
251 @retval FALSE Otherwise.
262 // This library interface is simply obsolete.
263 // Include the source code to user code.
266 if ((Char
>= L
'0') && (Char
<= L
'9')) {
267 *Digit
= (UINT8
) (Char
- L
'0');
271 if ((Char
>= L
'A') && (Char
<= L
'F')) {
272 *Digit
= (UINT8
) (Char
- L
'A' + 0x0A);
276 if ((Char
>= L
'a') && (Char
<= L
'f')) {
277 *Digit
= (UINT8
) (Char
- L
'a' + 0x0A);