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 if (Language
== NULL
) {
91 BestLanguage
= GetBestLanguage (
92 Uci
->SupportedLanguages
,
98 BestLanguage
= GetBestLanguage (
99 Uci
->SupportedLanguages
,
107 if (BestLanguage
!= NULL
) {
108 FreePool (BestLanguage
);
109 mUnicodeCollationInterface
= Uci
;
110 Status
= EFI_SUCCESS
;
115 if (Language
!= NULL
) {
125 Initialize Unicode Collation support.
127 This function searches Initialized Unicode Collation support based on PCDs:
128 PcdUnicodeCollation2Support and PcdUnicodeCollationSupport.
129 It first tries to locate Unicode Collation 2 protocol and matches it with current
130 platform language code. If for any reason the first attempt fails, it then tries to
131 use Unicode Collation Protocol.
133 @param AgentHandle The handle used to open Unicode Collation (2) protocol.
135 @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.
136 @retval Others The Unicode Collation (2) protocol has not been located.
140 InitializeUnicodeCollationSupport (
141 IN EFI_HANDLE AgentHandle
147 Status
= EFI_UNSUPPORTED
;
150 // First try to use RFC 4646 Unicode Collation 2 Protocol.
152 if (FeaturePcdGet (PcdUnicodeCollation2Support
)) {
153 Status
= InitializeUnicodeCollationSupportWorker (
155 &gEfiUnicodeCollation2ProtocolGuid
,
157 (CONST CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
)
162 // If the attempt to use Unicode Collation 2 Protocol fails, then we fall back
163 // on the ISO 639-2 Unicode Collation Protocol.
165 if (FeaturePcdGet (PcdUnicodeCollationSupport
) && EFI_ERROR (Status
)) {
166 Status
= InitializeUnicodeCollationSupportWorker (
168 &gEfiUnicodeCollationProtocolGuid
,
170 (CONST CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultLang
)
179 Performs a case-insensitive comparison of two Null-terminated Unicode strings.
181 @param S1 A pointer to a Null-terminated Unicode string.
182 @param S2 A pointer to a Null-terminated Unicode string.
184 @retval 0 S1 is equivalent to S2.
185 @retval >0 S1 is lexically greater than S2.
186 @retval <0 S1 is lexically less than S2.
194 ASSERT (StrSize (S1
) != 0);
195 ASSERT (StrSize (S2
) != 0);
196 ASSERT (mUnicodeCollationInterface
!= NULL
);
198 return mUnicodeCollationInterface
->StriColl (
199 mUnicodeCollationInterface
,
209 @param Str The string which will be upper-cased.
216 IN OUT CHAR16
*String
219 ASSERT (StrSize (String
) != 0);
220 ASSERT (mUnicodeCollationInterface
!= NULL
);
222 mUnicodeCollationInterface
->StrUpr (mUnicodeCollationInterface
, String
);
229 @param Str The string which will be lower-cased.
236 IN OUT CHAR16
*String
239 ASSERT (StrSize (String
) != 0);
240 ASSERT (mUnicodeCollationInterface
!= NULL
);
242 mUnicodeCollationInterface
->StrLwr (mUnicodeCollationInterface
, String
);
247 Convert FAT string to unicode string.
249 @param FatSize The size of FAT string.
250 @param Fat The FAT string.
251 @param String The unicode string.
263 ASSERT (Fat
!= NULL
);
264 ASSERT (String
!= NULL
);
265 ASSERT (((UINTN
) String
& 0x01) == 0);
266 ASSERT (mUnicodeCollationInterface
!= NULL
);
268 mUnicodeCollationInterface
->FatToStr (mUnicodeCollationInterface
, FatSize
, Fat
, String
);
273 Convert unicode string to Fat string.
275 @param String The unicode string.
276 @param FatSize The size of the FAT string.
277 @param Fat The FAT string.
279 @retval TRUE Convert successfully.
280 @retval FALSE Convert error.
290 ASSERT (Fat
!= NULL
);
291 ASSERT (StrSize (String
) != 0);
292 ASSERT (mUnicodeCollationInterface
!= NULL
);
294 return mUnicodeCollationInterface
->StrToFat (
295 mUnicodeCollationInterface
,