35 ASSERT (Utf8Buffer !=
NULL);
37 TempChar = *Utf8Buffer;
38 if ((TempChar & 0xF0) == 0xF0) {
46 if ((TempChar & 0x80) == 0x80) {
47 if ((TempChar & 0xC0) == 0xC0) {
49 if ((TempChar & 0xE0) == 0xE0) {
81 CHAR8 Ucs2CharFormat[UNICODE_FORMAT_CHAR_SIZE];
83 for (Index = 0; Index < 4; Index++) {
84 if ((*(Utf8Buffer + 2 + Index) & 0x80) != 0x00) {
85 return EFI_INVALID_PARAMETER;
89 ZeroMem (Ucs2CharFormat, UNICODE_FORMAT_CHAR_SIZE);
94 CopyMem (Ucs2CharFormat, Utf8Buffer + 2, UNICODE_FORMAT_CHAR_LEN);
100 CopyMem (Ucs2CharFormat, Utf8Buffer + 4, UNICODE_FORMAT_CHAR_LEN);
106 *((CHAR8 *)Ucs2Char) = Num2;
107 *(((CHAR8 *)Ucs2Char) + 1) = Num1;
124 OUT CHAR8 *Utf8Buffer
129 ASSERT (Utf8Buffer !=
NULL);
131 Ucs2Number = (UINT16)Ucs2Char;
132 if (Ucs2Number <= 0x007F) {
136 *Utf8Buffer = Ucs2Char & 0x7F;
138 }
else if ((Ucs2Number >= 0x0080) && (Ucs2Number <= 0x07FF)) {
142 *(Utf8Buffer + 1) = (Ucs2Char & 0x3F) | 0x80;
143 *Utf8Buffer = ((Ucs2Char >> 6) & 0x1F) | 0xC0;
151 *(Utf8Buffer + 2) = (Ucs2Char & 0x3F) | 0x80;
152 *(Utf8Buffer + 1) = ((Ucs2Char >> 6) & 0x3F) | 0x80;
153 *Utf8Buffer = ((Ucs2Char >> 12) & 0x0F) | 0xE0;
171 IN CHAR8 *Utf8Buffer,
181 ASSERT (Utf8Buffer !=
NULL && Ucs2Char !=
NULL);
182 ZeroMem (Ucs2Char,
sizeof (CHAR16));
183 Ucs2Buffer = (CHAR8 *)Ucs2Char;
192 TempChar1 = *Utf8Buffer;
193 if ((TempChar1 & 0x80) != 0x00) {
194 return EFI_INVALID_PARAMETER;
197 *Ucs2Buffer = TempChar1;
198 *(Ucs2Buffer + 1) = 0;
206 TempChar1 = *Utf8Buffer;
207 if ((TempChar1 & 0xE0) != 0xC0) {
208 return EFI_INVALID_PARAMETER;
211 TempChar2 = *(Utf8Buffer + 1);
212 if ((TempChar2 & 0xC0) != 0x80) {
213 return EFI_INVALID_PARAMETER;
216 *Ucs2Buffer = (TempChar1 << 6) + (TempChar2 & 0x3F);
217 *(Ucs2Buffer + 1) = (TempChar1 >> 2) & 0x07;
225 TempChar1 = *Utf8Buffer;
226 if ((TempChar1 & 0xF0) != 0xE0) {
227 return EFI_INVALID_PARAMETER;
230 TempChar2 = *(Utf8Buffer + 1);
231 if ((TempChar2 & 0xC0) != 0x80) {
232 return EFI_INVALID_PARAMETER;
235 TempChar3 = *(Utf8Buffer + 2);
236 if ((TempChar3 & 0xC0) != 0x80) {
237 return EFI_INVALID_PARAMETER;
240 *Ucs2Buffer = (TempChar2 << 6) + (TempChar3 & 0x3F);
241 *(Ucs2Buffer + 1) = (TempChar1 << 4) + ((TempChar2 >> 2) & 0x0F);
247 return EFI_INVALID_PARAMETER;
268 OUT CHAR8 **Utf8StrAddr
276 CHAR8 Utf8Buffer[UTF8_BUFFER_FOR_UCS2_MAX_SIZE];
277 UINT8 Utf8BufferSize;
279 if ((Ucs2Str ==
NULL) || (Utf8StrAddr ==
NULL)) {
280 return EFI_INVALID_PARAMETER;
283 Ucs2StrLength =
StrLen (Ucs2Str);
286 for (Ucs2StrIndex = 0; Ucs2StrIndex < Ucs2StrLength; Ucs2StrIndex++) {
287 ZeroMem (Utf8Buffer,
sizeof (Utf8Buffer));
288 Utf8BufferSize =
UCS2CharToUTF8 (Ucs2Str[Ucs2StrIndex], Utf8Buffer);
289 Utf8StrLength += Utf8BufferSize;
293 if (Utf8Str ==
NULL) {
294 return EFI_OUT_OF_RESOURCES;
298 for (Ucs2StrIndex = 0; Ucs2StrIndex < Ucs2StrLength; Ucs2StrIndex++) {
299 ZeroMem (Utf8Buffer,
sizeof (Utf8Buffer));
300 Utf8BufferSize =
UCS2CharToUTF8 (Ucs2Str[Ucs2StrIndex], Utf8Buffer);
302 CopyMem (Utf8Str + Utf8StrIndex, Utf8Buffer, Utf8BufferSize);
303 Utf8StrIndex += Utf8BufferSize;
306 Utf8Str[Utf8StrIndex] =
'\0';
307 *Utf8StrAddr = Utf8Str;
329 OUT CHAR16 **Ucs2StrAddr
336 UINT8 Utf8BufferSize;
339 if ((Utf8Str ==
NULL) || (Ucs2StrAddr ==
NULL)) {
340 return EFI_INVALID_PARAMETER;
347 while (*(Utf8Str + Utf8StrLength) !=
'\0') {
355 if (Ucs2StrTemp ==
NULL) {
356 return EFI_OUT_OF_RESOURCES;
361 while (Utf8Str[Utf8StrIndex] !=
'\0') {
362 if ((
CompareMem (Utf8Str + Utf8StrIndex,
"\\u", 2) == 0) &&
366 if (!EFI_ERROR (Status)) {
370 StrCpyS (Ucs2StrTemp + Ucs2StrIndex, 3, L
"\\u");
377 if ((Utf8BufferSize == 0) || (Utf8StrLength - Utf8StrIndex < Utf8BufferSize)) {
379 return EFI_INVALID_PARAMETER;
382 Status =
UTF8ToUCS2Char (Utf8Str + Utf8StrIndex, Ucs2StrTemp + Ucs2StrIndex);
383 if (EFI_ERROR (Status)) {
385 return EFI_INVALID_PARAMETER;
389 Utf8StrIndex += Utf8BufferSize;
394 if (*Ucs2StrAddr ==
NULL) {
396 return EFI_OUT_OF_RESOURCES;
399 StrCpyS (*Ucs2StrAddr, Ucs2StrIndex + 1, Ucs2StrTemp);
400 *(*Ucs2StrAddr + Ucs2StrIndex) = L
'\0';
RETURN_STATUS EFIAPI StrCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
UINTN EFIAPI AsciiStrHexToUintn(IN CONST CHAR8 *String)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
UINT8 GetUTF8SizeForUCS2(IN CHAR8 *Utf8Buffer)
EFI_STATUS UCS2StrToUTF8(IN CHAR16 *Ucs2Str, OUT CHAR8 **Utf8StrAddr)
EFI_STATUS UTF8ToUCS2Char(IN CHAR8 *Utf8Buffer, OUT CHAR16 *Ucs2Char)
EFI_STATUS UTF8StrToUCS2(IN CHAR8 *Utf8Str, OUT CHAR16 **Ucs2StrAddr)
EFI_STATUS GetUCS2CharByFormat(IN CHAR8 *Utf8Buffer, OUT CHAR16 *Ucs2Char)
UINT8 UCS2CharToUTF8(IN CHAR16 Ucs2Char, OUT CHAR8 *Utf8Buffer)
#define UNICODE_FORMAT_LEN
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)