2 Unicode Collation Support component that hides the trivial difference of Unicode Collation
3 and Unicode collation 2 Protocol.
5 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
12 EFI_UNICODE_COLLATION_PROTOCOL
*mUnicodeCollationInterface
= NULL
;
15 Worker function to initialize Unicode Collation support.
17 It tries to locate Unicode Collation (2) protocol and matches it with current
18 platform language code.
20 @param AgentHandle The handle used to open Unicode Collation (2) protocol.
21 @param ProtocolGuid The pointer to Unicode Collation (2) protocol GUID.
22 @param VariableName The name of the RFC 4646 or ISO 639-2 language variable.
23 @param DefaultLanguage The default language in case the RFC 4646 or ISO 639-2 language is absent.
25 @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.
26 @retval Others The Unicode Collation (2) protocol has not been located.
30 InitializeUnicodeCollationSupportWorker (
31 IN EFI_HANDLE AgentHandle
,
32 IN EFI_GUID
*ProtocolGuid
,
33 IN CONST CHAR16
*VariableName
,
34 IN CONST CHAR8
*DefaultLanguage
37 EFI_STATUS ReturnStatus
;
42 EFI_UNICODE_COLLATION_PROTOCOL
*Uci
;
43 BOOLEAN Iso639Language
;
47 Status
= gBS
->LocateHandleBuffer (
54 if (EFI_ERROR (Status
)) {
58 Iso639Language
= (BOOLEAN
) (ProtocolGuid
== &gEfiUnicodeCollationProtocolGuid
);
59 GetEfiGlobalVariable2 (VariableName
, (VOID
**) &Language
, NULL
);
61 ReturnStatus
= EFI_UNSUPPORTED
;
62 for (Index
= 0; Index
< NumHandles
; Index
++) {
64 // Open Unicode Collation Protocol
66 Status
= gBS
->OpenProtocol (
72 EFI_OPEN_PROTOCOL_GET_PROTOCOL
74 if (EFI_ERROR (Status
)) {
79 // Find the best matching matching language from the supported languages
80 // of Unicode Collation (2) protocol.
82 BestLanguage
= GetBestLanguage (
83 Uci
->SupportedLanguages
,
85 (Language
== NULL
) ? "" : Language
,
89 if (BestLanguage
!= NULL
) {
90 FreePool (BestLanguage
);
91 mUnicodeCollationInterface
= Uci
;
92 ReturnStatus
= EFI_SUCCESS
;
97 if (Language
!= NULL
) {
107 Initialize Unicode Collation support.
109 It tries to locate Unicode Collation 2 protocol and matches it with current
110 platform language code. If for any reason the first attempt fails, it then tries to
111 use Unicode Collation Protocol.
113 @param AgentHandle The handle used to open Unicode Collation (2) protocol.
115 @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.
116 @retval Others The Unicode Collation (2) protocol has not been located.
120 InitializeUnicodeCollationSupport (
121 IN EFI_HANDLE AgentHandle
127 Status
= EFI_UNSUPPORTED
;
130 // First try to use RFC 4646 Unicode Collation 2 Protocol.
132 Status
= InitializeUnicodeCollationSupportWorker (
134 &gEfiUnicodeCollation2ProtocolGuid
,
136 (CONST CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
)
139 // If the attempt to use Unicode Collation 2 Protocol fails, then we fall back
140 // on the ISO 639-2 Unicode Collation Protocol.
142 if (EFI_ERROR (Status
)) {
143 Status
= InitializeUnicodeCollationSupportWorker (
145 &gEfiUnicodeCollationProtocolGuid
,
147 (CONST CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultLang
)
156 Performs a case-insensitive comparison of two Null-terminated Unicode strings.
158 @param S1 A pointer to a Null-terminated Unicode string.
159 @param S2 A pointer to a Null-terminated Unicode string.
161 @retval 0 S1 is equivalent to S2.
162 @retval >0 S1 is lexically greater than S2.
163 @retval <0 S1 is lexically less than S2.
171 ASSERT (StrSize (S1
) != 0);
172 ASSERT (StrSize (S2
) != 0);
173 ASSERT (mUnicodeCollationInterface
!= NULL
);
175 return mUnicodeCollationInterface
->StriColl (
176 mUnicodeCollationInterface
,
186 @param String The string which will be upper-cased.
192 IN OUT CHAR16
*String
195 ASSERT (StrSize (String
) != 0);
196 ASSERT (mUnicodeCollationInterface
!= NULL
);
198 mUnicodeCollationInterface
->StrUpr (mUnicodeCollationInterface
, String
);
205 @param String The string which will be lower-cased.
211 IN OUT CHAR16
*String
214 ASSERT (StrSize (String
) != 0);
215 ASSERT (mUnicodeCollationInterface
!= NULL
);
217 mUnicodeCollationInterface
->StrLwr (mUnicodeCollationInterface
, String
);
222 Convert FAT string to unicode string.
224 @param FatSize The size of FAT string.
225 @param Fat The FAT string.
226 @param String The unicode string.
238 ASSERT (Fat
!= NULL
);
239 ASSERT (String
!= NULL
);
240 ASSERT (((UINTN
) String
& 0x01) == 0);
241 ASSERT (mUnicodeCollationInterface
!= NULL
);
243 mUnicodeCollationInterface
->FatToStr (mUnicodeCollationInterface
, FatSize
, Fat
, String
);
248 Convert unicode string to Fat string.
250 @param String The unicode string.
251 @param FatSize The size of the FAT string.
252 @param Fat The FAT string.
254 @retval TRUE Convert successfully.
255 @retval FALSE Convert error.
265 ASSERT (Fat
!= NULL
);
266 ASSERT (StrSize (String
) != 0);
267 ASSERT (mUnicodeCollationInterface
!= NULL
);
269 return mUnicodeCollationInterface
->StrToFat (
270 mUnicodeCollationInterface
,