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 This program and the accompanying materials are licensed and made available
7 under the terms and conditions of the BSD License which accompanies this
8 distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 EFI_UNICODE_COLLATION_PROTOCOL
*mUnicodeCollationInterface
= NULL
;
21 Worker function to initialize Unicode Collation support.
23 It tries to locate Unicode Collation (2) protocol and matches it with current
24 platform language code.
26 @param AgentHandle The handle used to open Unicode Collation (2) protocol.
27 @param ProtocolGuid The pointer to Unicode Collation (2) protocol GUID.
28 @param VariableName The name of the RFC 4646 or ISO 639-2 language variable.
29 @param DefaultLanguage The default language in case the RFC 4646 or ISO 639-2 language is absent.
31 @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.
32 @retval Others The Unicode Collation (2) protocol has not been located.
36 InitializeUnicodeCollationSupportWorker (
37 IN EFI_HANDLE AgentHandle
,
38 IN EFI_GUID
*ProtocolGuid
,
39 IN CONST CHAR16
*VariableName
,
40 IN CONST CHAR8
*DefaultLanguage
43 EFI_STATUS ReturnStatus
;
48 EFI_UNICODE_COLLATION_PROTOCOL
*Uci
;
49 BOOLEAN Iso639Language
;
53 Status
= gBS
->LocateHandleBuffer (
60 if (EFI_ERROR (Status
)) {
64 Iso639Language
= (BOOLEAN
) (ProtocolGuid
== &gEfiUnicodeCollationProtocolGuid
);
65 GetEfiGlobalVariable2 (VariableName
, (VOID
**) &Language
, NULL
);
67 ReturnStatus
= EFI_UNSUPPORTED
;
68 for (Index
= 0; Index
< NumHandles
; Index
++) {
70 // Open Unicode Collation Protocol
72 Status
= gBS
->OpenProtocol (
78 EFI_OPEN_PROTOCOL_GET_PROTOCOL
80 if (EFI_ERROR (Status
)) {
85 // Find the best matching matching language from the supported languages
86 // of Unicode Collation (2) protocol.
88 BestLanguage
= GetBestLanguage (
89 Uci
->SupportedLanguages
,
91 (Language
== NULL
) ? "" : Language
,
95 if (BestLanguage
!= NULL
) {
96 FreePool (BestLanguage
);
97 mUnicodeCollationInterface
= Uci
;
98 ReturnStatus
= EFI_SUCCESS
;
103 if (Language
!= NULL
) {
113 Initialize Unicode Collation support.
115 It tries to locate Unicode Collation 2 protocol and matches it with current
116 platform language code. If for any reason the first attempt fails, it then tries to
117 use Unicode Collation Protocol.
119 @param AgentHandle The handle used to open Unicode Collation (2) protocol.
121 @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.
122 @retval Others The Unicode Collation (2) protocol has not been located.
126 InitializeUnicodeCollationSupport (
127 IN EFI_HANDLE AgentHandle
133 Status
= EFI_UNSUPPORTED
;
136 // First try to use RFC 4646 Unicode Collation 2 Protocol.
138 Status
= InitializeUnicodeCollationSupportWorker (
140 &gEfiUnicodeCollation2ProtocolGuid
,
142 (CONST CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
)
145 // If the attempt to use Unicode Collation 2 Protocol fails, then we fall back
146 // on the ISO 639-2 Unicode Collation Protocol.
148 if (EFI_ERROR (Status
)) {
149 Status
= InitializeUnicodeCollationSupportWorker (
151 &gEfiUnicodeCollationProtocolGuid
,
153 (CONST CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultLang
)
162 Performs a case-insensitive comparison of two Null-terminated Unicode strings.
164 @param S1 A pointer to a Null-terminated Unicode string.
165 @param S2 A pointer to a Null-terminated Unicode string.
167 @retval 0 S1 is equivalent to S2.
168 @retval >0 S1 is lexically greater than S2.
169 @retval <0 S1 is lexically less than S2.
177 ASSERT (StrSize (S1
) != 0);
178 ASSERT (StrSize (S2
) != 0);
179 ASSERT (mUnicodeCollationInterface
!= NULL
);
181 return mUnicodeCollationInterface
->StriColl (
182 mUnicodeCollationInterface
,
192 @param String The string which will be upper-cased.
198 IN OUT CHAR16
*String
201 ASSERT (StrSize (String
) != 0);
202 ASSERT (mUnicodeCollationInterface
!= NULL
);
204 mUnicodeCollationInterface
->StrUpr (mUnicodeCollationInterface
, String
);
211 @param String The string which will be lower-cased.
217 IN OUT CHAR16
*String
220 ASSERT (StrSize (String
) != 0);
221 ASSERT (mUnicodeCollationInterface
!= NULL
);
223 mUnicodeCollationInterface
->StrLwr (mUnicodeCollationInterface
, String
);
228 Convert FAT string to unicode string.
230 @param FatSize The size of FAT string.
231 @param Fat The FAT string.
232 @param String The unicode string.
244 ASSERT (Fat
!= NULL
);
245 ASSERT (String
!= NULL
);
246 ASSERT (((UINTN
) String
& 0x01) == 0);
247 ASSERT (mUnicodeCollationInterface
!= NULL
);
249 mUnicodeCollationInterface
->FatToStr (mUnicodeCollationInterface
, FatSize
, Fat
, String
);
254 Convert unicode string to Fat string.
256 @param String The unicode string.
257 @param FatSize The size of the FAT string.
258 @param Fat The FAT string.
260 @retval TRUE Convert successfully.
261 @retval FALSE Convert error.
271 ASSERT (Fat
!= NULL
);
272 ASSERT (StrSize (String
) != 0);
273 ASSERT (mUnicodeCollationInterface
!= NULL
);
275 return mUnicodeCollationInterface
->StrToFat (
276 mUnicodeCollationInterface
,