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