2 Unicode Collation Protocol (English)
4 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "UnicodeCollationEng.h"
18 CHAR8 mEngUpperMap
[0x100];
19 CHAR8 mEngLowerMap
[0x100];
20 CHAR8 mEngInfoMap
[0x100];
22 CHAR8 mOtherChars
[] = {
54 STATIC EFI_HANDLE mHandle
= NULL
;
57 // EFI Unicode Collation Protocol supporting ISO 639-2 language code
59 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_COLLATION_PROTOCOL UnicodeEng
= {
70 // EFI Unicode Collation2 Protocol supporting RFC 3066 language code
72 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_COLLATION_PROTOCOL Unicode2Eng
= {
83 // Driver entry point.
87 InitializeUnicodeCollationEng (
88 IN EFI_HANDLE ImageHandle
,
89 IN EFI_SYSTEM_TABLE
*SystemTable
95 Initializes the Unicode Collation Driver
115 // Initialize mapping tables for the supported languages
117 for (Index
= 0; Index
< 0x100; Index
++) {
118 mEngUpperMap
[Index
] = (CHAR8
) Index
;
119 mEngLowerMap
[Index
] = (CHAR8
) Index
;
120 mEngInfoMap
[Index
] = 0;
122 if ((Index
>= 'a' && Index
<= 'z') || (Index
>= 0xe0 && Index
<= 0xf6) || (Index
>= 0xf8 && Index
<= 0xfe)) {
124 Index2
= Index
- 0x20;
125 mEngUpperMap
[Index
] = (CHAR8
) Index2
;
126 mEngLowerMap
[Index2
] = (CHAR8
) Index
;
128 mEngInfoMap
[Index
] |= CHAR_FAT_VALID
;
129 mEngInfoMap
[Index2
] |= CHAR_FAT_VALID
;
133 for (Index
= 0; mOtherChars
[Index
]; Index
++) {
134 Index2
= mOtherChars
[Index
];
135 mEngInfoMap
[Index2
] |= CHAR_FAT_VALID
;
138 if (FeaturePcdGet (PcdUnicodeCollation2Support
)) {
139 if (FeaturePcdGet (PcdUnicodeCollationSupport
)) {
140 Status
= gBS
->InstallMultipleProtocolInterfaces (
142 &gEfiUnicodeCollationProtocolGuid
,
144 &gEfiUnicodeCollation2ProtocolGuid
,
148 ASSERT_EFI_ERROR (Status
);
150 Status
= gBS
->InstallMultipleProtocolInterfaces (
152 &gEfiUnicodeCollation2ProtocolGuid
,
156 ASSERT_EFI_ERROR (Status
);
159 if (FeaturePcdGet (PcdUnicodeCollationSupport
)) {
160 Status
= gBS
->InstallMultipleProtocolInterfaces (
162 &gEfiUnicodeCollationProtocolGuid
,
166 ASSERT_EFI_ERROR (Status
);
169 // This module must support to produce at least one of Unicode Collation Protocol
170 // and Unicode Collation 2 Protocol.
173 Status
= EFI_UNSUPPORTED
;
183 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
191 Performs a case-insensitive comparison of two Null-terminated Unicode strings.
204 if (ToUpper (*s1
) != ToUpper (*s2
)) {
212 return ToUpper (*s1
) - ToUpper (*s2
);
218 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
225 Converts all the Unicode characters in a Null-terminated Unicode string
226 to lower case Unicode characters.
230 This - A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance.
231 Str1 - A pointer to a Null-terminated Unicode string.
232 Str2 - A pointer to a Null-terminated Unicode string.
236 0 - s1 is equivalent to s2.
237 > 0 - s1 is lexically greater than s2.
238 < 0 - s1 is lexically less than s2.
243 *Str
= ToLower (*Str
);
251 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
258 Converts all the Unicode characters in a Null-terminated
259 Unicode string to upper case Unicode characters.
271 *Str
= ToUpper (*Str
);
279 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
287 Performs a case-insensitive comparison between a Null-terminated
288 Unicode pattern string and a Null-terminated Unicode string.
290 The pattern string can use the '?' wildcard to match any character,
291 and the '*' wildcard to match any sub-string.
295 This - A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance.
296 String - A pointer to a Null-terminated Unicode string.
297 Pattern - A pointer to a Null-terminated Unicode pattern string.
301 TRUE - Pattern was found in String.
302 FALSE - Pattern was not found in String.
317 // End of pattern. If end of string, TRUE match
327 // Match zero or more chars
330 if (EngMetaiMatch (This
, String
, Pattern
)) {
337 return EngMetaiMatch (This
, String
, Pattern
);
341 // Match any one char
371 // if range of chars, get high range
374 if (CharP
== 0 || CharP
== ']') {
381 if (ToUpper (CharC
) >= ToUpper (Index3
) && ToUpper (CharC
) <= ToUpper (CharP
)) {
383 // if in range, it's a match
390 if (ToUpper (CharC
) == ToUpper (CharP
)) {
400 // skip to end of match char set
402 while (CharP
&& CharP
!= ']') {
412 if (ToUpper (CharC
) != ToUpper (CharP
)) {
425 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
434 Converts an 8.3 FAT file name using an OEM character set
435 to a Null-terminated Unicode string.
437 BUGBUG: Function has to expand DBCS FAT chars, currently not.
450 // No DBCS issues, just expand and add null terminate to end of string
452 while (*Fat
&& FatSize
) {
465 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
474 Converts a Null-terminated Unicode string to legal characters
475 in a FAT filename using an OEM character set.
477 Functions has to crunch string to a fat string. Replacing
478 any chars that can't be represented in the fat name.
491 BOOLEAN SpecialCharExist
;
493 SpecialCharExist
= FALSE
;
494 while (*String
&& FatSize
) {
496 // Skip '.' or ' ' when making a fat name
498 if (*String
!= '.' && *String
!= ' ') {
500 // If this is a valid fat char, move it.
501 // Otherwise, move a '_' and flag the fact that the name needs an Lfn
503 if (*String
< 0x100 && (mEngInfoMap
[*String
] & CHAR_FAT_VALID
)) {
504 *Fat
= mEngUpperMap
[*String
];
507 SpecialCharExist
= TRUE
;
517 // Do not terminate that fat string
519 return SpecialCharExist
;