2 Unicode Collation Support component that hides the trivial difference of Unicode Collation
3 and Unicode collation 2 Protocol.
5 Copyright (c) 2007 - 2009, Intel Corporation<BR>
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this 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 This function searches Initialized Unicode Collation support based on PCDs:
24 PcdUnicodeCollation2Support and PcdUnicodeCollationSupport.
25 It first tries to locate Unicode Collation 2 protocol and matches it with current
26 platform language code. If for any reason the first attempt fails, it then tries to
27 use Unicode Collation Protocol.
29 @param AgentHandle The handle used to open Unicode Collation (2) protocol.
30 @param ProtocolGuid The pointer to Unicode Collation (2) protocol GUID.
31 @param VariableName The name of the RFC 4646 or ISO 639-2 language variable.
32 @param DefaultLanguage The default language in case the RFC 4646 or ISO 639-2 language is absent.
34 @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.
35 @retval Others The Unicode Collation (2) protocol has not been located.
39 InitializeUnicodeCollationSupportWorker (
40 IN EFI_HANDLE AgentHandle
,
41 IN EFI_GUID
*ProtocolGuid
,
42 IN CONST CHAR16
*VariableName
,
43 IN CONST CHAR8
*DefaultLanguage
50 EFI_UNICODE_COLLATION_PROTOCOL
*Uci
;
51 BOOLEAN Iso639Language
;
55 Status
= gBS
->LocateHandleBuffer (
62 if (EFI_ERROR (Status
)) {
66 Iso639Language
= (BOOLEAN
) (ProtocolGuid
== &gEfiUnicodeCollationProtocolGuid
);
67 Language
= GetEfiGlobalVariable(VariableName
);
69 Status
= EFI_UNSUPPORTED
;
70 for (Index
= 0; Index
< NumHandles
; Index
++) {
72 // Open Unicode Collation Protocol
74 Status
= gBS
->OpenProtocol (
80 EFI_OPEN_PROTOCOL_GET_PROTOCOL
82 if (EFI_ERROR (Status
)) {
87 // Find the best matching matching language from the supported languages
88 // of Unicode Collation (2) protocol.
90 BestLanguage
= GetBestLanguage (
91 Uci
->SupportedLanguages
,
93 (Language
== NULL
) ? Language
: "",
97 if (BestLanguage
!= NULL
) {
98 FreePool (BestLanguage
);
99 mUnicodeCollationInterface
= Uci
;
100 Status
= EFI_SUCCESS
;
105 if (Language
!= NULL
) {
115 Initialize Unicode Collation support.
117 This function searches Initialized Unicode Collation support based on PCDs:
118 PcdUnicodeCollation2Support and PcdUnicodeCollationSupport.
119 It first tries to locate Unicode Collation 2 protocol and matches it with current
120 platform language code. If for any reason the first attempt fails, it then tries to
121 use Unicode Collation Protocol.
123 @param AgentHandle The handle used to open Unicode Collation (2) protocol.
125 @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.
126 @retval Others The Unicode Collation (2) protocol has not been located.
130 InitializeUnicodeCollationSupport (
131 IN EFI_HANDLE AgentHandle
137 Status
= EFI_UNSUPPORTED
;
140 // First try to use RFC 4646 Unicode Collation 2 Protocol.
142 if (FeaturePcdGet (PcdUnicodeCollation2Support
)) {
143 Status
= InitializeUnicodeCollationSupportWorker (
145 &gEfiUnicodeCollation2ProtocolGuid
,
147 (CONST CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
)
152 // If the attempt to use Unicode Collation 2 Protocol fails, then we fall back
153 // on the ISO 639-2 Unicode Collation Protocol.
155 if (FeaturePcdGet (PcdUnicodeCollationSupport
) && EFI_ERROR (Status
)) {
156 Status
= InitializeUnicodeCollationSupportWorker (
158 &gEfiUnicodeCollationProtocolGuid
,
160 (CONST CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultLang
)
169 Performs a case-insensitive comparison of two Null-terminated Unicode strings.
171 @param S1 A pointer to a Null-terminated Unicode string.
172 @param S2 A pointer to a Null-terminated Unicode string.
174 @retval 0 S1 is equivalent to S2.
175 @retval >0 S1 is lexically greater than S2.
176 @retval <0 S1 is lexically less than S2.
184 ASSERT (StrSize (S1
) != 0);
185 ASSERT (StrSize (S2
) != 0);
186 ASSERT (mUnicodeCollationInterface
!= NULL
);
188 return mUnicodeCollationInterface
->StriColl (
189 mUnicodeCollationInterface
,
199 @param Str The string which will be upper-cased.
206 IN OUT CHAR16
*String
209 ASSERT (StrSize (String
) != 0);
210 ASSERT (mUnicodeCollationInterface
!= NULL
);
212 mUnicodeCollationInterface
->StrUpr (mUnicodeCollationInterface
, String
);
219 @param Str The string which will be lower-cased.
226 IN OUT CHAR16
*String
229 ASSERT (StrSize (String
) != 0);
230 ASSERT (mUnicodeCollationInterface
!= NULL
);
232 mUnicodeCollationInterface
->StrLwr (mUnicodeCollationInterface
, String
);
237 Convert FAT string to unicode string.
239 @param FatSize The size of FAT string.
240 @param Fat The FAT string.
241 @param String The unicode string.
253 ASSERT (Fat
!= NULL
);
254 ASSERT (String
!= NULL
);
255 ASSERT (((UINTN
) String
& 0x01) == 0);
256 ASSERT (mUnicodeCollationInterface
!= NULL
);
258 mUnicodeCollationInterface
->FatToStr (mUnicodeCollationInterface
, FatSize
, Fat
, String
);
263 Convert unicode string to Fat string.
265 @param String The unicode string.
266 @param FatSize The size of the FAT string.
267 @param Fat The FAT string.
269 @retval TRUE Convert successfully.
270 @retval FALSE Convert error.
280 ASSERT (Fat
!= NULL
);
281 ASSERT (StrSize (String
) != 0);
282 ASSERT (mUnicodeCollationInterface
!= NULL
);
284 return mUnicodeCollationInterface
->StrToFat (
285 mUnicodeCollationInterface
,