TianoCore EDK2 master
Loading...
Searching...
No Matches
UnicodeCollation.c
Go to the documentation of this file.
1
10#include "Fat.h"
11
12EFI_UNICODE_COLLATION_PROTOCOL *mUnicodeCollationInterface = NULL;
13
31 IN EFI_HANDLE AgentHandle,
32 IN EFI_GUID *ProtocolGuid,
33 IN CONST CHAR16 *VariableName,
34 IN CONST CHAR8 *DefaultLanguage
35 )
36{
37 EFI_STATUS ReturnStatus;
38 EFI_STATUS Status;
39 UINTN NumHandles;
40 UINTN Index;
41 EFI_HANDLE *Handles;
43 BOOLEAN Iso639Language;
44 CHAR8 *Language;
45 CHAR8 *BestLanguage;
46
47 Status = gBS->LocateHandleBuffer (
49 ProtocolGuid,
50 NULL,
51 &NumHandles,
52 &Handles
53 );
54 if (EFI_ERROR (Status)) {
55 return Status;
56 }
57
58 Iso639Language = (BOOLEAN)(ProtocolGuid == &gEfiUnicodeCollationProtocolGuid);
59 GetEfiGlobalVariable2 (VariableName, (VOID **)&Language, NULL);
60
61 ReturnStatus = EFI_UNSUPPORTED;
62 for (Index = 0; Index < NumHandles; Index++) {
63 //
64 // Open Unicode Collation Protocol
65 //
66 Status = gBS->OpenProtocol (
67 Handles[Index],
68 ProtocolGuid,
69 (VOID **)&Uci,
70 AgentHandle,
71 NULL,
72 EFI_OPEN_PROTOCOL_GET_PROTOCOL
73 );
74 if (EFI_ERROR (Status)) {
75 continue;
76 }
77
78 //
79 // Find the best matching matching language from the supported languages
80 // of Unicode Collation (2) protocol.
81 //
82 BestLanguage = GetBestLanguage (
83 Uci->SupportedLanguages,
84 Iso639Language,
85 (Language == NULL) ? "" : Language,
86 DefaultLanguage,
87 NULL
88 );
89 if (BestLanguage != NULL) {
90 FreePool (BestLanguage);
91 mUnicodeCollationInterface = Uci;
92 ReturnStatus = EFI_SUCCESS;
93 break;
94 }
95 }
96
97 if (Language != NULL) {
98 FreePool (Language);
99 }
100
101 FreePool (Handles);
102
103 return ReturnStatus;
104}
105
121 IN EFI_HANDLE AgentHandle
122 )
123{
124 EFI_STATUS Status;
125
126 Status = EFI_UNSUPPORTED;
127
128 //
129 // First try to use RFC 4646 Unicode Collation 2 Protocol.
130 //
132 AgentHandle,
133 &gEfiUnicodeCollation2ProtocolGuid,
134 L"PlatformLang",
135 (CONST CHAR8 *)PcdGetPtr (PcdUefiVariableDefaultPlatformLang)
136 );
137 //
138 // If the attempt to use Unicode Collation 2 Protocol fails, then we fall back
139 // on the ISO 639-2 Unicode Collation Protocol.
140 //
141 if (EFI_ERROR (Status)) {
143 AgentHandle,
144 &gEfiUnicodeCollationProtocolGuid,
145 L"Lang",
146 (CONST CHAR8 *)PcdGetPtr (PcdUefiVariableDefaultLang)
147 );
148 }
149
150 return Status;
151}
152
163INTN
165 IN CHAR16 *S1,
166 IN CHAR16 *S2
167 )
168{
169 ASSERT (StrSize (S1) != 0);
170 ASSERT (StrSize (S2) != 0);
171 ASSERT (mUnicodeCollationInterface != NULL);
172
173 return mUnicodeCollationInterface->StriColl (
174 mUnicodeCollationInterface,
175 S1,
176 S2
177 );
178}
179
187VOID
189 IN OUT CHAR16 *String
190 )
191{
192 ASSERT (StrSize (String) != 0);
193 ASSERT (mUnicodeCollationInterface != NULL);
194
195 mUnicodeCollationInterface->StrUpr (mUnicodeCollationInterface, String);
196}
197
205VOID
207 IN OUT CHAR16 *String
208 )
209{
210 ASSERT (StrSize (String) != 0);
211 ASSERT (mUnicodeCollationInterface != NULL);
212
213 mUnicodeCollationInterface->StrLwr (mUnicodeCollationInterface, String);
214}
215
226VOID
228 IN UINTN FatSize,
229 IN CHAR8 *Fat,
230 OUT CHAR16 *String
231 )
232{
233 ASSERT (Fat != NULL);
234 ASSERT (String != NULL);
235 ASSERT (((UINTN)String & 0x01) == 0);
236 ASSERT (mUnicodeCollationInterface != NULL);
237
238 mUnicodeCollationInterface->FatToStr (mUnicodeCollationInterface, FatSize, Fat, String);
239}
240
252BOOLEAN
254 IN CHAR16 *String,
255 IN UINTN FatSize,
256 OUT CHAR8 *Fat
257 )
258{
259 ASSERT (Fat != NULL);
260 ASSERT (StrSize (String) != 0);
261 ASSERT (mUnicodeCollationInterface != NULL);
262
263 return mUnicodeCollationInterface->StrToFat (
264 mUnicodeCollationInterface,
265 String,
266 FatSize,
267 Fat
268 );
269}
UINT64 UINTN
INT64 INTN
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define PcdGetPtr(TokenName)
Definition: PcdLib.h:388
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI GetEfiGlobalVariable2(IN CONST CHAR16 *Name, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
Definition: UefiLib.c:1470
CHAR8 *EFIAPI GetBestLanguage(IN CONST CHAR8 *SupportedLanguages, IN UINTN Iso639Language,...)
Definition: UefiLib.c:1522
@ ByProtocol
Definition: UefiSpec.h:1518
BOOLEAN FatStrToFat(IN CHAR16 *String, IN UINTN FatSize, OUT CHAR8 *Fat)
VOID FatFatToStr(IN UINTN FatSize, IN CHAR8 *Fat, OUT CHAR16 *String)
INTN FatStriCmp(IN CHAR16 *S1, IN CHAR16 *S2)
EFI_STATUS InitializeUnicodeCollationSupportWorker(IN EFI_HANDLE AgentHandle, IN EFI_GUID *ProtocolGuid, IN CONST CHAR16 *VariableName, IN CONST CHAR8 *DefaultLanguage)
VOID FatStrLwr(IN OUT CHAR16 *String)
VOID FatStrUpr(IN OUT CHAR16 *String)
EFI_STATUS InitializeUnicodeCollationSupport(IN EFI_HANDLE AgentHandle)
Definition: Base.h:213