2 Unicode Collation Library that hides the trival difference of Unicode Collation
3 and Unicode collation 2 Protocol.
5 Copyright (c) 2007, 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 STATIC EFI_UNICODE_COLLATION_PROTOCOL
*mUnicodeCollationInterface
= NULL
;
22 (* SEARCH_LANG_CODE
) (
23 IN CONST CHAR8
*Languages
,
24 IN CONST CHAR8
*MatchLangCode
27 struct _UNICODE_INTERFACE
{
29 CHAR8
*DefaultLangCode
;
30 SEARCH_LANG_CODE SearchLangCode
;
31 EFI_GUID
*UnicodeProtocolGuid
;
34 typedef struct _UNICODE_INTERFACE UNICODE_INTERFACE
;
38 SearchIso639LangCode (
39 IN CONST CHAR8
*Languages
,
40 IN CONST CHAR8
*MatchLangCode
43 CONST CHAR8
*LangCode
;
45 for (LangCode
= Languages
; *LangCode
!= '\0'; LangCode
+= 3) {
46 if (CompareMem (LangCode
, MatchLangCode
, 3) == 0) {
56 SearchRfc3066LangCode (
57 IN CONST CHAR8
*Languages
,
58 IN CONST CHAR8
*MatchLangCode
64 SubStr
= AsciiStrStr (Languages
, MatchLangCode
);
69 if (SubStr
!= Languages
&& *(SubStr
- 1) != ';') {
73 Terminal
= *(SubStr
+ AsciiStrLen (MatchLangCode
));
74 if (Terminal
!= '\0' && Terminal
!= ';') {
81 GLOBAL_REMOVE_IF_UNREFERENCED UNICODE_INTERFACE mIso639Lang
= {
83 (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultLang
),
85 &gEfiUnicodeCollationProtocolGuid
,
88 GLOBAL_REMOVE_IF_UNREFERENCED UNICODE_INTERFACE mRfc3066Lang
= {
90 (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
),
91 SearchRfc3066LangCode
,
92 &gEfiUnicodeCollation2ProtocolGuid
,
97 InitializeUnicodeCollationSupportWithConfig (
98 IN EFI_HANDLE AgentHandle
,
99 IN UNICODE_INTERFACE
*UnicodeInterface
109 EFI_UNICODE_COLLATION_PROTOCOL
*Uci
;
112 BufferSize
= sizeof (Buffer
);
113 Status
= gRT
->GetVariable (
114 UnicodeInterface
->VariableName
,
115 &gEfiGlobalVariableGuid
,
120 if (EFI_ERROR (Status
)) {
121 LangCode
= UnicodeInterface
->DefaultLangCode
;
124 Status
= gBS
->LocateHandleBuffer (
126 UnicodeInterface
->UnicodeProtocolGuid
,
131 if (EFI_ERROR (Status
)) {
135 for (Index
= 0; Index
< NoHandles
; Index
++) {
137 // Open Unicode Collation Protocol
139 Status
= gBS
->OpenProtocol (
141 UnicodeInterface
->UnicodeProtocolGuid
,
145 EFI_OPEN_PROTOCOL_GET_PROTOCOL
147 if (EFI_ERROR (Status
)) {
151 if (UnicodeInterface
->SearchLangCode (Uci
->SupportedLanguages
, LangCode
)) {
152 mUnicodeCollationInterface
= Uci
;
159 return (mUnicodeCollationInterface
!= NULL
)? EFI_SUCCESS
: EFI_NOT_FOUND
;
163 Initialize Unicode Collation support.
165 @param AgentHandle The handle used to open Unicode Collation (2) protocol.
167 @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.
168 @retval Others The Unicode Collation (2) protocol has not been located.
172 InitializeUnicodeCollationSupport (
173 IN EFI_HANDLE AgentHandle
179 Status
= EFI_UNSUPPORTED
;
180 if (FeaturePcdGet (PcdUnicodeCollation2Support
)) {
181 Status
= InitializeUnicodeCollationSupportWithConfig (AgentHandle
, &mRfc3066Lang
);
184 if (FeaturePcdGet (PcdUnicodeCollationSupport
) && EFI_ERROR (Status
)) {
185 Status
= InitializeUnicodeCollationSupportWithConfig (AgentHandle
, &mIso639Lang
);
192 Performs a case-insensitive comparison of two Null-terminated Unicode strings.
194 @param S1 A pointer to a Null-terminated Unicode string.
195 @param S2 A pointer to a Null-terminated Unicode string.
197 @retval 0 S1 is equivalent to S2.
198 @retval >0 S1 is lexically greater than S2.
199 @retval <0 S1 is lexically less than S2.
207 ASSERT (StrSize (S1
) != 0);
208 ASSERT (StrSize (S2
) != 0);
209 ASSERT (mUnicodeCollationInterface
!= NULL
);
211 return mUnicodeCollationInterface
->StriColl (
212 mUnicodeCollationInterface
,
222 @param Str The string which will be upper-cased.
229 IN OUT CHAR16
*String
232 ASSERT (StrSize (String
) != 0);
233 ASSERT (mUnicodeCollationInterface
!= NULL
);
235 mUnicodeCollationInterface
->StrUpr (mUnicodeCollationInterface
, String
);
242 @param Str The string which will be lower-cased.
249 IN OUT CHAR16
*String
252 ASSERT (StrSize (String
) != 0);
253 ASSERT (mUnicodeCollationInterface
!= NULL
);
255 mUnicodeCollationInterface
->StrLwr (mUnicodeCollationInterface
, String
);
260 Convert FAT string to unicode string.
262 @param FatSize The size of FAT string.
263 @param Fat The FAT string.
264 @param String The unicode string.
276 ASSERT (Fat
!= NULL
);
277 ASSERT (String
!= NULL
);
278 ASSERT (((UINTN
) String
& 0x01) == 0);
279 ASSERT (mUnicodeCollationInterface
!= NULL
);
281 mUnicodeCollationInterface
->FatToStr (mUnicodeCollationInterface
, FatSize
, Fat
, String
);
286 Convert unicode string to Fat string.
288 @param String The unicode string.
289 @param FatSize The size of the FAT string.
290 @param Fat The FAT string.
292 @retval TRUE Convert successfully.
293 @retval FALSE Convert error.
303 ASSERT (Fat
!= NULL
);
304 ASSERT (StrSize (String
) != 0);
305 ASSERT (mUnicodeCollationInterface
!= NULL
);
307 return mUnicodeCollationInterface
->StrToFat (
308 mUnicodeCollationInterface
,