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 EFI_HANDLE mHandle
= NULL
;
65 EFI_UNICODE_COLLATION_PROTOCOL UnicodeEng
= {
79 InitializeUnicodeCollationEng (
80 IN EFI_HANDLE ImageHandle
,
81 IN EFI_SYSTEM_TABLE
*SystemTable
87 Initializes the Unicode Collation Driver
106 // Initialize mapping tables for the supported languages
108 for (Index
= 0; Index
< 0x100; Index
++) {
109 mEngUpperMap
[Index
] = (CHAR8
) Index
;
110 mEngLowerMap
[Index
] = (CHAR8
) Index
;
111 mEngInfoMap
[Index
] = 0;
113 if ((Index
>= 'a' && Index
<= 'z') || (Index
>= 0xe0 && Index
<= 0xf6) || (Index
>= 0xf8 && Index
<= 0xfe)) {
115 Index2
= Index
- 0x20;
116 mEngUpperMap
[Index
] = (CHAR8
) Index2
;
117 mEngLowerMap
[Index2
] = (CHAR8
) Index
;
119 mEngInfoMap
[Index
] |= CHAR_FAT_VALID
;
120 mEngInfoMap
[Index2
] |= CHAR_FAT_VALID
;
124 for (Index
= 0; mOtherChars
[Index
]; Index
++) {
125 Index2
= mOtherChars
[Index
];
126 mEngInfoMap
[Index2
] |= CHAR_FAT_VALID
;
129 // Create a handle for the device
131 return gBS
->InstallProtocolInterface (
133 &gEfiUnicodeCollationProtocolGuid
,
134 EFI_NATIVE_INTERFACE
,
142 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
150 Performs a case-insensitive comparison of two Null-terminated Unicode strings.
163 if (ToUpper (*s1
) != ToUpper (*s2
)) {
171 return ToUpper (*s1
) - ToUpper (*s2
);
177 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
184 Converts all the Unicode characters in a Null-terminated Unicode string
185 to lower case Unicode characters.
189 This - A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance.
190 Str1 - A pointer to a Null-terminated Unicode string.
191 Str2 - A pointer to a Null-terminated Unicode string.
195 0 - s1 is equivalent to s2.
196 > 0 - s1 is lexically greater than s2.
197 < 0 - s1 is lexically less than s2.
202 *Str
= ToLower (*Str
);
210 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
217 Converts all the Unicode characters in a Null-terminated
218 Unicode string to upper case Unicode characters.
230 *Str
= ToUpper (*Str
);
238 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
246 Performs a case-insensitive comparison between a Null-terminated
247 Unicode pattern string and a Null-terminated Unicode string.
249 The pattern string can use the '?' wildcard to match any character,
250 and the '*' wildcard to match any sub-string.
254 This - A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance.
255 String - A pointer to a Null-terminated Unicode string.
256 Pattern - A pointer to a Null-terminated Unicode pattern string.
260 TRUE - Pattern was found in String.
261 FALSE - Pattern was not found in String.
276 // End of pattern. If end of string, TRUE match
286 // Match zero or more chars
289 if (EngMetaiMatch (This
, String
, Pattern
)) {
296 return EngMetaiMatch (This
, String
, Pattern
);
300 // Match any one char
330 // if range of chars, get high range
333 if (CharP
== 0 || CharP
== ']') {
340 if (ToUpper (CharC
) >= ToUpper (Index3
) && ToUpper (CharC
) <= ToUpper (CharP
)) {
342 // if in range, it's a match
349 if (ToUpper (CharC
) == ToUpper (CharP
)) {
359 // skip to end of match char set
361 while (CharP
&& CharP
!= ']') {
371 if (ToUpper (CharC
) != ToUpper (CharP
)) {
384 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
393 Converts an 8.3 FAT file name using an OEM character set
394 to a Null-terminated Unicode string.
396 BUGBUG: Function has to expand DBCS FAT chars, currently not.
409 // No DBCS issues, just expand and add null terminate to end of string
411 while (*Fat
&& FatSize
) {
424 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
433 Converts a Null-terminated Unicode string to legal characters
434 in a FAT filename using an OEM character set.
436 Functions has to crunch string to a fat string. Replacing
437 any chars that can't be represented in the fat name.
450 BOOLEAN SpecialCharExist
;
452 SpecialCharExist
= FALSE
;
453 while (*String
&& FatSize
) {
455 // Skip '.' or ' ' when making a fat name
457 if (*String
!= '.' && *String
!= ' ') {
459 // If this is a valid fat char, move it.
460 // Otherwise, move a '_' and flag the fact that the name needs an Lfn
462 if (*String
< 0x100 && (mEngInfoMap
[*String
] & CHAR_FAT_VALID
)) {
463 *Fat
= mEngUpperMap
[*String
];
466 SpecialCharExist
= TRUE
;
476 // Do not terminate that fat string
478 return SpecialCharExist
;