3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Unicode Collation Protocol (English)
25 #include "UnicodeCollationEng.h"
27 CHAR8 mEngUpperMap
[0x100];
28 CHAR8 mEngLowerMap
[0x100];
29 CHAR8 mEngInfoMap
[0x100];
31 CHAR8 mOtherChars
[] = {
63 STATIC EFI_HANDLE mHandle
= NULL
;
66 // EFI Unicode Collation Protocol supporting ISO 639-2 language code
68 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_COLLATION_PROTOCOL UnicodeEng
= {
79 // EFI Unicode Collation2 Protocol supporting RFC 3066 language code
81 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_COLLATION_PROTOCOL Unicode2Eng
= {
92 // Driver entry point.
96 InitializeUnicodeCollationEng (
97 IN EFI_HANDLE ImageHandle
,
98 IN EFI_SYSTEM_TABLE
*SystemTable
104 Initializes the Unicode Collation Driver
124 // Initialize mapping tables for the supported languages
126 for (Index
= 0; Index
< 0x100; Index
++) {
127 mEngUpperMap
[Index
] = (CHAR8
) Index
;
128 mEngLowerMap
[Index
] = (CHAR8
) Index
;
129 mEngInfoMap
[Index
] = 0;
131 if ((Index
>= 'a' && Index
<= 'z') || (Index
>= 0xe0 && Index
<= 0xf6) || (Index
>= 0xf8 && Index
<= 0xfe)) {
133 Index2
= Index
- 0x20;
134 mEngUpperMap
[Index
] = (CHAR8
) Index2
;
135 mEngLowerMap
[Index2
] = (CHAR8
) Index
;
137 mEngInfoMap
[Index
] |= CHAR_FAT_VALID
;
138 mEngInfoMap
[Index2
] |= CHAR_FAT_VALID
;
142 for (Index
= 0; mOtherChars
[Index
]; Index
++) {
143 Index2
= mOtherChars
[Index
];
144 mEngInfoMap
[Index2
] |= CHAR_FAT_VALID
;
147 if (FeaturePcdGet (PcdUnicodeCollation2Support
)) {
148 if (FeaturePcdGet (PcdUnicodeCollationSupport
)) {
149 Status
= gBS
->InstallMultipleProtocolInterfaces (
151 &gEfiUnicodeCollationProtocolGuid
,
153 &gEfiUnicodeCollation2ProtocolGuid
,
157 ASSERT_EFI_ERROR (Status
);
159 Status
= gBS
->InstallMultipleProtocolInterfaces (
161 &gEfiUnicodeCollation2ProtocolGuid
,
165 ASSERT_EFI_ERROR (Status
);
168 if (FeaturePcdGet (PcdUnicodeCollationSupport
)) {
169 Status
= gBS
->InstallMultipleProtocolInterfaces (
171 &gEfiUnicodeCollationProtocolGuid
,
175 ASSERT_EFI_ERROR (Status
);
178 // This module must support to produce at least one of Unicode Collation Protocol
179 // and Unicode Collation 2 Protocol.
182 Status
= EFI_UNSUPPORTED
;
192 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
200 Performs a case-insensitive comparison of two Null-terminated Unicode strings.
213 if (ToUpper (*s1
) != ToUpper (*s2
)) {
221 return ToUpper (*s1
) - ToUpper (*s2
);
227 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
234 Converts all the Unicode characters in a Null-terminated Unicode string
235 to lower case Unicode characters.
239 This - A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance.
240 Str1 - A pointer to a Null-terminated Unicode string.
241 Str2 - A pointer to a Null-terminated Unicode string.
245 0 - s1 is equivalent to s2.
246 > 0 - s1 is lexically greater than s2.
247 < 0 - s1 is lexically less than s2.
252 *Str
= ToLower (*Str
);
260 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
267 Converts all the Unicode characters in a Null-terminated
268 Unicode string to upper case Unicode characters.
280 *Str
= ToUpper (*Str
);
288 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
296 Performs a case-insensitive comparison between a Null-terminated
297 Unicode pattern string and a Null-terminated Unicode string.
299 The pattern string can use the '?' wildcard to match any character,
300 and the '*' wildcard to match any sub-string.
304 This - A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance.
305 String - A pointer to a Null-terminated Unicode string.
306 Pattern - A pointer to a Null-terminated Unicode pattern string.
310 TRUE - Pattern was found in String.
311 FALSE - Pattern was not found in String.
326 // End of pattern. If end of string, TRUE match
336 // Match zero or more chars
339 if (EngMetaiMatch (This
, String
, Pattern
)) {
346 return EngMetaiMatch (This
, String
, Pattern
);
350 // Match any one char
380 // if range of chars, get high range
383 if (CharP
== 0 || CharP
== ']') {
390 if (ToUpper (CharC
) >= ToUpper (Index3
) && ToUpper (CharC
) <= ToUpper (CharP
)) {
392 // if in range, it's a match
399 if (ToUpper (CharC
) == ToUpper (CharP
)) {
409 // skip to end of match char set
411 while (CharP
&& CharP
!= ']') {
421 if (ToUpper (CharC
) != ToUpper (CharP
)) {
434 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
443 Converts an 8.3 FAT file name using an OEM character set
444 to a Null-terminated Unicode string.
446 BUGBUG: Function has to expand DBCS FAT chars, currently not.
459 // No DBCS issues, just expand and add null terminate to end of string
461 while (*Fat
&& FatSize
) {
474 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
483 Converts a Null-terminated Unicode string to legal characters
484 in a FAT filename using an OEM character set.
486 Functions has to crunch string to a fat string. Replacing
487 any chars that can't be represented in the fat name.
500 BOOLEAN SpecialCharExist
;
502 SpecialCharExist
= FALSE
;
503 while (*String
&& FatSize
) {
505 // Skip '.' or ' ' when making a fat name
507 if (*String
!= '.' && *String
!= ' ') {
509 // If this is a valid fat char, move it.
510 // Otherwise, move a '_' and flag the fact that the name needs an Lfn
512 if (*String
< 0x100 && (mEngInfoMap
[*String
] & CHAR_FAT_VALID
)) {
513 *Fat
= mEngUpperMap
[*String
];
516 SpecialCharExist
= TRUE
;
526 // Do not terminate that fat string
528 return SpecialCharExist
;