2 Driver to implement English version of Unicode Collation Protocol.
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
[MAP_TABLE_SIZE
];
19 CHAR8 mEngLowerMap
[MAP_TABLE_SIZE
];
20 CHAR8 mEngInfoMap
[MAP_TABLE_SIZE
];
22 CHAR8 mOtherChars
[] = {
54 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 4646 language code
72 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_COLLATION_PROTOCOL Unicode2Eng
= {
83 The user Entry Point for English module.
85 This function initializes unicode character mapping and then installs Unicode
86 Collation & Unicode Collation 2 Protocols based on the feature flags.
88 @param ImageHandle The firmware allocated handle for the EFI image.
89 @param SystemTable A pointer to the EFI System Table.
91 @retval EFI_SUCCESS The entry point is executed successfully.
92 @retval other Some error occurs when executing this entry point.
97 InitializeUnicodeCollationEng (
98 IN EFI_HANDLE ImageHandle
,
99 IN EFI_SYSTEM_TABLE
*SystemTable
107 // Initialize mapping tables for the supported languages
109 for (Index
= 0; Index
< MAP_TABLE_SIZE
; Index
++) {
110 mEngUpperMap
[Index
] = (CHAR8
) Index
;
111 mEngLowerMap
[Index
] = (CHAR8
) Index
;
112 mEngInfoMap
[Index
] = 0;
114 if ((Index
>= 'a' && Index
<= 'z') || (Index
>= 0xe0 && Index
<= 0xf6) || (Index
>= 0xf8 && Index
<= 0xfe)) {
116 Index2
= Index
- 0x20;
117 mEngUpperMap
[Index
] = (CHAR8
) Index2
;
118 mEngLowerMap
[Index2
] = (CHAR8
) Index
;
120 mEngInfoMap
[Index
] |= CHAR_FAT_VALID
;
121 mEngInfoMap
[Index2
] |= CHAR_FAT_VALID
;
125 for (Index
= 0; mOtherChars
[Index
] != 0; Index
++) {
126 Index2
= mOtherChars
[Index
];
127 mEngInfoMap
[Index2
] |= CHAR_FAT_VALID
;
130 if (FeaturePcdGet (PcdUnicodeCollation2Support
)) {
131 if (FeaturePcdGet (PcdUnicodeCollationSupport
)) {
132 Status
= gBS
->InstallMultipleProtocolInterfaces (
134 &gEfiUnicodeCollationProtocolGuid
,
136 &gEfiUnicodeCollation2ProtocolGuid
,
140 ASSERT_EFI_ERROR (Status
);
142 Status
= gBS
->InstallMultipleProtocolInterfaces (
144 &gEfiUnicodeCollation2ProtocolGuid
,
148 ASSERT_EFI_ERROR (Status
);
151 if (FeaturePcdGet (PcdUnicodeCollationSupport
)) {
152 Status
= gBS
->InstallMultipleProtocolInterfaces (
154 &gEfiUnicodeCollationProtocolGuid
,
158 ASSERT_EFI_ERROR (Status
);
161 // This module must support to produce at least one of Unicode Collation Protocol
162 // and Unicode Collation 2 Protocol.
165 Status
= EFI_UNSUPPORTED
;
174 Performs a case-insensitive comparison of two Null-terminated Unicode
177 @param This Protocol instance pointer.
178 @param Str1 A pointer to a Null-terminated Unicode string.
179 @param Str2 A pointer to a Null-terminated Unicode string.
181 @retval 0 Str1 is equivalent to Str2
182 @retval > 0 Str1 is lexically greater than Str2
183 @retval < 0 Str1 is lexically less than Str2
189 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
195 if (TO_UPPER (*Str1
) != TO_UPPER (*Str2
)) {
203 return TO_UPPER (*Str1
) - TO_UPPER (*Str2
);
208 Converts all the Unicode characters in a Null-terminated Unicode string to
209 lower case Unicode characters.
211 @param This Protocol instance pointer.
212 @param Str A pointer to a Null-terminated Unicode string.
218 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
223 *Str
= TO_LOWER (*Str
);
230 Converts all the Unicode characters in a Null-terminated Unicode string to upper
231 case Unicode characters.
233 @param This Protocol instance pointer.
234 @param Str A pointer to a Null-terminated Unicode string.
240 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
245 *Str
= TO_UPPER (*Str
);
251 Performs a case-insensitive comparison of a Null-terminated Unicode
252 pattern string and a Null-terminated Unicode string.
254 @param This Protocol instance pointer.
255 @param String A pointer to a Null-terminated Unicode string.
256 @param Pattern A pointer to a Null-terminated Unicode pattern string.
258 @retval TRUE Pattern was found in String.
259 @retval FALSE Pattern was not found in String.
265 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
281 // End of pattern. If end of string, TRUE match
291 // Match zero or more chars
293 while (*String
!= 0) {
294 if (EngMetaiMatch (This
, String
, Pattern
)) {
301 return EngMetaiMatch (This
, String
, Pattern
);
305 // Match any one char
335 // if range of chars, get high range
338 if (CharP
== 0 || CharP
== ']') {
345 if (TO_UPPER (CharC
) >= TO_UPPER (Index3
) && TO_UPPER (CharC
) <= TO_UPPER (CharP
)) {
347 // if in range, it's a match
354 if (TO_UPPER (CharC
) == TO_UPPER (CharP
)) {
364 // skip to end of match char set
366 while ((CharP
!= 0) && (CharP
!= ']')) {
376 if (TO_UPPER (CharC
) != TO_UPPER (CharP
)) {
388 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated
391 @param This Protocol instance pointer.
392 @param FatSize The size of the string Fat in bytes.
393 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
394 name using an OEM character set.
395 @param String A pointer to a Null-terminated Unicode string. The string must
396 be preallocated to hold FatSize Unicode characters.
402 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
409 // No DBCS issues, just expand and add null terminate to end of string
411 while ((*Fat
!= 0) && (FatSize
!= 0)) {
423 Converts a Null-terminated Unicode string to legal characters in a FAT
424 filename using an OEM character set.
426 @param This Protocol instance pointer.
427 @param String A pointer to a Null-terminated Unicode string. The string must
428 be preallocated to hold FatSize Unicode characters.
429 @param FatSize The size of the string Fat in bytes.
430 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
431 name using an OEM character set.
433 @retval TRUE Fat is a Long File Name
434 @retval FALSE Fat is an 8.3 file name
440 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
446 BOOLEAN SpecialCharExist
;
448 SpecialCharExist
= FALSE
;
449 while ((*String
!= 0) && (FatSize
!= 0)) {
451 // Skip '.' or ' ' when making a fat name
453 if (*String
!= '.' && *String
!= ' ') {
455 // If this is a valid fat char, move it.
456 // Otherwise, move a '_' and flag the fact that the name needs a long file name.
458 if (*String
< MAP_TABLE_SIZE
&& ((mEngInfoMap
[*String
] & CHAR_FAT_VALID
) != 0)) {
459 *Fat
= mEngUpperMap
[*String
];
462 SpecialCharExist
= TRUE
;
472 // Do not terminate that fat string
474 return SpecialCharExist
;