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
9 #include "UnicodeCollationEng.h"
11 CHAR8 mEngUpperMap
[MAP_TABLE_SIZE
];
12 CHAR8 mEngLowerMap
[MAP_TABLE_SIZE
];
13 CHAR8 mEngInfoMap
[MAP_TABLE_SIZE
];
15 CHAR8 mOtherChars
[] = {
47 EFI_HANDLE mHandle
= NULL
;
50 // EFI Unicode Collation Protocol supporting ISO 639-2 language code
52 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_COLLATION_PROTOCOL UnicodeEng
= {
63 // EFI Unicode Collation2 Protocol supporting RFC 4646 language code
65 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_COLLATION_PROTOCOL Unicode2Eng
= {
76 The user Entry Point for English module.
78 This function initializes unicode character mapping and then installs Unicode
79 Collation & Unicode Collation 2 Protocols based on the feature flags.
81 @param ImageHandle The firmware allocated handle for the EFI image.
82 @param SystemTable A pointer to the EFI System Table.
84 @retval EFI_SUCCESS The entry point is executed successfully.
85 @retval other Some error occurs when executing this entry point.
90 InitializeUnicodeCollationEng (
91 IN EFI_HANDLE ImageHandle
,
92 IN EFI_SYSTEM_TABLE
*SystemTable
100 // Initialize mapping tables for the supported languages
102 for (Index
= 0; Index
< MAP_TABLE_SIZE
; Index
++) {
103 mEngUpperMap
[Index
] = (CHAR8
)Index
;
104 mEngLowerMap
[Index
] = (CHAR8
)Index
;
105 mEngInfoMap
[Index
] = 0;
107 if (((Index
>= 'a') && (Index
<= 'z')) || ((Index
>= 0xe0) && (Index
<= 0xf6)) || ((Index
>= 0xf8) && (Index
<= 0xfe))) {
108 Index2
= Index
- 0x20;
109 mEngUpperMap
[Index
] = (CHAR8
)Index2
;
110 mEngLowerMap
[Index2
] = (CHAR8
)Index
;
112 mEngInfoMap
[Index
] |= CHAR_FAT_VALID
;
113 mEngInfoMap
[Index2
] |= CHAR_FAT_VALID
;
117 for (Index
= 0; mOtherChars
[Index
] != 0; Index
++) {
118 Index2
= mOtherChars
[Index
];
119 mEngInfoMap
[Index2
] |= CHAR_FAT_VALID
;
122 if (FeaturePcdGet (PcdUnicodeCollation2Support
)) {
123 if (FeaturePcdGet (PcdUnicodeCollationSupport
)) {
124 Status
= gBS
->InstallMultipleProtocolInterfaces (
126 &gEfiUnicodeCollationProtocolGuid
,
128 &gEfiUnicodeCollation2ProtocolGuid
,
132 ASSERT_EFI_ERROR (Status
);
134 Status
= gBS
->InstallMultipleProtocolInterfaces (
136 &gEfiUnicodeCollation2ProtocolGuid
,
140 ASSERT_EFI_ERROR (Status
);
143 if (FeaturePcdGet (PcdUnicodeCollationSupport
)) {
144 Status
= gBS
->InstallMultipleProtocolInterfaces (
146 &gEfiUnicodeCollationProtocolGuid
,
150 ASSERT_EFI_ERROR (Status
);
153 // This module must support to produce at least one of Unicode Collation Protocol
154 // and Unicode Collation 2 Protocol.
157 Status
= EFI_UNSUPPORTED
;
165 Performs a case-insensitive comparison of two Null-terminated strings.
167 @param This Protocol instance pointer.
168 @param Str1 A pointer to a Null-terminated string.
169 @param Str2 A pointer to a Null-terminated string.
171 @retval 0 Str1 is equivalent to Str2
172 @retval > 0 Str1 is lexically greater than Str2
173 @retval < 0 Str1 is lexically less than Str2
179 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
185 if (TO_UPPER (*Str1
) != TO_UPPER (*Str2
)) {
193 return TO_UPPER (*Str1
) - TO_UPPER (*Str2
);
197 Converts all the characters in a Null-terminated string to
198 lower case characters.
200 @param This Protocol instance pointer.
201 @param Str A pointer to a Null-terminated string.
207 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
212 *Str
= TO_LOWER (*Str
);
218 Converts all the characters in a Null-terminated string to upper
221 @param This Protocol instance pointer.
222 @param Str A pointer to a Null-terminated string.
228 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
233 *Str
= TO_UPPER (*Str
);
239 Performs a case-insensitive comparison of a Null-terminated
240 pattern string and a Null-terminated string.
242 @param This Protocol instance pointer.
243 @param String A pointer to a Null-terminated string.
244 @param Pattern A pointer to a Null-terminated pattern string.
246 @retval TRUE Pattern was found in String.
247 @retval FALSE Pattern was not found in String.
253 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
269 // End of pattern. If end of string, TRUE match
279 // Match zero or more chars
281 while (*String
!= 0) {
282 if (EngMetaiMatch (This
, String
, Pattern
)) {
289 return EngMetaiMatch (This
, String
, Pattern
);
293 // Match any one char
323 // if range of chars, get high range
326 if ((CharP
== 0) || (CharP
== ']')) {
333 if ((TO_UPPER (CharC
) >= TO_UPPER (Index3
)) && (TO_UPPER (CharC
) <= TO_UPPER (CharP
))) {
335 // if in range, it's a match
342 if (TO_UPPER (CharC
) == TO_UPPER (CharP
)) {
353 // skip to end of match char set
355 while ((CharP
!= 0) && (CharP
!= ']')) {
365 if (TO_UPPER (CharC
) != TO_UPPER (CharP
)) {
376 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated string.
378 @param This Protocol instance pointer.
379 @param FatSize The size of the string Fat in bytes.
380 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
381 name using an 8-bit OEM character set.
382 @param String A pointer to a Null-terminated string. The string must
383 be preallocated to hold FatSize characters.
389 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
396 // No DBCS issues, just expand and add null terminate to end of string
398 while ((*Fat
!= 0) && (FatSize
!= 0)) {
409 Converts a Null-terminated string to legal characters in a FAT
410 filename using an OEM character set.
412 @param This Protocol instance pointer.
413 @param String A pointer to a Null-terminated string. The string must
414 be preallocated to hold FatSize characters.
415 @param FatSize The size of the string Fat in bytes.
416 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
417 name using an OEM character set.
419 @retval TRUE Fat is a Long File Name
420 @retval FALSE Fat is an 8.3 file name
426 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
432 BOOLEAN SpecialCharExist
;
434 SpecialCharExist
= FALSE
;
435 while ((*String
!= 0) && (FatSize
!= 0)) {
437 // Skip '.' or ' ' when making a fat name
439 if ((*String
!= '.') && (*String
!= ' ')) {
441 // If this is a valid fat char, move it.
442 // Otherwise, move a '_' and flag the fact that the name needs a long file name.
444 if ((*String
< MAP_TABLE_SIZE
) && ((mEngInfoMap
[*String
] & CHAR_FAT_VALID
) != 0)) {
445 *Fat
= mEngUpperMap
[*String
];
448 SpecialCharExist
= TRUE
;
459 // Do not terminate that fat string
461 return SpecialCharExist
;