TianoCore EDK2 master
Loading...
Searching...
No Matches
UnicodeCollationEng.c
Go to the documentation of this file.
1
10
11CHAR8 mEngUpperMap[MAP_TABLE_SIZE];
12CHAR8 mEngLowerMap[MAP_TABLE_SIZE];
13CHAR8 mEngInfoMap[MAP_TABLE_SIZE];
14
15CHAR8 mOtherChars[] = {
16 '0',
17 '1',
18 '2',
19 '3',
20 '4',
21 '5',
22 '6',
23 '7',
24 '8',
25 '9',
26 '\\',
27 '.',
28 '_',
29 '^',
30 '$',
31 '~',
32 '!',
33 '#',
34 '%',
35 '&',
36 '-',
37 '{',
38 '}',
39 '(',
40 ')',
41 '@',
42 '`',
43 '\'',
44 '\0'
45};
46
48
49//
50// EFI Unicode Collation Protocol supporting ISO 639-2 language code
51//
59 "eng"
60};
61
62//
63// EFI Unicode Collation2 Protocol supporting RFC 4646 language code
64//
72 "en"
73};
74
89EFIAPI
91 IN EFI_HANDLE ImageHandle,
92 IN EFI_SYSTEM_TABLE *SystemTable
93 )
94{
95 EFI_STATUS Status;
96 UINTN Index;
97 UINTN Index2;
98
99 //
100 // Initialize mapping tables for the supported languages
101 //
102 for (Index = 0; Index < MAP_TABLE_SIZE; Index++) {
103 mEngUpperMap[Index] = (CHAR8)Index;
104 mEngLowerMap[Index] = (CHAR8)Index;
105 mEngInfoMap[Index] = 0;
106
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;
111
112 mEngInfoMap[Index] |= CHAR_FAT_VALID;
113 mEngInfoMap[Index2] |= CHAR_FAT_VALID;
114 }
115 }
116
117 for (Index = 0; mOtherChars[Index] != 0; Index++) {
118 Index2 = mOtherChars[Index];
119 mEngInfoMap[Index2] |= CHAR_FAT_VALID;
120 }
121
122 if (FeaturePcdGet (PcdUnicodeCollation2Support)) {
123 if (FeaturePcdGet (PcdUnicodeCollationSupport)) {
124 Status = gBS->InstallMultipleProtocolInterfaces (
125 &mHandle,
126 &gEfiUnicodeCollationProtocolGuid,
127 &UnicodeEng,
128 &gEfiUnicodeCollation2ProtocolGuid,
129 &Unicode2Eng,
130 NULL
131 );
132 ASSERT_EFI_ERROR (Status);
133 } else {
134 Status = gBS->InstallMultipleProtocolInterfaces (
135 &mHandle,
136 &gEfiUnicodeCollation2ProtocolGuid,
137 &Unicode2Eng,
138 NULL
139 );
140 ASSERT_EFI_ERROR (Status);
141 }
142 } else {
143 if (FeaturePcdGet (PcdUnicodeCollationSupport)) {
144 Status = gBS->InstallMultipleProtocolInterfaces (
145 &mHandle,
146 &gEfiUnicodeCollationProtocolGuid,
147 &UnicodeEng,
148 NULL
149 );
150 ASSERT_EFI_ERROR (Status);
151 } else {
152 //
153 // This module must support to produce at least one of Unicode Collation Protocol
154 // and Unicode Collation 2 Protocol.
155 //
156 ASSERT (FALSE);
157 Status = EFI_UNSUPPORTED;
158 }
159 }
160
161 return Status;
162}
163
176INTN
177EFIAPI
180 IN CHAR16 *Str1,
181 IN CHAR16 *Str2
182 )
183{
184 while (*Str1 != 0) {
185 if (TO_UPPER (*Str1) != TO_UPPER (*Str2)) {
186 break;
187 }
188
189 Str1 += 1;
190 Str2 += 1;
191 }
192
193 return TO_UPPER (*Str1) - TO_UPPER (*Str2);
194}
195
204VOID
205EFIAPI
208 IN OUT CHAR16 *Str
209 )
210{
211 while (*Str != 0) {
212 *Str = TO_LOWER (*Str);
213 Str += 1;
214 }
215}
216
225VOID
226EFIAPI
229 IN OUT CHAR16 *Str
230 )
231{
232 while (*Str != 0) {
233 *Str = TO_UPPER (*Str);
234 Str += 1;
235 }
236}
237
250BOOLEAN
251EFIAPI
254 IN CHAR16 *String,
255 IN CHAR16 *Pattern
256 )
257{
258 CHAR16 CharC;
259 CHAR16 CharP;
260 CHAR16 Index3;
261
262 for ( ; ;) {
263 CharP = *Pattern;
264 Pattern += 1;
265
266 switch (CharP) {
267 case 0:
268 //
269 // End of pattern. If end of string, TRUE match
270 //
271 if (*String != 0) {
272 return FALSE;
273 } else {
274 return TRUE;
275 }
276
277 case '*':
278 //
279 // Match zero or more chars
280 //
281 while (*String != 0) {
282 if (EngMetaiMatch (This, String, Pattern)) {
283 return TRUE;
284 }
285
286 String += 1;
287 }
288
289 return EngMetaiMatch (This, String, Pattern);
290
291 case '?':
292 //
293 // Match any one char
294 //
295 if (*String == 0) {
296 return FALSE;
297 }
298
299 String += 1;
300 break;
301
302 case '[':
303 //
304 // Match char set
305 //
306 CharC = *String;
307 if (CharC == 0) {
308 //
309 // syntax problem
310 //
311 return FALSE;
312 }
313
314 Index3 = 0;
315 CharP = *Pattern++;
316 while (CharP != 0) {
317 if (CharP == ']') {
318 return FALSE;
319 }
320
321 if (CharP == '-') {
322 //
323 // if range of chars, get high range
324 //
325 CharP = *Pattern;
326 if ((CharP == 0) || (CharP == ']')) {
327 //
328 // syntax problem
329 //
330 return FALSE;
331 }
332
333 if ((TO_UPPER (CharC) >= TO_UPPER (Index3)) && (TO_UPPER (CharC) <= TO_UPPER (CharP))) {
334 //
335 // if in range, it's a match
336 //
337 break;
338 }
339 }
340
341 Index3 = CharP;
342 if (TO_UPPER (CharC) == TO_UPPER (CharP)) {
343 //
344 // if char matches
345 //
346 break;
347 }
348
349 CharP = *Pattern++;
350 }
351
352 //
353 // skip to end of match char set
354 //
355 while ((CharP != 0) && (CharP != ']')) {
356 CharP = *Pattern;
357 Pattern += 1;
358 }
359
360 String += 1;
361 break;
362
363 default:
364 CharC = *String;
365 if (TO_UPPER (CharC) != TO_UPPER (CharP)) {
366 return FALSE;
367 }
368
369 String += 1;
370 break;
371 }
372 }
373}
374
386VOID
387EFIAPI
390 IN UINTN FatSize,
391 IN CHAR8 *Fat,
392 OUT CHAR16 *String
393 )
394{
395 //
396 // No DBCS issues, just expand and add null terminate to end of string
397 //
398 while ((*Fat != 0) && (FatSize != 0)) {
399 *String = *Fat;
400 String += 1;
401 Fat += 1;
402 FatSize -= 1;
403 }
404
405 *String = 0;
406}
407
423BOOLEAN
424EFIAPI
427 IN CHAR16 *String,
428 IN UINTN FatSize,
429 OUT CHAR8 *Fat
430 )
431{
432 BOOLEAN SpecialCharExist;
433
434 SpecialCharExist = FALSE;
435 while ((*String != 0) && (FatSize != 0)) {
436 //
437 // Skip '.' or ' ' when making a fat name
438 //
439 if ((*String != '.') && (*String != ' ')) {
440 //
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.
443 //
444 if ((*String < MAP_TABLE_SIZE) && ((mEngInfoMap[*String] & CHAR_FAT_VALID) != 0)) {
445 *Fat = mEngUpperMap[*String];
446 } else {
447 *Fat = '_';
448 SpecialCharExist = TRUE;
449 }
450
451 Fat += 1;
452 FatSize -= 1;
453 }
454
455 String += 1;
456 }
457
458 //
459 // Do not terminate that fat string
460 //
461 return SpecialCharExist;
462}
UINT64 UINTN
INT64 INTN
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define GLOBAL_REMOVE_IF_UNREFERENCED
Definition: Base.h:48
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define FeaturePcdGet(TokenName)
Definition: PcdLib.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
EFI_BOOT_SERVICES * gBS
BOOLEAN EFIAPI EngStrToFat(IN EFI_UNICODE_COLLATION_PROTOCOL *This, IN CHAR16 *String, IN UINTN FatSize, OUT CHAR8 *Fat)
VOID EFIAPI EngStrLwr(IN EFI_UNICODE_COLLATION_PROTOCOL *This, IN OUT CHAR16 *Str)
VOID EFIAPI EngFatToStr(IN EFI_UNICODE_COLLATION_PROTOCOL *This, IN UINTN FatSize, IN CHAR8 *Fat, OUT CHAR16 *String)
EFI_STATUS EFIAPI InitializeUnicodeCollationEng(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
VOID EFIAPI EngStrUpr(IN EFI_UNICODE_COLLATION_PROTOCOL *This, IN OUT CHAR16 *Str)
BOOLEAN EFIAPI EngMetaiMatch(IN EFI_UNICODE_COLLATION_PROTOCOL *This, IN CHAR16 *String, IN CHAR16 *Pattern)
INTN EFIAPI EngStriColl(IN EFI_UNICODE_COLLATION_PROTOCOL *This, IN CHAR16 *Str1, IN CHAR16 *Str2)
EFI_HANDLE mHandle