]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/String.c
0b6a1957472fc169a59a741239cf7fe5c3372860
[mirror_edk2.git] / MdePkg / Library / BaseLib / String.c
1 /** @file
2 Unicode and ASCII string primatives.
3
4 Copyright (c) 2006 - 2010, 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.
9
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.
12
13 **/
14
15 #include "BaseLibInternals.h"
16
17 #define QUOTIENT_MAX_UINTN_DIVIDED_BY_10 ((~((UINTN) 0)) / 10U)
18 #define REMAINDER_MAX_UINTN_DIVIDED_BY_10 ((~((UINTN) 0)) % 10U)
19
20
21 #define QUOTIENT_MAX_UINTN_DIVIDED_BY_16 ((~((UINTN) 0)) / 16U)
22 #define REMAINDER_MAX_UINTN_DIVIDED_BY_16 ((~((UINTN) 0)) % 16U)
23
24 #define QUOTIENT_MAX_UINT64_DIVIDED_BY_10 ((~((UINT64) 0)) / 10U)
25 #define REMAINDER_MAX_UINT64_DIVIDED_BY_10 ((~((UINT64) 0)) % 10U)
26
27 #define QUOTIENT_MAX_UINT64_DIVIDED_BY_16 ((~((UINT64) 0)) / 16U)
28 #define REMAINDER_MAX_UINT64_DIVIDED_BY_16 ((~((UINT64) 0)) % 16U)
29
30 /**
31 Copies one Null-terminated Unicode string to another Null-terminated Unicode
32 string and returns the new Unicode string.
33
34 This function copies the contents of the Unicode string Source to the Unicode
35 string Destination, and returns Destination. If Source and Destination
36 overlap, then the results are undefined.
37
38 If Destination is NULL, then ASSERT().
39 If Destination is not aligned on a 16-bit boundary, then ASSERT().
40 If Source is NULL, then ASSERT().
41 If Source is not aligned on a 16-bit boundary, then ASSERT().
42 If Source and Destination overlap, then ASSERT().
43 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
44 PcdMaximumUnicodeStringLength Unicode characters, not including the
45 Null-terminator, then ASSERT().
46
47 @param Destination A pointer to a Null-terminated Unicode string.
48 @param Source A pointer to a Null-terminated Unicode string.
49
50 @return Destination.
51
52 **/
53 CHAR16 *
54 EFIAPI
55 StrCpy (
56 OUT CHAR16 *Destination,
57 IN CONST CHAR16 *Source
58 )
59 {
60 CHAR16 *ReturnValue;
61
62 //
63 // Destination cannot be NULL
64 //
65 ASSERT (Destination != NULL);
66 ASSERT (((UINTN) Destination & BIT0) == 0);
67
68 //
69 // Destination and source cannot overlap
70 //
71 ASSERT ((UINTN)(Destination - Source) > StrLen (Source));
72 ASSERT ((UINTN)(Source - Destination) > StrLen (Source));
73
74 ReturnValue = Destination;
75 while (*Source != 0) {
76 *(Destination++) = *(Source++);
77 }
78 *Destination = 0;
79 return ReturnValue;
80 }
81
82 /**
83 Copies up to a specified length from one Null-terminated Unicode string to
84 another Null-terminated Unicode string and returns the new Unicode string.
85
86 This function copies the contents of the Unicode string Source to the Unicode
87 string Destination, and returns Destination. At most, Length Unicode
88 characters are copied from Source to Destination. If Length is 0, then
89 Destination is returned unmodified. If Length is greater that the number of
90 Unicode characters in Source, then Destination is padded with Null Unicode
91 characters. If Source and Destination overlap, then the results are
92 undefined.
93
94 If Length > 0 and Destination is NULL, then ASSERT().
95 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
96 If Length > 0 and Source is NULL, then ASSERT().
97 If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().
98 If Source and Destination overlap, then ASSERT().
99 If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
100 PcdMaximumUnicodeStringLength, then ASSERT().
101 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
102 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
103 then ASSERT().
104
105 @param Destination A pointer to a Null-terminated Unicode string.
106 @param Source A pointer to a Null-terminated Unicode string.
107 @param Length The maximum number of Unicode characters to copy.
108
109 @return Destination.
110
111 **/
112 CHAR16 *
113 EFIAPI
114 StrnCpy (
115 OUT CHAR16 *Destination,
116 IN CONST CHAR16 *Source,
117 IN UINTN Length
118 )
119 {
120 CHAR16 *ReturnValue;
121
122 if (Length == 0) {
123 return Destination;
124 }
125
126 //
127 // Destination cannot be NULL if Length is not zero
128 //
129 ASSERT (Destination != NULL);
130 ASSERT (((UINTN) Destination & BIT0) == 0);
131
132 //
133 // Destination and source cannot overlap
134 //
135 ASSERT ((UINTN)(Destination - Source) > StrLen (Source));
136 ASSERT ((UINTN)(Source - Destination) >= Length);
137
138 if (PcdGet32 (PcdMaximumUnicodeStringLength) != 0) {
139 ASSERT (Length <= PcdGet32 (PcdMaximumUnicodeStringLength));
140 }
141
142 ReturnValue = Destination;
143
144 while ((*Source != L'\0') && (Length > 0)) {
145 *(Destination++) = *(Source++);
146 Length--;
147 }
148
149 ZeroMem (Destination, Length * sizeof (*Destination));
150 return ReturnValue;
151 }
152
153 /**
154 Returns the length of a Null-terminated Unicode string.
155
156 This function returns the number of Unicode characters in the Null-terminated
157 Unicode string specified by String.
158
159 If String is NULL, then ASSERT().
160 If String is not aligned on a 16-bit boundary, then ASSERT().
161 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
162 PcdMaximumUnicodeStringLength Unicode characters, not including the
163 Null-terminator, then ASSERT().
164
165 @param String A pointer to a Null-terminated Unicode string.
166
167 @return The length of String.
168
169 **/
170 UINTN
171 EFIAPI
172 StrLen (
173 IN CONST CHAR16 *String
174 )
175 {
176 UINTN Length;
177
178 ASSERT (String != NULL);
179 ASSERT (((UINTN) String & BIT0) == 0);
180
181 for (Length = 0; *String != L'\0'; String++, Length++) {
182 //
183 // If PcdMaximumUnicodeStringLength is not zero,
184 // length should not more than PcdMaximumUnicodeStringLength
185 //
186 if (PcdGet32 (PcdMaximumUnicodeStringLength) != 0) {
187 ASSERT (Length < PcdGet32 (PcdMaximumUnicodeStringLength));
188 }
189 }
190 return Length;
191 }
192
193 /**
194 Returns the size of a Null-terminated Unicode string in bytes, including the
195 Null terminator.
196
197 This function returns the size, in bytes, of the Null-terminated Unicode string
198 specified by String.
199
200 If String is NULL, then ASSERT().
201 If String is not aligned on a 16-bit boundary, then ASSERT().
202 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
203 PcdMaximumUnicodeStringLength Unicode characters, not including the
204 Null-terminator, then ASSERT().
205
206 @param String A pointer to a Null-terminated Unicode string.
207
208 @return The size of String.
209
210 **/
211 UINTN
212 EFIAPI
213 StrSize (
214 IN CONST CHAR16 *String
215 )
216 {
217 return (StrLen (String) + 1) * sizeof (*String);
218 }
219
220 /**
221 Compares two Null-terminated Unicode strings, and returns the difference
222 between the first mismatched Unicode characters.
223
224 This function compares the Null-terminated Unicode string FirstString to the
225 Null-terminated Unicode string SecondString. If FirstString is identical to
226 SecondString, then 0 is returned. Otherwise, the value returned is the first
227 mismatched Unicode character in SecondString subtracted from the first
228 mismatched Unicode character in FirstString.
229
230 If FirstString is NULL, then ASSERT().
231 If FirstString is not aligned on a 16-bit boundary, then ASSERT().
232 If SecondString is NULL, then ASSERT().
233 If SecondString is not aligned on a 16-bit boundary, then ASSERT().
234 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
235 than PcdMaximumUnicodeStringLength Unicode characters, not including the
236 Null-terminator, then ASSERT().
237 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
238 than PcdMaximumUnicodeStringLength Unicode characters, not including the
239 Null-terminator, then ASSERT().
240
241 @param FirstString A pointer to a Null-terminated Unicode string.
242 @param SecondString A pointer to a Null-terminated Unicode string.
243
244 @retval 0 FirstString is identical to SecondString.
245 @return others FirstString is not identical to SecondString.
246
247 **/
248 INTN
249 EFIAPI
250 StrCmp (
251 IN CONST CHAR16 *FirstString,
252 IN CONST CHAR16 *SecondString
253 )
254 {
255 //
256 // ASSERT both strings are less long than PcdMaximumUnicodeStringLength
257 //
258 ASSERT (StrSize (FirstString) != 0);
259 ASSERT (StrSize (SecondString) != 0);
260
261 while ((*FirstString != L'\0') && (*FirstString == *SecondString)) {
262 FirstString++;
263 SecondString++;
264 }
265 return *FirstString - *SecondString;
266 }
267
268 /**
269 Compares up to a specified length the contents of two Null-terminated Unicode strings,
270 and returns the difference between the first mismatched Unicode characters.
271
272 This function compares the Null-terminated Unicode string FirstString to the
273 Null-terminated Unicode string SecondString. At most, Length Unicode
274 characters will be compared. If Length is 0, then 0 is returned. If
275 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
276 value returned is the first mismatched Unicode character in SecondString
277 subtracted from the first mismatched Unicode character in FirstString.
278
279 If Length > 0 and FirstString is NULL, then ASSERT().
280 If Length > 0 and FirstString is not aligned on a 16-bit boundary, then ASSERT().
281 If Length > 0 and SecondString is NULL, then ASSERT().
282 If Length > 0 and SecondString is not aligned on a 16-bit boundary, then ASSERT().
283 If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
284 PcdMaximumUnicodeStringLength, then ASSERT().
285 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more than
286 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
287 then ASSERT().
288 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more than
289 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
290 then ASSERT().
291
292 @param FirstString A pointer to a Null-terminated Unicode string.
293 @param SecondString A pointer to a Null-terminated Unicode string.
294 @param Length The maximum number of Unicode characters to compare.
295
296 @retval 0 FirstString is identical to SecondString.
297 @return others FirstString is not identical to SecondString.
298
299 **/
300 INTN
301 EFIAPI
302 StrnCmp (
303 IN CONST CHAR16 *FirstString,
304 IN CONST CHAR16 *SecondString,
305 IN UINTN Length
306 )
307 {
308 if (Length == 0) {
309 return 0;
310 }
311
312 //
313 // ASSERT both strings are less long than PcdMaximumUnicodeStringLength.
314 // Length tests are performed inside StrLen().
315 //
316 ASSERT (StrSize (FirstString) != 0);
317 ASSERT (StrSize (SecondString) != 0);
318
319 if (PcdGet32 (PcdMaximumUnicodeStringLength) != 0) {
320 ASSERT (Length <= PcdGet32 (PcdMaximumUnicodeStringLength));
321 }
322
323 while ((*FirstString != L'\0') &&
324 (*FirstString == *SecondString) &&
325 (Length > 1)) {
326 FirstString++;
327 SecondString++;
328 Length--;
329 }
330
331 return *FirstString - *SecondString;
332 }
333
334 /**
335 Concatenates one Null-terminated Unicode string to another Null-terminated
336 Unicode string, and returns the concatenated Unicode string.
337
338 This function concatenates two Null-terminated Unicode strings. The contents
339 of Null-terminated Unicode string Source are concatenated to the end of
340 Null-terminated Unicode string Destination. The Null-terminated concatenated
341 Unicode String is returned. If Source and Destination overlap, then the
342 results are undefined.
343
344 If Destination is NULL, then ASSERT().
345 If Destination is not aligned on a 16-bit boundary, then ASSERT().
346 If Source is NULL, then ASSERT().
347 If Source is not aligned on a 16-bit boundary, then ASSERT().
348 If Source and Destination overlap, then ASSERT().
349 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
350 than PcdMaximumUnicodeStringLength Unicode characters, not including the
351 Null-terminator, then ASSERT().
352 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
353 PcdMaximumUnicodeStringLength Unicode characters, not including the
354 Null-terminator, then ASSERT().
355 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
356 and Source results in a Unicode string with more than
357 PcdMaximumUnicodeStringLength Unicode characters, not including the
358 Null-terminator, then ASSERT().
359
360 @param Destination A pointer to a Null-terminated Unicode string.
361 @param Source A pointer to a Null-terminated Unicode string.
362
363 @return Destination.
364
365 **/
366 CHAR16 *
367 EFIAPI
368 StrCat (
369 IN OUT CHAR16 *Destination,
370 IN CONST CHAR16 *Source
371 )
372 {
373 StrCpy (Destination + StrLen (Destination), Source);
374
375 //
376 // Size of the resulting string should never be zero.
377 // PcdMaximumUnicodeStringLength is tested inside StrLen().
378 //
379 ASSERT (StrSize (Destination) != 0);
380 return Destination;
381 }
382
383 /**
384 Concatenates up to a specified length one Null-terminated Unicode to the end
385 of another Null-terminated Unicode string, and returns the concatenated
386 Unicode string.
387
388 This function concatenates two Null-terminated Unicode strings. The contents
389 of Null-terminated Unicode string Source are concatenated to the end of
390 Null-terminated Unicode string Destination, and Destination is returned. At
391 most, Length Unicode characters are concatenated from Source to the end of
392 Destination, and Destination is always Null-terminated. If Length is 0, then
393 Destination is returned unmodified. If Source and Destination overlap, then
394 the results are undefined.
395
396 If Destination is NULL, then ASSERT().
397 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
398 If Length > 0 and Source is NULL, then ASSERT().
399 If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().
400 If Source and Destination overlap, then ASSERT().
401 If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
402 PcdMaximumUnicodeStringLength, then ASSERT().
403 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
404 than PcdMaximumUnicodeStringLength Unicode characters, not including the
405 Null-terminator, then ASSERT().
406 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
407 PcdMaximumUnicodeStringLength Unicode characters, not including the
408 Null-terminator, then ASSERT().
409 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
410 and Source results in a Unicode string with more than PcdMaximumUnicodeStringLength
411 Unicode characters, not including the Null-terminator, then ASSERT().
412
413 @param Destination A pointer to a Null-terminated Unicode string.
414 @param Source A pointer to a Null-terminated Unicode string.
415 @param Length The maximum number of Unicode characters to concatenate from
416 Source.
417
418 @return Destination.
419
420 **/
421 CHAR16 *
422 EFIAPI
423 StrnCat (
424 IN OUT CHAR16 *Destination,
425 IN CONST CHAR16 *Source,
426 IN UINTN Length
427 )
428 {
429 UINTN DestinationLen;
430
431 DestinationLen = StrLen (Destination);
432 StrnCpy (Destination + DestinationLen, Source, Length);
433 Destination[DestinationLen + Length] = L'\0';
434
435 //
436 // Size of the resulting string should never be zero.
437 // PcdMaximumUnicodeStringLength is tested inside StrLen().
438 //
439 ASSERT (StrSize (Destination) != 0);
440 return Destination;
441 }
442
443 /**
444 Returns the first occurrence of a Null-terminated Unicode sub-string
445 in a Null-terminated Unicode string.
446
447 This function scans the contents of the Null-terminated Unicode string
448 specified by String and returns the first occurrence of SearchString.
449 If SearchString is not found in String, then NULL is returned. If
450 the length of SearchString is zero, then String is
451 returned.
452
453 If String is NULL, then ASSERT().
454 If String is not aligned on a 16-bit boundary, then ASSERT().
455 If SearchString is NULL, then ASSERT().
456 If SearchString is not aligned on a 16-bit boundary, then ASSERT().
457
458 If PcdMaximumUnicodeStringLength is not zero, and SearchString
459 or String contains more than PcdMaximumUnicodeStringLength Unicode
460 characters, not including the Null-terminator, then ASSERT().
461
462 @param String A pointer to a Null-terminated Unicode string.
463 @param SearchString A pointer to a Null-terminated Unicode string to search for.
464
465 @retval NULL If the SearchString does not appear in String.
466 @return others If there is a match.
467
468 **/
469 CHAR16 *
470 EFIAPI
471 StrStr (
472 IN CONST CHAR16 *String,
473 IN CONST CHAR16 *SearchString
474 )
475 {
476 CONST CHAR16 *FirstMatch;
477 CONST CHAR16 *SearchStringTmp;
478
479 //
480 // ASSERT both strings are less long than PcdMaximumUnicodeStringLength.
481 // Length tests are performed inside StrLen().
482 //
483 ASSERT (StrSize (String) != 0);
484 ASSERT (StrSize (SearchString) != 0);
485
486 if (*SearchString == L'\0') {
487 return (CHAR16 *) String;
488 }
489
490 while (*String != L'\0') {
491 SearchStringTmp = SearchString;
492 FirstMatch = String;
493
494 while ((*String == *SearchStringTmp)
495 && (*String != L'\0')) {
496 String++;
497 SearchStringTmp++;
498 }
499
500 if (*SearchStringTmp == L'\0') {
501 return (CHAR16 *) FirstMatch;
502 }
503
504 if (*String == L'\0') {
505 return NULL;
506 }
507
508 String = FirstMatch + 1;
509 }
510
511 return NULL;
512 }
513
514 /**
515 Check if a Unicode character is a decimal character.
516
517 This internal function checks if a Unicode character is a
518 decimal character. The valid decimal character is from
519 L'0' to L'9'.
520
521 @param Char The character to check against.
522
523 @retval TRUE If the Char is a decmial character.
524 @retval FALSE If the Char is not a decmial character.
525
526 **/
527 BOOLEAN
528 EFIAPI
529 InternalIsDecimalDigitCharacter (
530 IN CHAR16 Char
531 )
532 {
533 return (BOOLEAN) (Char >= L'0' && Char <= L'9');
534 }
535
536 /**
537 Convert a Unicode character to upper case only if
538 it maps to a valid small-case ASCII character.
539
540 This internal function only deal with Unicode character
541 which maps to a valid small-case ASCII character, i.e.
542 L'a' to L'z'. For other Unicode character, the input character
543 is returned directly.
544
545 @param Char The character to convert.
546
547 @retval LowerCharacter If the Char is with range L'a' to L'z'.
548 @retval Unchanged Otherwise.
549
550 **/
551 CHAR16
552 EFIAPI
553 InternalCharToUpper (
554 IN CHAR16 Char
555 )
556 {
557 if (Char >= L'a' && Char <= L'z') {
558 return (CHAR16) (Char - (L'a' - L'A'));
559 }
560
561 return Char;
562 }
563
564 /**
565 Convert a Unicode character to numerical value.
566
567 This internal function only deal with Unicode character
568 which maps to a valid hexadecimal ASII character, i.e.
569 L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other
570 Unicode character, the value returned does not make sense.
571
572 @param Char The character to convert.
573
574 @return The numerical value converted.
575
576 **/
577 UINTN
578 EFIAPI
579 InternalHexCharToUintn (
580 IN CHAR16 Char
581 )
582 {
583 if (InternalIsDecimalDigitCharacter (Char)) {
584 return Char - L'0';
585 }
586
587 return (UINTN) (10 + InternalCharToUpper (Char) - L'A');
588 }
589
590 /**
591 Check if a Unicode character is a hexadecimal character.
592
593 This internal function checks if a Unicode character is a
594 decimal character. The valid hexadecimal character is
595 L'0' to L'9', L'a' to L'f', or L'A' to L'F'.
596
597
598 @param Char The character to check against.
599
600 @retval TRUE If the Char is a hexadecmial character.
601 @retval FALSE If the Char is not a hexadecmial character.
602
603 **/
604 BOOLEAN
605 EFIAPI
606 InternalIsHexaDecimalDigitCharacter (
607 IN CHAR16 Char
608 )
609 {
610
611 return (BOOLEAN) (InternalIsDecimalDigitCharacter (Char) ||
612 (Char >= L'A' && Char <= L'F') ||
613 (Char >= L'a' && Char <= L'f'));
614 }
615
616 /**
617 Convert a Null-terminated Unicode decimal string to a value of
618 type UINTN.
619
620 This function returns a value of type UINTN by interpreting the contents
621 of the Unicode string specified by String as a decimal number. The format
622 of the input Unicode string String is:
623
624 [spaces] [decimal digits].
625
626 The valid decimal digit character is in the range [0-9]. The
627 function will ignore the pad space, which includes spaces or
628 tab characters, before [decimal digits]. The running zero in the
629 beginning of [decimal digits] will be ignored. Then, the function
630 stops at the first character that is a not a valid decimal character
631 or a Null-terminator, whichever one comes first.
632
633 If String is NULL, then ASSERT().
634 If String is not aligned in a 16-bit boundary, then ASSERT().
635 If String has only pad spaces, then 0 is returned.
636 If String has no pad spaces or valid decimal digits,
637 then 0 is returned.
638 If the number represented by String overflows according
639 to the range defined by UINTN, then ASSERT().
640
641 If PcdMaximumUnicodeStringLength is not zero, and String contains
642 more than PcdMaximumUnicodeStringLength Unicode characters, not including
643 the Null-terminator, then ASSERT().
644
645 @param String A pointer to a Null-terminated Unicode string.
646
647 @retval Value translated from String.
648
649 **/
650 UINTN
651 EFIAPI
652 StrDecimalToUintn (
653 IN CONST CHAR16 *String
654 )
655 {
656 UINTN Result;
657
658 //
659 // ASSERT String is less long than PcdMaximumUnicodeStringLength.
660 // Length tests are performed inside StrLen().
661 //
662 ASSERT (StrSize (String) != 0);
663
664 //
665 // Ignore the pad spaces (space or tab)
666 //
667 while ((*String == L' ') || (*String == L'\t')) {
668 String++;
669 }
670
671 //
672 // Ignore leading Zeros after the spaces
673 //
674 while (*String == L'0') {
675 String++;
676 }
677
678 Result = 0;
679
680 while (InternalIsDecimalDigitCharacter (*String)) {
681 //
682 // If the number represented by String overflows according
683 // to the range defined by UINTN, then ASSERT().
684 //
685 ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_10) ||
686 ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_10) &&
687 (*String - L'0') <= REMAINDER_MAX_UINTN_DIVIDED_BY_10)
688 );
689
690 Result = Result * 10 + (*String - L'0');
691 String++;
692 }
693
694 return Result;
695 }
696
697
698 /**
699 Convert a Null-terminated Unicode decimal string to a value of
700 type UINT64.
701
702 This function returns a value of type UINT64 by interpreting the contents
703 of the Unicode string specified by String as a decimal number. The format
704 of the input Unicode string String is:
705
706 [spaces] [decimal digits].
707
708 The valid decimal digit character is in the range [0-9]. The
709 function will ignore the pad space, which includes spaces or
710 tab characters, before [decimal digits]. The running zero in the
711 beginning of [decimal digits] will be ignored. Then, the function
712 stops at the first character that is a not a valid decimal character
713 or a Null-terminator, whichever one comes first.
714
715 If String is NULL, then ASSERT().
716 If String is not aligned in a 16-bit boundary, then ASSERT().
717 If String has only pad spaces, then 0 is returned.
718 If String has no pad spaces or valid decimal digits,
719 then 0 is returned.
720 If the number represented by String overflows according
721 to the range defined by UINT64, then ASSERT().
722
723 If PcdMaximumUnicodeStringLength is not zero, and String contains
724 more than PcdMaximumUnicodeStringLength Unicode characters, not including
725 the Null-terminator, then ASSERT().
726
727 @param String A pointer to a Null-terminated Unicode string.
728
729 @retval Value translated from String.
730
731 **/
732 UINT64
733 EFIAPI
734 StrDecimalToUint64 (
735 IN CONST CHAR16 *String
736 )
737 {
738 UINT64 Result;
739
740 //
741 // ASSERT String is less long than PcdMaximumUnicodeStringLength.
742 // Length tests are performed inside StrLen().
743 //
744 ASSERT (StrSize (String) != 0);
745
746 //
747 // Ignore the pad spaces (space or tab)
748 //
749 while ((*String == L' ') || (*String == L'\t')) {
750 String++;
751 }
752
753 //
754 // Ignore leading Zeros after the spaces
755 //
756 while (*String == L'0') {
757 String++;
758 }
759
760 Result = 0;
761
762 while (InternalIsDecimalDigitCharacter (*String)) {
763 //
764 // If the number represented by String overflows according
765 // to the range defined by UINTN, then ASSERT().
766 //
767 ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_10) ||
768 ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_10) &&
769 (*String - L'0') <= REMAINDER_MAX_UINT64_DIVIDED_BY_10)
770 );
771
772 Result = MultU64x32 (Result, 10) + (*String - L'0');
773 String++;
774 }
775
776 return Result;
777 }
778
779 /**
780 Convert a Null-terminated Unicode hexadecimal string to a value of type UINTN.
781
782 This function returns a value of type UINTN by interpreting the contents
783 of the Unicode string specified by String as a hexadecimal number.
784 The format of the input Unicode string String is:
785
786 [spaces][zeros][x][hexadecimal digits].
787
788 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
789 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
790 If "x" appears in the input string, it must be prefixed with at least one 0.
791 The function will ignore the pad space, which includes spaces or tab characters,
792 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
793 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
794 first valid hexadecimal digit. Then, the function stops at the first character that is
795 a not a valid hexadecimal character or NULL, whichever one comes first.
796
797 If String is NULL, then ASSERT().
798 If String is not aligned in a 16-bit boundary, then ASSERT().
799 If String has only pad spaces, then zero is returned.
800 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
801 then zero is returned.
802 If the number represented by String overflows according to the range defined by
803 UINTN, then ASSERT().
804
805 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
806 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
807 then ASSERT().
808
809 @param String A pointer to a Null-terminated Unicode string.
810
811 @retval Value translated from String.
812
813 **/
814 UINTN
815 EFIAPI
816 StrHexToUintn (
817 IN CONST CHAR16 *String
818 )
819 {
820 UINTN Result;
821
822 //
823 // ASSERT String is less long than PcdMaximumUnicodeStringLength.
824 // Length tests are performed inside StrLen().
825 //
826 ASSERT (StrSize (String) != 0);
827
828 //
829 // Ignore the pad spaces (space or tab)
830 //
831 while ((*String == L' ') || (*String == L'\t')) {
832 String++;
833 }
834
835 //
836 // Ignore leading Zeros after the spaces
837 //
838 while (*String == L'0') {
839 String++;
840 }
841
842 if (InternalCharToUpper (*String) == L'X') {
843 if (*(String - 1) != L'0') {
844 return 0;
845 }
846 //
847 // Skip the 'X'
848 //
849 String++;
850 }
851
852 Result = 0;
853
854 while (InternalIsHexaDecimalDigitCharacter (*String)) {
855 //
856 // If the Hex Number represented by String overflows according
857 // to the range defined by UINTN, then ASSERT().
858 //
859 ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_16) ||
860 ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_16) &&
861 (InternalHexCharToUintn (*String) <= REMAINDER_MAX_UINTN_DIVIDED_BY_16))
862 );
863
864 Result = (Result << 4) + InternalHexCharToUintn (*String);
865 String++;
866 }
867
868 return Result;
869 }
870
871
872 /**
873 Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.
874
875 This function returns a value of type UINT64 by interpreting the contents
876 of the Unicode string specified by String as a hexadecimal number.
877 The format of the input Unicode string String is
878
879 [spaces][zeros][x][hexadecimal digits].
880
881 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
882 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
883 If "x" appears in the input string, it must be prefixed with at least one 0.
884 The function will ignore the pad space, which includes spaces or tab characters,
885 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
886 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
887 first valid hexadecimal digit. Then, the function stops at the first character that is
888 a not a valid hexadecimal character or NULL, whichever one comes first.
889
890 If String is NULL, then ASSERT().
891 If String is not aligned in a 16-bit boundary, then ASSERT().
892 If String has only pad spaces, then zero is returned.
893 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
894 then zero is returned.
895 If the number represented by String overflows according to the range defined by
896 UINT64, then ASSERT().
897
898 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
899 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
900 then ASSERT().
901
902 @param String A pointer to a Null-terminated Unicode string.
903
904 @retval Value translated from String.
905
906 **/
907 UINT64
908 EFIAPI
909 StrHexToUint64 (
910 IN CONST CHAR16 *String
911 )
912 {
913 UINT64 Result;
914
915 //
916 // ASSERT String is less long than PcdMaximumUnicodeStringLength.
917 // Length tests are performed inside StrLen().
918 //
919 ASSERT (StrSize (String) != 0);
920
921 //
922 // Ignore the pad spaces (space or tab)
923 //
924 while ((*String == L' ') || (*String == L'\t')) {
925 String++;
926 }
927
928 //
929 // Ignore leading Zeros after the spaces
930 //
931 while (*String == L'0') {
932 String++;
933 }
934
935 if (InternalCharToUpper (*String) == L'X') {
936 ASSERT (*(String - 1) == L'0');
937 if (*(String - 1) != L'0') {
938 return 0;
939 }
940 //
941 // Skip the 'X'
942 //
943 String++;
944 }
945
946 Result = 0;
947
948 while (InternalIsHexaDecimalDigitCharacter (*String)) {
949 //
950 // If the Hex Number represented by String overflows according
951 // to the range defined by UINTN, then ASSERT().
952 //
953 ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_16)||
954 ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_16) &&
955 (InternalHexCharToUintn (*String) <= REMAINDER_MAX_UINT64_DIVIDED_BY_16))
956 );
957
958 Result = LShiftU64 (Result, 4);
959 Result = Result + InternalHexCharToUintn (*String);
960 String++;
961 }
962
963 return Result;
964 }
965
966 /**
967 Check if a ASCII character is a decimal character.
968
969 This internal function checks if a Unicode character is a
970 decimal character. The valid decimal character is from
971 '0' to '9'.
972
973 @param Char The character to check against.
974
975 @retval TRUE If the Char is a decmial character.
976 @retval FALSE If the Char is not a decmial character.
977
978 **/
979 BOOLEAN
980 EFIAPI
981 InternalAsciiIsDecimalDigitCharacter (
982 IN CHAR8 Char
983 )
984 {
985 return (BOOLEAN) (Char >= '0' && Char <= '9');
986 }
987
988 /**
989 Check if a ASCII character is a hexadecimal character.
990
991 This internal function checks if a ASCII character is a
992 decimal character. The valid hexadecimal character is
993 L'0' to L'9', L'a' to L'f', or L'A' to L'F'.
994
995
996 @param Char The character to check against.
997
998 @retval TRUE If the Char is a hexadecmial character.
999 @retval FALSE If the Char is not a hexadecmial character.
1000
1001 **/
1002 BOOLEAN
1003 EFIAPI
1004 InternalAsciiIsHexaDecimalDigitCharacter (
1005 IN CHAR8 Char
1006 )
1007 {
1008
1009 return (BOOLEAN) (InternalAsciiIsDecimalDigitCharacter (Char) ||
1010 (Char >= 'A' && Char <= 'F') ||
1011 (Char >= 'a' && Char <= 'f'));
1012 }
1013
1014 /**
1015 Convert a Null-terminated Unicode string to a Null-terminated
1016 ASCII string and returns the ASCII string.
1017
1018 This function converts the content of the Unicode string Source
1019 to the ASCII string Destination by copying the lower 8 bits of
1020 each Unicode character. It returns Destination.
1021
1022 If any Unicode characters in Source contain non-zero value in
1023 the upper 8 bits, then ASSERT().
1024
1025 If Destination is NULL, then ASSERT().
1026 If Source is NULL, then ASSERT().
1027 If Source is not aligned on a 16-bit boundary, then ASSERT().
1028 If Source and Destination overlap, then ASSERT().
1029
1030 If PcdMaximumUnicodeStringLength is not zero, and Source contains
1031 more than PcdMaximumUnicodeStringLength Unicode characters, not including
1032 the Null-terminator, then ASSERT().
1033
1034 If PcdMaximumAsciiStringLength is not zero, and Source contains more
1035 than PcdMaximumAsciiStringLength Unicode characters, not including the
1036 Null-terminator, then ASSERT().
1037
1038 @param Source A pointer to a Null-terminated Unicode string.
1039 @param Destination A pointer to a Null-terminated ASCII string.
1040
1041 @return Destination.
1042
1043 **/
1044 CHAR8 *
1045 EFIAPI
1046 UnicodeStrToAsciiStr (
1047 IN CONST CHAR16 *Source,
1048 OUT CHAR8 *Destination
1049 )
1050 {
1051 CHAR8 *ReturnValue;
1052
1053 ASSERT (Destination != NULL);
1054
1055 //
1056 // ASSERT if Source is long than PcdMaximumUnicodeStringLength.
1057 // Length tests are performed inside StrLen().
1058 //
1059 ASSERT (StrSize (Source) != 0);
1060
1061 //
1062 // Source and Destination should not overlap
1063 //
1064 ASSERT ((UINTN) ((CHAR16 *) Destination - Source) > StrLen (Source));
1065 ASSERT ((UINTN) ((CHAR8 *) Source - Destination) > StrLen (Source));
1066
1067
1068 ReturnValue = Destination;
1069 while (*Source != '\0') {
1070 //
1071 // If any Unicode characters in Source contain
1072 // non-zero value in the upper 8 bits, then ASSERT().
1073 //
1074 ASSERT (*Source < 0x100);
1075 *(Destination++) = (CHAR8) *(Source++);
1076 }
1077
1078 *Destination = '\0';
1079
1080 //
1081 // ASSERT Original Destination is less long than PcdMaximumAsciiStringLength.
1082 // Length tests are performed inside AsciiStrLen().
1083 //
1084 ASSERT (AsciiStrSize (ReturnValue) != 0);
1085
1086 return ReturnValue;
1087 }
1088
1089
1090 /**
1091 Copies one Null-terminated ASCII string to another Null-terminated ASCII
1092 string and returns the new ASCII string.
1093
1094 This function copies the contents of the ASCII string Source to the ASCII
1095 string Destination, and returns Destination. If Source and Destination
1096 overlap, then the results are undefined.
1097
1098 If Destination is NULL, then ASSERT().
1099 If Source is NULL, then ASSERT().
1100 If Source and Destination overlap, then ASSERT().
1101 If PcdMaximumAsciiStringLength is not zero and Source contains more than
1102 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1103 then ASSERT().
1104
1105 @param Destination A pointer to a Null-terminated ASCII string.
1106 @param Source A pointer to a Null-terminated ASCII string.
1107
1108 @return Destination
1109
1110 **/
1111 CHAR8 *
1112 EFIAPI
1113 AsciiStrCpy (
1114 OUT CHAR8 *Destination,
1115 IN CONST CHAR8 *Source
1116 )
1117 {
1118 CHAR8 *ReturnValue;
1119
1120 //
1121 // Destination cannot be NULL
1122 //
1123 ASSERT (Destination != NULL);
1124
1125 //
1126 // Destination and source cannot overlap
1127 //
1128 ASSERT ((UINTN)(Destination - Source) > AsciiStrLen (Source));
1129 ASSERT ((UINTN)(Source - Destination) > AsciiStrLen (Source));
1130
1131 ReturnValue = Destination;
1132 while (*Source != 0) {
1133 *(Destination++) = *(Source++);
1134 }
1135 *Destination = 0;
1136 return ReturnValue;
1137 }
1138
1139 /**
1140 Copies up to a specified length one Null-terminated ASCII string to another
1141 Null-terminated ASCII string and returns the new ASCII string.
1142
1143 This function copies the contents of the ASCII string Source to the ASCII
1144 string Destination, and returns Destination. At most, Length ASCII characters
1145 are copied from Source to Destination. If Length is 0, then Destination is
1146 returned unmodified. If Length is greater that the number of ASCII characters
1147 in Source, then Destination is padded with Null ASCII characters. If Source
1148 and Destination overlap, then the results are undefined.
1149
1150 If Destination is NULL, then ASSERT().
1151 If Source is NULL, then ASSERT().
1152 If Source and Destination overlap, then ASSERT().
1153 If PcdMaximumAsciiStringLength is not zero, and Length is greater than
1154 PcdMaximumAsciiStringLength, then ASSERT().
1155 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1156 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1157 then ASSERT().
1158
1159 @param Destination A pointer to a Null-terminated ASCII string.
1160 @param Source A pointer to a Null-terminated ASCII string.
1161 @param Length The maximum number of ASCII characters to copy.
1162
1163 @return Destination
1164
1165 **/
1166 CHAR8 *
1167 EFIAPI
1168 AsciiStrnCpy (
1169 OUT CHAR8 *Destination,
1170 IN CONST CHAR8 *Source,
1171 IN UINTN Length
1172 )
1173 {
1174 CHAR8 *ReturnValue;
1175
1176 if (Length == 0) {
1177 return Destination;
1178 }
1179
1180 //
1181 // Destination cannot be NULL
1182 //
1183 ASSERT (Destination != NULL);
1184
1185 //
1186 // Destination and source cannot overlap
1187 //
1188 ASSERT ((UINTN)(Destination - Source) > AsciiStrLen (Source));
1189 ASSERT ((UINTN)(Source - Destination) >= Length);
1190
1191 if (PcdGet32 (PcdMaximumAsciiStringLength) != 0) {
1192 ASSERT (Length <= PcdGet32 (PcdMaximumAsciiStringLength));
1193 }
1194
1195 ReturnValue = Destination;
1196
1197 while (*Source != 0 && Length > 0) {
1198 *(Destination++) = *(Source++);
1199 Length--;
1200 }
1201
1202 ZeroMem (Destination, Length * sizeof (*Destination));
1203 return ReturnValue;
1204 }
1205
1206 /**
1207 Returns the length of a Null-terminated ASCII string.
1208
1209 This function returns the number of ASCII characters in the Null-terminated
1210 ASCII string specified by String.
1211
1212 If Length > 0 and Destination is NULL, then ASSERT().
1213 If Length > 0 and Source is NULL, then ASSERT().
1214 If PcdMaximumAsciiStringLength is not zero and String contains more than
1215 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1216 then ASSERT().
1217
1218 @param String A pointer to a Null-terminated ASCII string.
1219
1220 @return The length of String.
1221
1222 **/
1223 UINTN
1224 EFIAPI
1225 AsciiStrLen (
1226 IN CONST CHAR8 *String
1227 )
1228 {
1229 UINTN Length;
1230
1231 ASSERT (String != NULL);
1232
1233 for (Length = 0; *String != '\0'; String++, Length++) {
1234 //
1235 // If PcdMaximumUnicodeStringLength is not zero,
1236 // length should not more than PcdMaximumUnicodeStringLength
1237 //
1238 if (PcdGet32 (PcdMaximumAsciiStringLength) != 0) {
1239 ASSERT (Length < PcdGet32 (PcdMaximumAsciiStringLength));
1240 }
1241 }
1242 return Length;
1243 }
1244
1245 /**
1246 Returns the size of a Null-terminated ASCII string in bytes, including the
1247 Null terminator.
1248
1249 This function returns the size, in bytes, of the Null-terminated ASCII string
1250 specified by String.
1251
1252 If String is NULL, then ASSERT().
1253 If PcdMaximumAsciiStringLength is not zero and String contains more than
1254 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1255 then ASSERT().
1256
1257 @param String A pointer to a Null-terminated ASCII string.
1258
1259 @return The size of String.
1260
1261 **/
1262 UINTN
1263 EFIAPI
1264 AsciiStrSize (
1265 IN CONST CHAR8 *String
1266 )
1267 {
1268 return (AsciiStrLen (String) + 1) * sizeof (*String);
1269 }
1270
1271 /**
1272 Compares two Null-terminated ASCII strings, and returns the difference
1273 between the first mismatched ASCII characters.
1274
1275 This function compares the Null-terminated ASCII string FirstString to the
1276 Null-terminated ASCII string SecondString. If FirstString is identical to
1277 SecondString, then 0 is returned. Otherwise, the value returned is the first
1278 mismatched ASCII character in SecondString subtracted from the first
1279 mismatched ASCII character in FirstString.
1280
1281 If FirstString is NULL, then ASSERT().
1282 If SecondString is NULL, then ASSERT().
1283 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
1284 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1285 then ASSERT().
1286 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
1287 than PcdMaximumAsciiStringLength ASCII characters, not including the
1288 Null-terminator, then ASSERT().
1289
1290 @param FirstString A pointer to a Null-terminated ASCII string.
1291 @param SecondString A pointer to a Null-terminated ASCII string.
1292
1293 @retval ==0 FirstString is identical to SecondString.
1294 @retval !=0 FirstString is not identical to SecondString.
1295
1296 **/
1297 INTN
1298 EFIAPI
1299 AsciiStrCmp (
1300 IN CONST CHAR8 *FirstString,
1301 IN CONST CHAR8 *SecondString
1302 )
1303 {
1304 //
1305 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
1306 //
1307 ASSERT (AsciiStrSize (FirstString));
1308 ASSERT (AsciiStrSize (SecondString));
1309
1310 while ((*FirstString != '\0') && (*FirstString == *SecondString)) {
1311 FirstString++;
1312 SecondString++;
1313 }
1314
1315 return *FirstString - *SecondString;
1316 }
1317
1318 /**
1319 Converts a lowercase Ascii character to upper one.
1320
1321 If Chr is lowercase Ascii character, then converts it to upper one.
1322
1323 If Value >= 0xA0, then ASSERT().
1324 If (Value & 0x0F) >= 0x0A, then ASSERT().
1325
1326 @param Chr one Ascii character
1327
1328 @return The uppercase value of Ascii character
1329
1330 **/
1331 CHAR8
1332 EFIAPI
1333 InternalBaseLibAsciiToUpper (
1334 IN CHAR8 Chr
1335 )
1336 {
1337 return (UINT8) ((Chr >= 'a' && Chr <= 'z') ? Chr - ('a' - 'A') : Chr);
1338 }
1339
1340 /**
1341 Convert a ASCII character to numerical value.
1342
1343 This internal function only deal with Unicode character
1344 which maps to a valid hexadecimal ASII character, i.e.
1345 '0' to '9', 'a' to 'f' or 'A' to 'F'. For other
1346 ASCII character, the value returned does not make sense.
1347
1348 @param Char The character to convert.
1349
1350 @return The numerical value converted.
1351
1352 **/
1353 UINTN
1354 EFIAPI
1355 InternalAsciiHexCharToUintn (
1356 IN CHAR8 Char
1357 )
1358 {
1359 if (InternalIsDecimalDigitCharacter (Char)) {
1360 return Char - '0';
1361 }
1362
1363 return (UINTN) (10 + InternalBaseLibAsciiToUpper (Char) - 'A');
1364 }
1365
1366
1367 /**
1368 Performs a case insensitive comparison of two Null-terminated ASCII strings,
1369 and returns the difference between the first mismatched ASCII characters.
1370
1371 This function performs a case insensitive comparison of the Null-terminated
1372 ASCII string FirstString to the Null-terminated ASCII string SecondString. If
1373 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
1374 value returned is the first mismatched lower case ASCII character in
1375 SecondString subtracted from the first mismatched lower case ASCII character
1376 in FirstString.
1377
1378 If FirstString is NULL, then ASSERT().
1379 If SecondString is NULL, then ASSERT().
1380 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
1381 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1382 then ASSERT().
1383 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
1384 than PcdMaximumAsciiStringLength ASCII characters, not including the
1385 Null-terminator, then ASSERT().
1386
1387 @param FirstString A pointer to a Null-terminated ASCII string.
1388 @param SecondString A pointer to a Null-terminated ASCII string.
1389
1390 @retval ==0 FirstString is identical to SecondString using case insensitive
1391 comparisons.
1392 @retval !=0 FirstString is not identical to SecondString using case
1393 insensitive comparisons.
1394
1395 **/
1396 INTN
1397 EFIAPI
1398 AsciiStriCmp (
1399 IN CONST CHAR8 *FirstString,
1400 IN CONST CHAR8 *SecondString
1401 )
1402 {
1403 CHAR8 UpperFirstString;
1404 CHAR8 UpperSecondString;
1405
1406 //
1407 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
1408 //
1409 ASSERT (AsciiStrSize (FirstString));
1410 ASSERT (AsciiStrSize (SecondString));
1411
1412 UpperFirstString = InternalBaseLibAsciiToUpper (*FirstString);
1413 UpperSecondString = InternalBaseLibAsciiToUpper (*SecondString);
1414 while ((*FirstString != '\0') && (UpperFirstString == UpperSecondString)) {
1415 FirstString++;
1416 SecondString++;
1417 UpperFirstString = InternalBaseLibAsciiToUpper (*FirstString);
1418 UpperSecondString = InternalBaseLibAsciiToUpper (*SecondString);
1419 }
1420
1421 return UpperFirstString - UpperSecondString;
1422 }
1423
1424 /**
1425 Compares two Null-terminated ASCII strings with maximum lengths, and returns
1426 the difference between the first mismatched ASCII characters.
1427
1428 This function compares the Null-terminated ASCII string FirstString to the
1429 Null-terminated ASCII string SecondString. At most, Length ASCII characters
1430 will be compared. If Length is 0, then 0 is returned. If FirstString is
1431 identical to SecondString, then 0 is returned. Otherwise, the value returned
1432 is the first mismatched ASCII character in SecondString subtracted from the
1433 first mismatched ASCII character in FirstString.
1434
1435 If Length > 0 and FirstString is NULL, then ASSERT().
1436 If Length > 0 and SecondString is NULL, then ASSERT().
1437 If PcdMaximumAsciiStringLength is not zero, and Length is greater than
1438 PcdMaximumAsciiStringLength, then ASSERT().
1439 If PcdMaximumAsciiStringLength is not zero, and FirstString contains more than
1440 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1441 then ASSERT().
1442 If PcdMaximumAsciiStringLength is not zero, and SecondString contains more than
1443 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1444 then ASSERT().
1445
1446 @param FirstString A pointer to a Null-terminated ASCII string.
1447 @param SecondString A pointer to a Null-terminated ASCII string.
1448 @param Length The maximum number of ASCII characters for compare.
1449
1450 @retval ==0 FirstString is identical to SecondString.
1451 @retval !=0 FirstString is not identical to SecondString.
1452
1453 **/
1454 INTN
1455 EFIAPI
1456 AsciiStrnCmp (
1457 IN CONST CHAR8 *FirstString,
1458 IN CONST CHAR8 *SecondString,
1459 IN UINTN Length
1460 )
1461 {
1462 if (Length == 0) {
1463 return 0;
1464 }
1465
1466 //
1467 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
1468 //
1469 ASSERT (AsciiStrSize (FirstString));
1470 ASSERT (AsciiStrSize (SecondString));
1471
1472 if (PcdGet32 (PcdMaximumAsciiStringLength) != 0) {
1473 ASSERT (Length <= PcdGet32 (PcdMaximumAsciiStringLength));
1474 }
1475
1476 while ((*FirstString != '\0') &&
1477 (*FirstString == *SecondString) &&
1478 (Length > 1)) {
1479 FirstString++;
1480 SecondString++;
1481 Length--;
1482 }
1483 return *FirstString - *SecondString;
1484 }
1485
1486 /**
1487 Concatenates one Null-terminated ASCII string to another Null-terminated
1488 ASCII string, and returns the concatenated ASCII string.
1489
1490 This function concatenates two Null-terminated ASCII strings. The contents of
1491 Null-terminated ASCII string Source are concatenated to the end of Null-
1492 terminated ASCII string Destination. The Null-terminated concatenated ASCII
1493 String is returned.
1494
1495 If Destination is NULL, then ASSERT().
1496 If Source is NULL, then ASSERT().
1497 If PcdMaximumAsciiStringLength is not zero and Destination contains more than
1498 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1499 then ASSERT().
1500 If PcdMaximumAsciiStringLength is not zero and Source contains more than
1501 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1502 then ASSERT().
1503 If PcdMaximumAsciiStringLength is not zero and concatenating Destination and
1504 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
1505 ASCII characters, then ASSERT().
1506
1507 @param Destination A pointer to a Null-terminated ASCII string.
1508 @param Source A pointer to a Null-terminated ASCII string.
1509
1510 @return Destination
1511
1512 **/
1513 CHAR8 *
1514 EFIAPI
1515 AsciiStrCat (
1516 IN OUT CHAR8 *Destination,
1517 IN CONST CHAR8 *Source
1518 )
1519 {
1520 AsciiStrCpy (Destination + AsciiStrLen (Destination), Source);
1521
1522 //
1523 // Size of the resulting string should never be zero.
1524 // PcdMaximumUnicodeStringLength is tested inside StrLen().
1525 //
1526 ASSERT (AsciiStrSize (Destination) != 0);
1527 return Destination;
1528 }
1529
1530 /**
1531 Concatenates up to a specified length one Null-terminated ASCII string to
1532 the end of another Null-terminated ASCII string, and returns the
1533 concatenated ASCII string.
1534
1535 This function concatenates two Null-terminated ASCII strings. The contents
1536 of Null-terminated ASCII string Source are concatenated to the end of Null-
1537 terminated ASCII string Destination, and Destination is returned. At most,
1538 Length ASCII characters are concatenated from Source to the end of
1539 Destination, and Destination is always Null-terminated. If Length is 0, then
1540 Destination is returned unmodified. If Source and Destination overlap, then
1541 the results are undefined.
1542
1543 If Length > 0 and Destination is NULL, then ASSERT().
1544 If Length > 0 and Source is NULL, then ASSERT().
1545 If Source and Destination overlap, then ASSERT().
1546 If PcdMaximumAsciiStringLength is not zero, and Length is greater than
1547 PcdMaximumAsciiStringLength, then ASSERT().
1548 If PcdMaximumAsciiStringLength is not zero, and Destination contains more than
1549 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1550 then ASSERT().
1551 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1552 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1553 then ASSERT().
1554 If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and
1555 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
1556 ASCII characters, not including the Null-terminator, then ASSERT().
1557
1558 @param Destination A pointer to a Null-terminated ASCII string.
1559 @param Source A pointer to a Null-terminated ASCII string.
1560 @param Length The maximum number of ASCII characters to concatenate from
1561 Source.
1562
1563 @return Destination
1564
1565 **/
1566 CHAR8 *
1567 EFIAPI
1568 AsciiStrnCat (
1569 IN OUT CHAR8 *Destination,
1570 IN CONST CHAR8 *Source,
1571 IN UINTN Length
1572 )
1573 {
1574 UINTN DestinationLen;
1575
1576 DestinationLen = AsciiStrLen (Destination);
1577 AsciiStrnCpy (Destination + DestinationLen, Source, Length);
1578 Destination[DestinationLen + Length] = '\0';
1579
1580 //
1581 // Size of the resulting string should never be zero.
1582 // PcdMaximumUnicodeStringLength is tested inside StrLen().
1583 //
1584 ASSERT (AsciiStrSize (Destination) != 0);
1585 return Destination;
1586 }
1587
1588 /**
1589 Returns the first occurrence of a Null-terminated ASCII sub-string
1590 in a Null-terminated ASCII string.
1591
1592 This function scans the contents of the ASCII string specified by String
1593 and returns the first occurrence of SearchString. If SearchString is not
1594 found in String, then NULL is returned. If the length of SearchString is zero,
1595 then String is returned.
1596
1597 If String is NULL, then ASSERT().
1598 If SearchString is NULL, then ASSERT().
1599
1600 If PcdMaximumAsciiStringLength is not zero, and SearchString or
1601 String contains more than PcdMaximumAsciiStringLength Unicode characters
1602 not including the Null-terminator, then ASSERT().
1603
1604 @param String A pointer to a Null-terminated ASCII string.
1605 @param SearchString A pointer to a Null-terminated ASCII string to search for.
1606
1607 @retval NULL If the SearchString does not appear in String.
1608 @retval others If there is a match return the first occurrence of SearchingString.
1609 If the length of SearchString is zero,return String.
1610
1611 **/
1612 CHAR8 *
1613 EFIAPI
1614 AsciiStrStr (
1615 IN CONST CHAR8 *String,
1616 IN CONST CHAR8 *SearchString
1617 )
1618 {
1619 CONST CHAR8 *FirstMatch;
1620 CONST CHAR8 *SearchStringTmp;
1621
1622 //
1623 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
1624 //
1625 ASSERT (AsciiStrSize (String) != 0);
1626 ASSERT (AsciiStrSize (SearchString) != 0);
1627
1628 if (*SearchString == '\0') {
1629 return (CHAR8 *) String;
1630 }
1631
1632 while (*String != '\0') {
1633 SearchStringTmp = SearchString;
1634 FirstMatch = String;
1635
1636 while ((*String == *SearchStringTmp)
1637 && (*String != '\0')) {
1638 String++;
1639 SearchStringTmp++;
1640 }
1641
1642 if (*SearchStringTmp == '\0') {
1643 return (CHAR8 *) FirstMatch;
1644 }
1645
1646 if (*String == '\0') {
1647 return NULL;
1648 }
1649
1650 String = FirstMatch + 1;
1651 }
1652
1653 return NULL;
1654 }
1655
1656 /**
1657 Convert a Null-terminated ASCII decimal string to a value of type
1658 UINTN.
1659
1660 This function returns a value of type UINTN by interpreting the contents
1661 of the ASCII string String as a decimal number. The format of the input
1662 ASCII string String is:
1663
1664 [spaces] [decimal digits].
1665
1666 The valid decimal digit character is in the range [0-9]. The function will
1667 ignore the pad space, which includes spaces or tab characters, before the digits.
1668 The running zero in the beginning of [decimal digits] will be ignored. Then, the
1669 function stops at the first character that is a not a valid decimal character or
1670 Null-terminator, whichever on comes first.
1671
1672 If String has only pad spaces, then 0 is returned.
1673 If String has no pad spaces or valid decimal digits, then 0 is returned.
1674 If the number represented by String overflows according to the range defined by
1675 UINTN, then ASSERT().
1676 If String is NULL, then ASSERT().
1677 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1678 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1679 then ASSERT().
1680
1681 @param String A pointer to a Null-terminated ASCII string.
1682
1683 @retval Value translated from String.
1684
1685 **/
1686 UINTN
1687 EFIAPI
1688 AsciiStrDecimalToUintn (
1689 IN CONST CHAR8 *String
1690 )
1691 {
1692 UINTN Result;
1693
1694 //
1695 // ASSERT Strings is less long than PcdMaximumAsciiStringLength
1696 //
1697 ASSERT (AsciiStrSize (String) != 0);
1698
1699 //
1700 // Ignore the pad spaces (space or tab)
1701 //
1702 while ((*String == ' ') || (*String == '\t' )) {
1703 String++;
1704 }
1705
1706 //
1707 // Ignore leading Zeros after the spaces
1708 //
1709 while (*String == '0') {
1710 String++;
1711 }
1712
1713 Result = 0;
1714
1715 while (InternalAsciiIsDecimalDigitCharacter (*String)) {
1716 //
1717 // If the number represented by String overflows according
1718 // to the range defined by UINTN, then ASSERT().
1719 //
1720 ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_10) ||
1721 ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_10) &&
1722 (*String - '0') <= REMAINDER_MAX_UINTN_DIVIDED_BY_10)
1723 );
1724
1725 Result = Result * 10 + (*String - '0');
1726 String++;
1727 }
1728
1729 return Result;
1730 }
1731
1732
1733 /**
1734 Convert a Null-terminated ASCII decimal string to a value of type
1735 UINT64.
1736
1737 This function returns a value of type UINT64 by interpreting the contents
1738 of the ASCII string String as a decimal number. The format of the input
1739 ASCII string String is:
1740
1741 [spaces] [decimal digits].
1742
1743 The valid decimal digit character is in the range [0-9]. The function will
1744 ignore the pad space, which includes spaces or tab characters, before the digits.
1745 The running zero in the beginning of [decimal digits] will be ignored. Then, the
1746 function stops at the first character that is a not a valid decimal character or
1747 Null-terminator, whichever on comes first.
1748
1749 If String has only pad spaces, then 0 is returned.
1750 If String has no pad spaces or valid decimal digits, then 0 is returned.
1751 If the number represented by String overflows according to the range defined by
1752 UINT64, then ASSERT().
1753 If String is NULL, then ASSERT().
1754 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1755 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1756 then ASSERT().
1757
1758 @param String A pointer to a Null-terminated ASCII string.
1759
1760 @retval Value translated from String.
1761
1762 **/
1763 UINT64
1764 EFIAPI
1765 AsciiStrDecimalToUint64 (
1766 IN CONST CHAR8 *String
1767 )
1768 {
1769 UINT64 Result;
1770
1771 //
1772 // ASSERT Strings is less long than PcdMaximumAsciiStringLength
1773 //
1774 ASSERT (AsciiStrSize (String) != 0);
1775
1776 //
1777 // Ignore the pad spaces (space or tab)
1778 //
1779 while ((*String == ' ') || (*String == '\t' )) {
1780 String++;
1781 }
1782
1783 //
1784 // Ignore leading Zeros after the spaces
1785 //
1786 while (*String == '0') {
1787 String++;
1788 }
1789
1790 Result = 0;
1791
1792 while (InternalAsciiIsDecimalDigitCharacter (*String)) {
1793 //
1794 // If the number represented by String overflows according
1795 // to the range defined by UINTN, then ASSERT().
1796 //
1797 ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_10) ||
1798 ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_10) &&
1799 (*String - '0') <= REMAINDER_MAX_UINT64_DIVIDED_BY_10)
1800 );
1801
1802 Result = MultU64x32 (Result, 10) + (*String - '0');
1803 String++;
1804 }
1805
1806 return Result;
1807 }
1808
1809 /**
1810 Convert a Null-terminated ASCII hexadecimal string to a value of type UINTN.
1811
1812 This function returns a value of type UINTN by interpreting the contents of
1813 the ASCII string String as a hexadecimal number. The format of the input ASCII
1814 string String is:
1815
1816 [spaces][zeros][x][hexadecimal digits].
1817
1818 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1819 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1820 appears in the input string, it must be prefixed with at least one 0. The function
1821 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1822 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1823 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1824 digit. Then, the function stops at the first character that is a not a valid
1825 hexadecimal character or Null-terminator, whichever on comes first.
1826
1827 If String has only pad spaces, then 0 is returned.
1828 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1829 0 is returned.
1830
1831 If the number represented by String overflows according to the range defined by UINTN,
1832 then ASSERT().
1833 If String is NULL, then ASSERT().
1834 If PcdMaximumAsciiStringLength is not zero,
1835 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1836 the Null-terminator, then ASSERT().
1837
1838 @param String A pointer to a Null-terminated ASCII string.
1839
1840 @retval Value translated from String.
1841
1842 **/
1843 UINTN
1844 EFIAPI
1845 AsciiStrHexToUintn (
1846 IN CONST CHAR8 *String
1847 )
1848 {
1849 UINTN Result;
1850
1851 //
1852 // ASSERT Strings is less long than PcdMaximumAsciiStringLength
1853 //
1854 ASSERT (AsciiStrSize (String) != 0);
1855
1856 //
1857 // Ignore the pad spaces (space or tab)
1858 //
1859 while ((*String == ' ') || (*String == '\t' )) {
1860 String++;
1861 }
1862
1863 //
1864 // Ignore leading Zeros after the spaces
1865 //
1866 while (*String == '0') {
1867 String++;
1868 }
1869
1870 if (InternalBaseLibAsciiToUpper (*String) == 'X') {
1871 ASSERT (*(String - 1) == '0');
1872 if (*(String - 1) != '0') {
1873 return 0;
1874 }
1875 //
1876 // Skip the 'X'
1877 //
1878 String++;
1879 }
1880
1881 Result = 0;
1882
1883 while (InternalAsciiIsHexaDecimalDigitCharacter (*String)) {
1884 //
1885 // If the Hex Number represented by String overflows according
1886 // to the range defined by UINTN, then ASSERT().
1887 //
1888 ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_16) ||
1889 ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_16) &&
1890 (InternalAsciiHexCharToUintn (*String) <= REMAINDER_MAX_UINTN_DIVIDED_BY_16))
1891 );
1892
1893 Result = (Result << 4) + InternalAsciiHexCharToUintn (*String);
1894 String++;
1895 }
1896
1897 return Result;
1898 }
1899
1900
1901 /**
1902 Convert a Null-terminated ASCII hexadecimal string to a value of type UINT64.
1903
1904 This function returns a value of type UINT64 by interpreting the contents of
1905 the ASCII string String as a hexadecimal number. The format of the input ASCII
1906 string String is:
1907
1908 [spaces][zeros][x][hexadecimal digits].
1909
1910 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1911 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1912 appears in the input string, it must be prefixed with at least one 0. The function
1913 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1914 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1915 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1916 digit. Then, the function stops at the first character that is a not a valid
1917 hexadecimal character or Null-terminator, whichever on comes first.
1918
1919 If String has only pad spaces, then 0 is returned.
1920 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1921 0 is returned.
1922
1923 If the number represented by String overflows according to the range defined by UINT64,
1924 then ASSERT().
1925 If String is NULL, then ASSERT().
1926 If PcdMaximumAsciiStringLength is not zero,
1927 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1928 the Null-terminator, then ASSERT().
1929
1930 @param String A pointer to a Null-terminated ASCII string.
1931
1932 @retval Value translated from String.
1933
1934 **/
1935 UINT64
1936 EFIAPI
1937 AsciiStrHexToUint64 (
1938 IN CONST CHAR8 *String
1939 )
1940 {
1941 UINT64 Result;
1942
1943 //
1944 // ASSERT Strings is less long than PcdMaximumAsciiStringLength
1945 //
1946 ASSERT (AsciiStrSize (String) != 0);
1947
1948 //
1949 // Ignore the pad spaces (space or tab) and leading Zeros
1950 //
1951 //
1952 // Ignore the pad spaces (space or tab)
1953 //
1954 while ((*String == ' ') || (*String == '\t' )) {
1955 String++;
1956 }
1957
1958 //
1959 // Ignore leading Zeros after the spaces
1960 //
1961 while (*String == '0') {
1962 String++;
1963 }
1964
1965 if (InternalBaseLibAsciiToUpper (*String) == 'X') {
1966 ASSERT (*(String - 1) == '0');
1967 if (*(String - 1) != '0') {
1968 return 0;
1969 }
1970 //
1971 // Skip the 'X'
1972 //
1973 String++;
1974 }
1975
1976 Result = 0;
1977
1978 while (InternalAsciiIsHexaDecimalDigitCharacter (*String)) {
1979 //
1980 // If the Hex Number represented by String overflows according
1981 // to the range defined by UINTN, then ASSERT().
1982 //
1983 ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_16) ||
1984 ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_16) &&
1985 (InternalAsciiHexCharToUintn (*String) <= REMAINDER_MAX_UINT64_DIVIDED_BY_16))
1986 );
1987
1988 Result = LShiftU64 (Result, 4);
1989 Result = Result + InternalAsciiHexCharToUintn (*String);
1990 String++;
1991 }
1992
1993 return Result;
1994 }
1995
1996
1997 /**
1998 Convert one Null-terminated ASCII string to a Null-terminated
1999 Unicode string and returns the Unicode string.
2000
2001 This function converts the contents of the ASCII string Source to the Unicode
2002 string Destination, and returns Destination. The function terminates the
2003 Unicode string Destination by appending a Null-terminator character at the end.
2004 The caller is responsible to make sure Destination points to a buffer with size
2005 equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.
2006
2007 If Destination is NULL, then ASSERT().
2008 If Destination is not aligned on a 16-bit boundary, then ASSERT().
2009 If Source is NULL, then ASSERT().
2010 If Source and Destination overlap, then ASSERT().
2011 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
2012 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
2013 then ASSERT().
2014 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
2015 PcdMaximumUnicodeStringLength ASCII characters not including the
2016 Null-terminator, then ASSERT().
2017
2018 @param Source A pointer to a Null-terminated ASCII string.
2019 @param Destination A pointer to a Null-terminated Unicode string.
2020
2021 @return Destination.
2022
2023 **/
2024 CHAR16 *
2025 EFIAPI
2026 AsciiStrToUnicodeStr (
2027 IN CONST CHAR8 *Source,
2028 OUT CHAR16 *Destination
2029 )
2030 {
2031 CHAR16 *ReturnValue;
2032
2033 ASSERT (Destination != NULL);
2034
2035 //
2036 // ASSERT Source is less long than PcdMaximumAsciiStringLength
2037 //
2038 ASSERT (AsciiStrSize (Source) != 0);
2039
2040 //
2041 // Source and Destination should not overlap
2042 //
2043 ASSERT ((UINTN) ((CHAR8 *) Destination - Source) > AsciiStrLen (Source));
2044 ASSERT ((UINTN) (Source - (CHAR8 *) Destination) > (AsciiStrLen (Source) * sizeof (CHAR16)));
2045
2046
2047 ReturnValue = Destination;
2048 while (*Source != '\0') {
2049 *(Destination++) = (CHAR16) *(Source++);
2050 }
2051 //
2052 // End the Destination with a NULL.
2053 //
2054 *Destination = '\0';
2055
2056 //
2057 // ASSERT Original Destination is less long than PcdMaximumUnicodeStringLength
2058 //
2059 ASSERT (StrSize (ReturnValue) != 0);
2060
2061 return ReturnValue;
2062 }
2063
2064 /**
2065 Converts an 8-bit value to an 8-bit BCD value.
2066
2067 Converts the 8-bit value specified by Value to BCD. The BCD value is
2068 returned.
2069
2070 If Value >= 100, then ASSERT().
2071
2072 @param Value The 8-bit value to convert to BCD. Range 0..99.
2073
2074 @return The BCD value.
2075
2076 **/
2077 UINT8
2078 EFIAPI
2079 DecimalToBcd8 (
2080 IN UINT8 Value
2081 )
2082 {
2083 ASSERT (Value < 100);
2084 return (UINT8) (((Value / 10) << 4) | (Value % 10));
2085 }
2086
2087 /**
2088 Converts an 8-bit BCD value to an 8-bit value.
2089
2090 Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit
2091 value is returned.
2092
2093 If Value >= 0xA0, then ASSERT().
2094 If (Value & 0x0F) >= 0x0A, then ASSERT().
2095
2096 @param Value The 8-bit BCD value to convert to an 8-bit value.
2097
2098 @return The 8-bit value is returned.
2099
2100 **/
2101 UINT8
2102 EFIAPI
2103 BcdToDecimal8 (
2104 IN UINT8 Value
2105 )
2106 {
2107 ASSERT (Value < 0xa0);
2108 ASSERT ((Value & 0xf) < 0xa);
2109 return (UINT8) ((Value >> 4) * 10 + (Value & 0xf));
2110 }