2 Driver to implement English version of Unicode Collation Protocol.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 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 strings.
176 @param This Protocol instance pointer.
177 @param Str1 A pointer to a Null-terminated string.
178 @param Str2 A pointer to a Null-terminated string.
180 @retval 0 Str1 is equivalent to Str2
181 @retval > 0 Str1 is lexically greater than Str2
182 @retval < 0 Str1 is lexically less than Str2
188 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
194 if (TO_UPPER (*Str1
) != TO_UPPER (*Str2
)) {
202 return TO_UPPER (*Str1
) - TO_UPPER (*Str2
);
207 Converts all the characters in a Null-terminated string to
208 lower case characters.
210 @param This Protocol instance pointer.
211 @param Str A pointer to a Null-terminated string.
217 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
222 *Str
= TO_LOWER (*Str
);
229 Converts all the characters in a Null-terminated string to upper
232 @param This Protocol instance pointer.
233 @param Str A pointer to a Null-terminated string.
239 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
244 *Str
= TO_UPPER (*Str
);
250 Performs a case-insensitive comparison of a Null-terminated
251 pattern string and a Null-terminated string.
253 @param This Protocol instance pointer.
254 @param String A pointer to a Null-terminated string.
255 @param Pattern A pointer to a Null-terminated pattern string.
257 @retval TRUE Pattern was found in String.
258 @retval FALSE Pattern was not found in String.
264 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
280 // End of pattern. If end of string, TRUE match
290 // Match zero or more chars
292 while (*String
!= 0) {
293 if (EngMetaiMatch (This
, String
, Pattern
)) {
300 return EngMetaiMatch (This
, String
, Pattern
);
304 // Match any one char
334 // if range of chars, get high range
337 if (CharP
== 0 || CharP
== ']') {
344 if (TO_UPPER (CharC
) >= TO_UPPER (Index3
) && TO_UPPER (CharC
) <= TO_UPPER (CharP
)) {
346 // if in range, it's a match
353 if (TO_UPPER (CharC
) == TO_UPPER (CharP
)) {
363 // skip to end of match char set
365 while ((CharP
!= 0) && (CharP
!= ']')) {
375 if (TO_UPPER (CharC
) != TO_UPPER (CharP
)) {
387 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated string.
389 @param This Protocol instance pointer.
390 @param FatSize The size of the string Fat in bytes.
391 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
392 name using an 8-bit OEM character set.
393 @param String A pointer to a Null-terminated string. The string must
394 be preallocated to hold FatSize characters.
400 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
407 // No DBCS issues, just expand and add null terminate to end of string
409 while ((*Fat
!= 0) && (FatSize
!= 0)) {
421 Converts a Null-terminated string to legal characters in a FAT
422 filename using an OEM character set.
424 @param This Protocol instance pointer.
425 @param String A pointer to a Null-terminated string. The string must
426 be preallocated to hold FatSize characters.
427 @param FatSize The size of the string Fat in bytes.
428 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
429 name using an OEM character set.
431 @retval TRUE Fat is a Long File Name
432 @retval FALSE Fat is an 8.3 file name
438 IN EFI_UNICODE_COLLATION_PROTOCOL
*This
,
444 BOOLEAN SpecialCharExist
;
446 SpecialCharExist
= FALSE
;
447 while ((*String
!= 0) && (FatSize
!= 0)) {
449 // Skip '.' or ' ' when making a fat name
451 if (*String
!= '.' && *String
!= ' ') {
453 // If this is a valid fat char, move it.
454 // Otherwise, move a '_' and flag the fact that the name needs a long file name.
456 if (*String
< MAP_TABLE_SIZE
&& ((mEngInfoMap
[*String
] & CHAR_FAT_VALID
) != 0)) {
457 *Fat
= mEngUpperMap
[*String
];
460 SpecialCharExist
= TRUE
;
470 // Do not terminate that fat string
472 return SpecialCharExist
;