2 Unicode Collation Support component that hides the trivial difference of Unicode Collation
3 and Unicode collation 2 Protocol.
5 Copyright (c) 2007 - 2010, Intel Corporation<BR>
6 All rights reserved. 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
47 EFI_UNICODE_COLLATION_PROTOCOL
*Uci
;
48 BOOLEAN Iso639Language
;
52 Status
= gBS
->LocateHandleBuffer (
59 if (EFI_ERROR (Status
)) {
63 Iso639Language
= (BOOLEAN
) (ProtocolGuid
== &gEfiUnicodeCollationProtocolGuid
);
64 Language
= GetEfiGlobalVariable(VariableName
);
66 Status
= EFI_UNSUPPORTED
;
67 for (Index
= 0; Index
< NumHandles
; Index
++) {
69 // Open Unicode Collation Protocol
71 Status
= gBS
->OpenProtocol (
77 EFI_OPEN_PROTOCOL_GET_PROTOCOL
79 if (EFI_ERROR (Status
)) {
84 // Find the best matching matching language from the supported languages
85 // of Unicode Collation (2) protocol.
87 BestLanguage
= GetBestLanguage (
88 Uci
->SupportedLanguages
,
90 (Language
== NULL
) ? "" : Language
,
94 if (BestLanguage
!= NULL
) {
95 FreePool (BestLanguage
);
96 mUnicodeCollationInterface
= Uci
;
102 if (Language
!= NULL
) {
112 Initialize Unicode Collation support.
114 It tries to locate Unicode Collation 2 protocol and matches it with current
115 platform language code. If for any reason the first attempt fails, it then tries to
116 use Unicode Collation Protocol.
118 @param AgentHandle The handle used to open Unicode Collation (2) protocol.
120 @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.
121 @retval Others The Unicode Collation (2) protocol has not been located.
125 InitializeUnicodeCollationSupport (
126 IN EFI_HANDLE AgentHandle
132 Status
= EFI_UNSUPPORTED
;
135 // First try to use RFC 4646 Unicode Collation 2 Protocol.
137 Status
= InitializeUnicodeCollationSupportWorker (
139 &gEfiUnicodeCollation2ProtocolGuid
,
141 (CONST CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
)
144 // If the attempt to use Unicode Collation 2 Protocol fails, then we fall back
145 // on the ISO 639-2 Unicode Collation Protocol.
147 if (EFI_ERROR (Status
)) {
148 Status
= InitializeUnicodeCollationSupportWorker (
150 &gEfiUnicodeCollationProtocolGuid
,
152 (CONST CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultLang
)
161 Performs a case-insensitive comparison of two Null-terminated Unicode strings.
163 @param S1 A pointer to a Null-terminated Unicode string.
164 @param S2 A pointer to a Null-terminated Unicode string.
166 @retval 0 S1 is equivalent to S2.
167 @retval >0 S1 is lexically greater than S2.
168 @retval <0 S1 is lexically less than S2.
176 ASSERT (StrSize (S1
) != 0);
177 ASSERT (StrSize (S2
) != 0);
178 ASSERT (mUnicodeCollationInterface
!= NULL
);
180 return mUnicodeCollationInterface
->StriColl (
181 mUnicodeCollationInterface
,
191 @param Str 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 Str The string which will be lower-cased.
218 IN OUT CHAR16
*String
221 ASSERT (StrSize (String
) != 0);
222 ASSERT (mUnicodeCollationInterface
!= NULL
);
224 mUnicodeCollationInterface
->StrLwr (mUnicodeCollationInterface
, String
);
229 Convert FAT string to unicode string.
231 @param FatSize The size of FAT string.
232 @param Fat The FAT string.
233 @param String The unicode string.
245 ASSERT (Fat
!= NULL
);
246 ASSERT (String
!= NULL
);
247 ASSERT (((UINTN
) String
& 0x01) == 0);
248 ASSERT (mUnicodeCollationInterface
!= NULL
);
250 mUnicodeCollationInterface
->FatToStr (mUnicodeCollationInterface
, FatSize
, Fat
, String
);
255 Convert unicode string to Fat string.
257 @param String The unicode string.
258 @param FatSize The size of the FAT string.
259 @param Fat The FAT string.
261 @retval TRUE Convert successfully.
262 @retval FALSE Convert error.
272 ASSERT (Fat
!= NULL
);
273 ASSERT (StrSize (String
) != 0);
274 ASSERT (mUnicodeCollationInterface
!= NULL
);
276 return mUnicodeCollationInterface
->StrToFat (
277 mUnicodeCollationInterface
,