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)
24 #include "UnicodeCollationEng.h"
26 CHAR8 mEngUpperMap
[0x100];
27 CHAR8 mEngLowerMap
[0x100];
28 CHAR8 mEngInfoMap
[0x100];
30 CHAR8 mOtherChars
[] = {
62 EFI_HANDLE mHandle
= NULL
;
64 EFI_UNICODE_COLLATION_PROTOCOL UnicodeEng
= {
78 InitializeUnicodeCollationEng (
79 IN EFI_HANDLE ImageHandle
,
80 IN EFI_SYSTEM_TABLE
*SystemTable
86 Initializes the Unicode Collation Driver
105 // Initialize mapping tables for the supported languages
107 for (Index
= 0; Index
< 0x100; Index
++) {
108 mEngUpperMap
[Index
] = (CHAR8
) Index
;
109 mEngLowerMap
[Index
] = (CHAR8
) Index
;
110 mEngInfoMap
[Index
] = 0;
112 if ((Index
>= 'a' && Index
<= 'z') || (Index
>= 0xe0 && Index
<= 0xf6) || (Index
>= 0xf8 && Index
<= 0xfe)) {
114 Index2
= Index
- 0x20;
115 mEngUpperMap
[Index
] = (CHAR8
) Index2
;
116 mEngLowerMap
[Index2
] = (CHAR8
) Index
;
118 mEngInfoMap
[Index
] |= CHAR_FAT_VALID
;
119 mEngInfoMap
[Index2
] |= CHAR_FAT_VALID
;
123 for (Index
= 0; mOtherChars
[Index
]; Index
++) {
124 Index2
= mOtherChars
[Index
];
125 mEngInfoMap
[Index2
] |= CHAR_FAT_VALID
;
128 // Create a handle for the device
130 return gBS
->InstallProtocolInterface (
132 &gEfiUnicodeCollationProtocolGuid
,
133 EFI_NATIVE_INTERFACE
,
141 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
149 Performs a case-insensitive comparison of two Null-terminated Unicode strings.
162 if (ToUpper (*s1
) != ToUpper (*s2
)) {
170 return ToUpper (*s1
) - ToUpper (*s2
);
176 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
183 Converts all the Unicode characters in a Null-terminated Unicode string
184 to lower case Unicode characters.
188 This - A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance.
189 Str1 - A pointer to a Null-terminated Unicode string.
190 Str2 - A pointer to a Null-terminated Unicode string.
194 0 - s1 is equivalent to s2.
195 > 0 - s1 is lexically greater than s2.
196 < 0 - s1 is lexically less than s2.
201 *Str
= ToLower (*Str
);
209 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
216 Converts all the Unicode characters in a Null-terminated
217 Unicode string to upper case Unicode characters.
229 *Str
= ToUpper (*Str
);
237 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
245 Performs a case-insensitive comparison between a Null-terminated
246 Unicode pattern string and a Null-terminated Unicode string.
248 The pattern string can use the '?' wildcard to match any character,
249 and the '*' wildcard to match any sub-string.
253 This - A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance.
254 String - A pointer to a Null-terminated Unicode string.
255 Pattern - A pointer to a Null-terminated Unicode pattern string.
259 TRUE - Pattern was found in String.
260 FALSE - Pattern was not found in String.
275 // End of pattern. If end of string, TRUE match
285 // Match zero or more chars
288 if (EngMetaiMatch (This
, String
, Pattern
)) {
295 return EngMetaiMatch (This
, String
, Pattern
);
299 // Match any one char
329 // if range of chars, get high range
332 if (CharP
== 0 || CharP
== ']') {
339 if (ToUpper (CharC
) >= ToUpper (Index3
) && ToUpper (CharC
) <= ToUpper (CharP
)) {
341 // if in range, it's a match
348 if (ToUpper (CharC
) == ToUpper (CharP
)) {
358 // skip to end of match char set
360 while (CharP
&& CharP
!= ']') {
370 if (ToUpper (CharC
) != ToUpper (CharP
)) {
383 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
392 Converts an 8.3 FAT file name using an OEM character set
393 to a Null-terminated Unicode string.
395 BUGBUG: Function has to expand DBCS FAT chars, currently not.
408 // No DBCS issues, just expand and add null terminate to end of string
410 while (*Fat
&& FatSize
) {
423 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
432 Converts a Null-terminated Unicode string to legal characters
433 in a FAT filename using an OEM character set.
435 Functions has to crunch string to a fat string. Replacing
436 any chars that can't be represented in the fat name.
449 BOOLEAN SpecialCharExist
;
451 SpecialCharExist
= FALSE
;
452 while (*String
&& FatSize
) {
454 // Skip '.' or ' ' when making a fat name
456 if (*String
!= '.' && *String
!= ' ') {
458 // If this is a valid fat char, move it.
459 // Otherwise, move a '_' and flag the fact that the name needs an Lfn
461 if (*String
< 0x100 && (mEngInfoMap
[*String
] & CHAR_FAT_VALID
)) {
462 *Fat
= mEngUpperMap
[*String
];
465 SpecialCharExist
= TRUE
;
475 // Do not terminate that fat string
477 return SpecialCharExist
;