Remove DiskIoPartition and old Emu, adjust MonoStatusCode in EdkNt32Pkg
[mirror_edk2.git] / MdePkg / Library / BaseLib / String.c
1 /** @file
2 Unicode string primatives.
3
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. 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 Module Name: String.c
14
15 **/
16
17 /**
18 Copies one Null-terminated Unicode string to another Null-terminated Unicode
19 string and returns the new Unicode string.
20
21 This function copies the contents of the Unicode string Source to the Unicode
22 string Destination, and returns Destination. If Source and Destination
23 overlap, then the results are undefined.
24
25 If Destination is NULL, then ASSERT().
26 If Source is NULL, then ASSERT().
27 If Source and Destination overlap, then ASSERT().
28 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
29 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
30
31 @param Destination Pointer to a Null-terminated Unicode string.
32 @param Source Pointer to a Null-terminated Unicode string.
33
34 @return Destiantion
35
36 **/
37 CHAR16 *
38 EFIAPI
39 StrCpy (
40 OUT CHAR16 *Destination,
41 IN CONST CHAR16 *Source
42 )
43 {
44 CHAR16 *ReturnValue;
45
46 //
47 // Destination cannot be NULL
48 //
49 ASSERT (Destination != NULL);
50
51 //
52 // Destination and source cannot overlap
53 //
54 ASSERT ((UINTN)(Destination - Source) > StrLen (Source));
55 ASSERT ((UINTN)(Source - Destination) > StrLen (Source));
56
57 ReturnValue = Destination;
58 while (*Source) {
59 *(Destination++) = *(Source++);
60 }
61 *Destination = 0;
62 return ReturnValue;
63 }
64
65 /**
66 Copies one Null-terminated Unicode string with a maximum length to another
67 Null-terminated Unicode string with a maximum length and returns the new
68 Unicode string.
69
70 This function copies the contents of the Unicode string Source to the Unicode
71 string Destination, and returns Destination. At most, Length Unicode
72 characters are copied from Source to Destination. If Length is 0, then
73 Destination is returned unmodified. If Length is greater that the number of
74 Unicode characters in Source, then Destination is padded with Null Unicode
75 characters. If Source and Destination overlap, then the results are
76 undefined.
77
78 If Destination is NULL, then ASSERT().
79 If Source is NULL, then ASSERT().
80 If Source and Destination overlap, then ASSERT().
81 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
82 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
83
84 @param Destination Pointer to a Null-terminated Unicode string.
85 @param Source Pointer to a Null-terminated Unicode string.
86 @param Length Maximum number of Unicode characters to copy.
87
88 @return Destination
89
90 **/
91 CHAR16 *
92 EFIAPI
93 StrnCpy (
94 OUT CHAR16 *Destination,
95 IN CONST CHAR16 *Source,
96 IN UINTN Length
97 )
98 {
99 CHAR16 *ReturnValue;
100
101 if (Length == 0) {
102 return Destination;
103 }
104
105 //
106 // Destination cannot be NULL if Length is not zero
107 //
108 ASSERT (Destination != NULL);
109
110 //
111 // Destination and source cannot overlap
112 // Q: Does Source have to be NULL-terminated?
113 //
114 ASSERT ((UINTN)(Destination - Source) > StrLen (Source));
115 ASSERT ((UINTN)(Source - Destination) >= Length);
116
117 ReturnValue = Destination;
118
119 while ((*Source != L'\0') && (Length > 0)) {
120 *(Destination++) = *(Source++);
121 Length--;
122 }
123
124 ZeroMem (Destination, Length * sizeof (*Destination));
125 return ReturnValue;
126 }
127
128 /**
129 Returns the length of a Null-terminated Unicode string.
130
131 This function returns the number of Unicode characters in the Null-terminated
132 Unicode string specified by String.
133
134 If String is NULL, then ASSERT().
135 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
136 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
137
138 @param String Pointer to a Null-terminated Unicode string.
139
140 @return The length of String.
141
142 **/
143 UINTN
144 EFIAPI
145 StrLen (
146 IN CONST CHAR16 *String
147 )
148 {
149 UINTN Length;
150
151 ASSERT (String != NULL);
152
153 for (Length = 0; *String != L'\0'; String++, Length++) {
154 //
155 // If PcdMaximumUnicodeStringLength is not zero,
156 // length should not more than PcdMaximumUnicodeStringLength
157 //
158 if (PcdGet32 (PcdMaximumUnicodeStringLength) != 0) {
159 ASSERT (Length < PcdGet32 (PcdMaximumUnicodeStringLength));
160 }
161 }
162 return Length;
163 }
164
165 /**
166 Returns the size of a Null-terminated Unicode string in bytes, including the
167 Null terminator.
168
169 This function returns the size, in bytes, of the Null-terminated Unicode
170 string specified by String.
171
172 If String is NULL, then ASSERT().
173 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
174 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
175
176 @param String Pointer to a Null-terminated Unicode string.
177
178 @return The size of String.
179
180 **/
181 UINTN
182 EFIAPI
183 StrSize (
184 IN CONST CHAR16 *String
185 )
186 {
187 return (StrLen (String) + 1) * sizeof (*String);
188 }
189
190 /**
191 Compares two Null-terminated Unicode strings, and returns the difference
192 between the first mismatched Unicode characters.
193
194 This function compares the Null-terminated Unicode string FirstString to the
195 Null-terminated Unicode string SecondString. If FirstString is identical to
196 SecondString, then 0 is returned. Otherwise, the value returned is the first
197 mismatched Unicode character in SecondString subtracted from the first
198 mismatched Unicode character in FirstString.
199
200 If FirstString is NULL, then ASSERT().
201 If SecondString is NULL, then ASSERT().
202 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
203 than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
204 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
205 than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
206
207 @param FirstString Pointer to a Null-terminated Unicode string.
208 @param SecondString Pointer to a Null-terminated Unicode string.
209
210 @retval 0 FirstString is identical to SecondString.
211 @retval !=0 FirstString is not identical to SecondString.
212
213 **/
214 INTN
215 EFIAPI
216 StrCmp (
217 IN CONST CHAR16 *FirstString,
218 IN CONST CHAR16 *SecondString
219 )
220 {
221 //
222 // ASSERT both strings are less long than PcdMaximumUnicodeStringLength
223 //
224 ASSERT (StrSize (FirstString) != 0);
225 ASSERT (StrSize (SecondString) != 0);
226
227 while ((*FirstString != L'\0') && (*FirstString == *SecondString)) {
228 FirstString++;
229 SecondString++;
230 }
231 return *FirstString - *SecondString;
232 }
233
234 /**
235 Compares two Null-terminated Unicode strings with maximum lengths, and
236 returns the difference between the first mismatched Unicode characters.
237
238 This function compares the Null-terminated Unicode string FirstString to the
239 Null-terminated Unicode string SecondString. At most, Length Unicode
240 characters will be compared. If Length is 0, then 0 is returned. If
241 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
242 value returned is the first mismatched Unicode character in SecondString
243 subtracted from the first mismatched Unicode character in FirstString.
244
245 If FirstString is NULL, then ASSERT().
246 If SecondString is NULL, then ASSERT().
247 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
248 than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
249 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
250 than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
251
252 @param FirstString Pointer to a Null-terminated Unicode string.
253 @param SecondString Pointer to a Null-terminated Unicode string.
254 @param Length Maximum number of Unicode characters to compare.
255
256 @retval 0 FirstString is identical to SecondString.
257 @retval !=0 FirstString is not identical to SecondString.
258
259 **/
260 INTN
261 EFIAPI
262 StrnCmp (
263 IN CONST CHAR16 *FirstString,
264 IN CONST CHAR16 *SecondString,
265 IN UINTN Length
266 )
267 {
268 if (Length == 0) {
269 return 0;
270 }
271
272 //
273 // ASSERT both strings are less long than PcdMaximumUnicodeStringLength.
274 // Length tests are performed inside StrLen().
275 //
276 ASSERT (StrSize (FirstString) != 0);
277 ASSERT (StrSize (SecondString) != 0);
278
279 while ((*FirstString != L'\0') &&
280 (*FirstString == *SecondString) &&
281 (Length > 1)) {
282 FirstString++;
283 SecondString++;
284 Length--;
285 }
286
287 return *FirstString - *SecondString;
288 }
289
290 /**
291 Concatenates one Null-terminated Unicode string to another Null-terminated
292 Unicode string, and returns the concatenated Unicode string.
293
294 This function concatenates two Null-terminated Unicode strings. The contents
295 of Null-terminated Unicode string Source are concatenated to the end of
296 Null-terminated Unicode string Destination. The Null-terminated concatenated
297 Unicode String is returned. If Source and Destination overlap, then the
298 results are undefined.
299
300 If Destination is NULL, then ASSERT().
301 If Source is NULL, then ASSERT().
302 If Source and Destination overlap, then ASSERT().
303 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
304 than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
305 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
306 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
307 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
308 and Source results in a Unicode string with more than
309 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
310
311 @param Destination Pointer to a Null-terminated Unicode string.
312 @param Source Pointer to a Null-terminated Unicode string.
313
314 @return Destination
315
316 **/
317 CHAR16 *
318 EFIAPI
319 StrCat (
320 IN OUT CHAR16 *Destination,
321 IN CONST CHAR16 *Source
322 )
323 {
324 StrCpy (Destination + StrLen (Destination), Source);
325
326 //
327 // Size of the resulting string should never be zero.
328 // PcdMaximumUnicodeStringLength is tested inside StrLen().
329 //
330 ASSERT (StrSize (Destination) != 0);
331 return Destination;
332 }
333
334 /**
335 Concatenates one Null-terminated Unicode string with a maximum length to the
336 end of another Null-terminated Unicode string, and returns the concatenated
337 Unicode string.
338
339 This function concatenates two Null-terminated Unicode strings. The contents
340 of Null-terminated Unicode string Source are concatenated to the end of
341 Null-terminated Unicode string Destination, and Destination is returned. At
342 most, Length Unicode characters are concatenated from Source to the end of
343 Destination, and Destination is always Null-terminated. If Length is 0, then
344 Destination is returned unmodified. If Source and Destination overlap, then
345 the results are undefined.
346
347 If Destination is NULL, then ASSERT().
348 If Source is NULL, then ASSERT().
349 If Source and Destination overlap, then ASSERT().
350 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
351 than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
352 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
353 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
354 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
355 and Source results in a Unicode string with more than
356 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
357
358 @param Destination Pointer to a Null-terminated Unicode string.
359 @param Source Pointer to a Null-terminated Unicode string.
360 @param Length Maximum number of Unicode characters to concatenate from
361 Source.
362
363 @return Destination
364
365 **/
366 CHAR16 *
367 EFIAPI
368 StrnCat (
369 IN OUT CHAR16 *Destination,
370 IN CONST CHAR16 *Source,
371 IN UINTN Length
372 )
373 {
374 StrnCpy (Destination + StrLen (Destination), Source, Length);
375
376 //
377 // Size of the resulting string should never be zero.
378 // PcdMaximumUnicodeStringLength is tested inside StrLen().
379 //
380 ASSERT (StrSize (Destination) != 0);
381 return Destination;
382 }
383
384 /**
385 Copies one Null-terminated ASCII string to another Null-terminated ASCII
386 string and returns the new ASCII string.
387
388 This function copies the contents of the ASCII string Source to the ASCII
389 string Destination, and returns Destination. If Source and Destination
390 overlap, then the results are undefined.
391
392 If Destination is NULL, then ASSERT().
393 If Source is NULL, then ASSERT().
394 If Source and Destination overlap, then ASSERT().
395 If PcdMaximumAsciiStringLength is not zero and Source contains more than
396 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
397
398 @param Destination Pointer to a Null-terminated ASCII string.
399 @param Source Pointer to a Null-terminated ASCII string.
400
401 @return Destination
402
403 **/
404 CHAR8 *
405 EFIAPI
406 AsciiStrCpy (
407 OUT CHAR8 *Destination,
408 IN CONST CHAR8 *Source
409 )
410 {
411 CHAR8 *ReturnValue;
412
413 //
414 // Destination cannot be NULL
415 //
416 ASSERT (Destination != NULL);
417
418 //
419 // Destination and source cannot overlap
420 //
421 ASSERT ((UINTN)(Destination - Source) > AsciiStrLen (Source));
422 ASSERT ((UINTN)(Source - Destination) > AsciiStrLen (Source));
423
424 ReturnValue = Destination;
425 while (*Source) {
426 *(Destination++) = *(Source++);
427 }
428 *Destination = 0;
429 return ReturnValue;
430 }
431
432 /**
433 Copies one Null-terminated ASCII string with a maximum length to another
434 Null-terminated ASCII string with a maximum length and returns the new ASCII
435 string.
436
437 This function copies the contents of the ASCII string Source to the ASCII
438 string Destination, and returns Destination. At most, Length ASCII characters
439 are copied from Source to Destination. If Length is 0, then Destination is
440 returned unmodified. If Length is greater that the number of ASCII characters
441 in Source, then Destination is padded with Null ASCII characters. If Source
442 and Destination overlap, then the results are undefined.
443
444 If Destination is NULL, then ASSERT().
445 If Source is NULL, then ASSERT().
446 If Source and Destination overlap, then ASSERT().
447 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
448 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
449
450 @param Destination Pointer to a Null-terminated ASCII string.
451 @param Source Pointer to a Null-terminated ASCII string.
452 @param Length Maximum number of ASCII characters to copy.
453
454 @return Destination
455
456 **/
457 CHAR8 *
458 EFIAPI
459 AsciiStrnCpy (
460 OUT CHAR8 *Destination,
461 IN CONST CHAR8 *Source,
462 IN UINTN Length
463 )
464 {
465 CHAR8 *ReturnValue;
466
467 if (Length == 0) {
468 return Destination;
469 }
470
471 //
472 // Destination cannot be NULL
473 //
474 ASSERT (Destination != NULL);
475
476 //
477 // Destination and source cannot overlap
478 //
479 ASSERT ((UINTN)(Destination - Source) > AsciiStrLen (Source));
480 ASSERT ((UINTN)(Source - Destination) >= Length);
481
482 ReturnValue = Destination;
483
484 while (*Source && Length > 0) {
485 *(Destination++) = *(Source++);
486 Length--;
487 }
488
489 ZeroMem (Destination, Length * sizeof (*Destination));
490 return ReturnValue;
491 }
492
493 /**
494 Returns the length of a Null-terminated ASCII string.
495
496 This function returns the number of ASCII characters in the Null-terminated
497 ASCII string specified by String.
498
499 If String is NULL, then ASSERT().
500 If PcdMaximumAsciiStringLength is not zero and String contains more than
501 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
502
503 @param String Pointer to a Null-terminated ASCII string.
504
505 @return The length of String.
506
507 **/
508 UINTN
509 EFIAPI
510 AsciiStrLen (
511 IN CONST CHAR8 *String
512 )
513 {
514 UINTN Length;
515
516 ASSERT (String != NULL);
517
518 for (Length = 0; *String != '\0'; String++, Length++) {
519 //
520 // If PcdMaximumUnicodeStringLength is not zero,
521 // length should not more than PcdMaximumUnicodeStringLength
522 //
523 if (PcdGet32 (PcdMaximumAsciiStringLength) != 0) {
524 ASSERT (Length < PcdGet32 (PcdMaximumAsciiStringLength));
525 }
526 }
527 return Length;
528 }
529
530 /**
531 Returns the size of a Null-terminated ASCII string in bytes, including the
532 Null terminator.
533
534 This function returns the size, in bytes, of the Null-terminated ASCII string
535 specified by String.
536
537 If String is NULL, then ASSERT().
538 If PcdMaximumAsciiStringLength is not zero and String contains more than
539 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
540
541 @param String Pointer to a Null-terminated ASCII string.
542
543 @return The size of String.
544
545 **/
546 UINTN
547 EFIAPI
548 AsciiStrSize (
549 IN CONST CHAR8 *String
550 )
551 {
552 return (AsciiStrLen (String) + 1) * sizeof (*String);
553 }
554
555 /**
556 Compares two Null-terminated ASCII strings, and returns the difference
557 between the first mismatched ASCII characters.
558
559 This function compares the Null-terminated ASCII string FirstString to the
560 Null-terminated ASCII string SecondString. If FirstString is identical to
561 SecondString, then 0 is returned. Otherwise, the value returned is the first
562 mismatched ASCII character in SecondString subtracted from the first
563 mismatched ASCII character in FirstString.
564
565 If FirstString is NULL, then ASSERT().
566 If SecondString is NULL, then ASSERT().
567 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
568 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
569 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
570 than PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
571
572 @param FirstString Pointer to a Null-terminated ASCII string.
573 @param SecondString Pointer to a Null-terminated ASCII string.
574
575 @retval 0 FirstString is identical to SecondString.
576 @retval !=0 FirstString is not identical to SecondString.
577
578 **/
579 INTN
580 EFIAPI
581 AsciiStrCmp (
582 IN CONST CHAR8 *FirstString,
583 IN CONST CHAR8 *SecondString
584 )
585 {
586 //
587 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
588 //
589 ASSERT (AsciiStrSize (FirstString));
590 ASSERT (AsciiStrSize (SecondString));
591
592 while ((*FirstString != '\0') && (*FirstString == *SecondString)) {
593 FirstString++;
594 SecondString++;
595 }
596
597 return *FirstString - *SecondString;
598 }
599
600 STATIC
601 CHAR8
602 EFIAPI
603 AsciiToUpper (
604 IN CHAR8 Chr
605 )
606 {
607 return (Chr >= 'a' && Chr <= 'z') ? Chr - ('a' - 'A') : Chr;
608 }
609
610 /**
611 Performs a case insensitive comparison of two Null-terminated ASCII strings,
612 and returns the difference between the first mismatched ASCII characters.
613
614 This function performs a case insensitive comparison of the Null-terminated
615 ASCII string FirstString to the Null-terminated ASCII string SecondString. If
616 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
617 value returned is the first mismatched lower case ASCII character in
618 SecondString subtracted from the first mismatched lower case ASCII character
619 in FirstString.
620
621 If FirstString is NULL, then ASSERT().
622 If SecondString is NULL, then ASSERT().
623 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
624 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
625 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
626 than PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
627
628 @param FirstString Pointer to a Null-terminated ASCII string.
629 @param SecondString Pointer to a Null-terminated ASCII string.
630
631 @retval 0 FirstString is identical to SecondString using case insensitive
632 comparisons.
633 @retval !=0 FirstString is not identical to SecondString using case
634 insensitive comparisons.
635
636 **/
637 INTN
638 EFIAPI
639 AsciiStriCmp (
640 IN CONST CHAR8 *FirstString,
641 IN CONST CHAR8 *SecondString
642 )
643 {
644 //
645 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
646 //
647 ASSERT (AsciiStrSize (FirstString));
648 ASSERT (AsciiStrSize (SecondString));
649
650 while ((*FirstString != '\0') &&
651 (AsciiToUpper (*FirstString) == AsciiToUpper (*SecondString))) {
652 FirstString++;
653 SecondString++;
654 }
655
656 return AsciiToUpper (*FirstString) - AsciiToUpper (*SecondString);
657 }
658
659 /**
660 Compares two Null-terminated ASCII strings with maximum lengths, and returns
661 the difference between the first mismatched ASCII characters.
662
663 This function compares the Null-terminated ASCII string FirstString to the
664 Null-terminated ASCII string SecondString. At most, Length ASCII characters
665 will be compared. If Length is 0, then 0 is returned. If FirstString is
666 identical to SecondString, then 0 is returned. Otherwise, the value returned
667 is the first mismatched ASCII character in SecondString subtracted from the
668 first mismatched ASCII character in FirstString.
669
670 If FirstString is NULL, then ASSERT().
671 If SecondString is NULL, then ASSERT().
672 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
673 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
674 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
675 than PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
676
677 @param FirstString Pointer to a Null-terminated ASCII string.
678 @param SecondString Pointer to a Null-terminated ASCII string.
679
680 @retval 0 FirstString is identical to SecondString.
681 @retval !=0 FirstString is not identical to SecondString.
682
683 **/
684 INTN
685 EFIAPI
686 AsciiStrnCmp (
687 IN CONST CHAR8 *FirstString,
688 IN CONST CHAR8 *SecondString,
689 IN UINTN Length
690 )
691 {
692 //
693 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
694 //
695 ASSERT (AsciiStrSize (FirstString));
696 ASSERT (AsciiStrSize (SecondString));
697
698 while ((*FirstString != '\0') &&
699 (*FirstString == *SecondString) &&
700 (Length > 1)) {
701 FirstString++;
702 SecondString++;
703 Length--;
704 }
705 return *FirstString - *SecondString;
706 }
707
708 /**
709 Concatenates one Null-terminated ASCII string to another Null-terminated
710 ASCII string, and returns the concatenated ASCII string.
711
712 This function concatenates two Null-terminated ASCII strings. The contents of
713 Null-terminated ASCII string Source are concatenated to the end of Null-
714 terminated ASCII string Destination. The Null-terminated concatenated ASCII
715 String is returned.
716
717 If Destination is NULL, then ASSERT().
718 If Source is NULL, then ASSERT().
719 If PcdMaximumAsciiStringLength is not zero and Destination contains more than
720 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
721 If PcdMaximumAsciiStringLength is not zero and Source contains more than
722 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
723 If PcdMaximumAsciiStringLength is not zero and concatenating Destination and
724 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
725 ASCII characters, then ASSERT().
726
727 @param Destination Pointer to a Null-terminated ASCII string.
728 @param Source Pointer to a Null-terminated ASCII string.
729
730 @return Destination
731
732 **/
733 CHAR8 *
734 EFIAPI
735 AsciiStrCat (
736 IN OUT CHAR8 *Destination,
737 IN CONST CHAR8 *Source
738 )
739 {
740 AsciiStrCpy (Destination + AsciiStrLen (Destination), Source);
741
742 //
743 // Size of the resulting string should never be zero.
744 // PcdMaximumUnicodeStringLength is tested inside StrLen().
745 //
746 ASSERT (AsciiStrSize (Destination) != 0);
747 return Destination;
748 }
749
750 /**
751 Concatenates one Null-terminated ASCII string with a maximum length to the
752 end of another Null-terminated ASCII string, and returns the concatenated
753 ASCII string.
754
755 This function concatenates two Null-terminated ASCII strings. The contents
756 of Null-terminated ASCII string Source are concatenated to the end of Null-
757 terminated ASCII string Destination, and Destination is returned. At most,
758 Length ASCII characters are concatenated from Source to the end of
759 Destination, and Destination is always Null-terminated. If Length is 0, then
760 Destination is returned unmodified. If Source and Destination overlap, then
761 the results are undefined.
762
763 If Destination is NULL, then ASSERT().
764 If Source is NULL, then ASSERT().
765 If Source and Destination overlap, then ASSERT().
766 If PcdMaximumAsciiStringLength is not zero, and Destination contains more
767 than PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
768 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
769 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
770 If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and
771 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
772 ASCII characters, then ASSERT().
773
774 @param Destination Pointer to a Null-terminated ASCII string.
775 @param Source Pointer to a Null-terminated ASCII string.
776 @param Length Maximum number of ASCII characters to concatenate from
777 Source.
778
779 @return Destination
780
781 **/
782 CHAR8 *
783 EFIAPI
784 AsciiStrnCat (
785 IN OUT CHAR8 *Destination,
786 IN CONST CHAR8 *Source,
787 IN UINTN Length
788 )
789 {
790 AsciiStrnCpy (Destination + AsciiStrLen (Destination), Source, Length);
791
792 //
793 // Size of the resulting string should never be zero.
794 // PcdMaximumUnicodeStringLength is tested inside StrLen().
795 //
796 ASSERT (AsciiStrSize (Destination) != 0);
797 return Destination;
798 }
799
800 /**
801 Converts an 8-bit value to an 8-bit BCD value.
802
803 Converts the 8-bit value specified by Value to BCD. The BCD value is
804 returned.
805
806 If Value >= 100, then ASSERT().
807
808 @param Value The 8-bit value to convert to BCD. Range 0..99.
809
810 @return The BCD value
811
812 **/
813 UINT8
814 EFIAPI
815 DecimalToBcd8 (
816 IN UINT8 Value
817 )
818 {
819 ASSERT (Value < 100);
820 return ((Value / 10) << 4) | (Value % 10);
821 }
822
823 /**
824 Converts an 8-bit BCD value to an 8-bit value.
825
826 Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit
827 value is returned.
828
829 If Value >= 0xA0, then ASSERT().
830 If (Value & 0x0F) >= 0x0A, then ASSERT().
831
832 @param Value The 8-bit BCD value to convert to an 8-bit value.
833
834 @return The 8-bit value is returned.
835
836 **/
837 UINT8
838 EFIAPI
839 BcdToDecimal8 (
840 IN UINT8 Value
841 )
842 {
843 ASSERT (Value < 0xa0);
844 ASSERT ((Value & 0xf) < 0xa);
845 return (Value >> 4) * 10 + (Value & 0xf);
846 }