2 Driver to implement English version of Unicode Collation Protocol.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "UnicodeCollationEng.h"
12 CHAR8 mEngUpperMap
[MAP_TABLE_SIZE
];
13 CHAR8 mEngLowerMap
[MAP_TABLE_SIZE
];
14 CHAR8 mEngInfoMap
[MAP_TABLE_SIZE
];
16 CHAR8 mOtherChars
[] = {
48 EFI_HANDLE mHandle
= NULL
;
51 // EFI Unicode Collation Protocol supporting ISO 639-2 language code
53 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_COLLATION_PROTOCOL UnicodeEng
= {
64 // EFI Unicode Collation2 Protocol supporting RFC 4646 language code
66 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_COLLATION_PROTOCOL Unicode2Eng
= {
77 The user Entry Point for English module.
79 This function initializes unicode character mapping and then installs Unicode
80 Collation & Unicode Collation 2 Protocols based on the feature flags.
82 @param ImageHandle The firmware allocated handle for the EFI image.
83 @param SystemTable A pointer to the EFI System Table.
85 @retval EFI_SUCCESS The entry point is executed successfully.
86 @retval other Some error occurs when executing this entry point.
91 InitializeUnicodeCollationEng (
92 IN EFI_HANDLE ImageHandle
,
93 IN EFI_SYSTEM_TABLE
*SystemTable
101 // Initialize mapping tables for the supported languages
103 for (Index
= 0; Index
< MAP_TABLE_SIZE
; Index
++) {
104 mEngUpperMap
[Index
] = (CHAR8
) Index
;
105 mEngLowerMap
[Index
] = (CHAR8
) Index
;
106 mEngInfoMap
[Index
] = 0;
108 if ((Index
>= 'a' && Index
<= 'z') || (Index
>= 0xe0 && Index
<= 0xf6) || (Index
>= 0xf8 && Index
<= 0xfe)) {
110 Index2
= Index
- 0x20;
111 mEngUpperMap
[Index
] = (CHAR8
) Index2
;
112 mEngLowerMap
[Index2
] = (CHAR8
) Index
;
114 mEngInfoMap
[Index
] |= CHAR_FAT_VALID
;
115 mEngInfoMap
[Index2
] |= CHAR_FAT_VALID
;
119 for (Index
= 0; mOtherChars
[Index
] != 0; Index
++) {
120 Index2
= mOtherChars
[Index
];
121 mEngInfoMap
[Index2
] |= CHAR_FAT_VALID
;
124 if (FeaturePcdGet (PcdUnicodeCollation2Support
)) {
125 if (FeaturePcdGet (PcdUnicodeCollationSupport
)) {
126 Status
= gBS
->InstallMultipleProtocolInterfaces (
128 &gEfiUnicodeCollationProtocolGuid
,
130 &gEfiUnicodeCollation2ProtocolGuid
,
134 ASSERT_EFI_ERROR (Status
);
136 Status
= gBS
->InstallMultipleProtocolInterfaces (
138 &gEfiUnicodeCollation2ProtocolGuid
,
142 ASSERT_EFI_ERROR (Status
);
145 if (FeaturePcdGet (PcdUnicodeCollationSupport
)) {
146 Status
= gBS
->InstallMultipleProtocolInterfaces (
148 &gEfiUnicodeCollationProtocolGuid
,
152 ASSERT_EFI_ERROR (Status
);
155 // This module must support to produce at least one of Unicode Collation Protocol
156 // and Unicode Collation 2 Protocol.
159 Status
= EFI_UNSUPPORTED
;
168 Performs a case-insensitive comparison of two Null-terminated strings.
170 @param This Protocol instance pointer.
171 @param Str1 A pointer to a Null-terminated string.
172 @param Str2 A pointer to a Null-terminated string.
174 @retval 0 Str1 is equivalent to Str2
175 @retval > 0 Str1 is lexically greater than Str2
176 @retval < 0 Str1 is lexically less than Str2
182 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
188 if (TO_UPPER (*Str1
) != TO_UPPER (*Str2
)) {
196 return TO_UPPER (*Str1
) - TO_UPPER (*Str2
);
201 Converts all the characters in a Null-terminated string to
202 lower case characters.
204 @param This Protocol instance pointer.
205 @param Str A pointer to a Null-terminated string.
211 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
216 *Str
= TO_LOWER (*Str
);
223 Converts all the characters in a Null-terminated string to upper
226 @param This Protocol instance pointer.
227 @param Str A pointer to a Null-terminated string.
233 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
238 *Str
= TO_UPPER (*Str
);
244 Performs a case-insensitive comparison of a Null-terminated
245 pattern string and a Null-terminated string.
247 @param This Protocol instance pointer.
248 @param String A pointer to a Null-terminated string.
249 @param Pattern A pointer to a Null-terminated pattern string.
251 @retval TRUE Pattern was found in String.
252 @retval FALSE Pattern was not found in String.
258 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
274 // End of pattern. If end of string, TRUE match
284 // Match zero or more chars
286 while (*String
!= 0) {
287 if (EngMetaiMatch (This
, String
, Pattern
)) {
294 return EngMetaiMatch (This
, String
, Pattern
);
298 // Match any one char
328 // if range of chars, get high range
331 if (CharP
== 0 || CharP
== ']') {
338 if (TO_UPPER (CharC
) >= TO_UPPER (Index3
) && TO_UPPER (CharC
) <= TO_UPPER (CharP
)) {
340 // if in range, it's a match
347 if (TO_UPPER (CharC
) == TO_UPPER (CharP
)) {
357 // skip to end of match char set
359 while ((CharP
!= 0) && (CharP
!= ']')) {
369 if (TO_UPPER (CharC
) != TO_UPPER (CharP
)) {
381 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated string.
383 @param This Protocol instance pointer.
384 @param FatSize The size of the string Fat in bytes.
385 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
386 name using an 8-bit OEM character set.
387 @param String A pointer to a Null-terminated string. The string must
388 be preallocated to hold FatSize characters.
394 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
401 // No DBCS issues, just expand and add null terminate to end of string
403 while ((*Fat
!= 0) && (FatSize
!= 0)) {
415 Converts a Null-terminated string to legal characters in a FAT
416 filename using an OEM character set.
418 @param This Protocol instance pointer.
419 @param String A pointer to a Null-terminated string. The string must
420 be preallocated to hold FatSize characters.
421 @param FatSize The size of the string Fat in bytes.
422 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
423 name using an OEM character set.
425 @retval TRUE Fat is a Long File Name
426 @retval FALSE Fat is an 8.3 file name
432 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
438 BOOLEAN SpecialCharExist
;
440 SpecialCharExist
= FALSE
;
441 while ((*String
!= 0) && (FatSize
!= 0)) {
443 // Skip '.' or ' ' when making a fat name
445 if (*String
!= '.' && *String
!= ' ') {
447 // If this is a valid fat char, move it.
448 // Otherwise, move a '_' and flag the fact that the name needs a long file name.
450 if (*String
< MAP_TABLE_SIZE
&& ((mEngInfoMap
[*String
] & CHAR_FAT_VALID
) != 0)) {
451 *Fat
= mEngUpperMap
[*String
];
454 SpecialCharExist
= TRUE
;
464 // Do not terminate that fat string
466 return SpecialCharExist
;