2 Unicode string primatives.
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
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.
19 #include <UefiBaseTypes.h>
22 #include <CommonLib.h>
23 #define _gPcd_FixedAtBuild_PcdMaximumUnicodeStringLength 0
24 #define _gPcd_FixedAtBuild_PcdMaximumAsciiStringLength 0
27 Copies one Null-terminated Unicode string to another Null-terminated Unicode
28 string and returns the new Unicode string.
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.
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().
40 @param Destination Pointer to a Null-terminated Unicode string.
41 @param Source Pointer to a Null-terminated Unicode string.
49 OUT CHAR16
*Destination
,
50 IN CONST CHAR16
*Source
56 // Destination cannot be NULL
58 ASSERT (Destination
!= NULL
);
61 // Destination and source cannot overlap
63 ASSERT ((UINTN
)(Destination
- Source
) > StrLen (Source
));
64 ASSERT ((UINTN
)(Source
- Destination
) > StrLen (Source
));
66 ReturnValue
= Destination
;
68 *(Destination
++) = *(Source
++);
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
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
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().
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.
103 OUT CHAR16
*Destination
,
104 IN CONST CHAR16
*Source
,
115 // Destination cannot be NULL if Length is not zero
117 ASSERT (Destination
!= NULL
);
120 // Destination and source cannot overlap
121 // Q: Does Source have to be NULL-terminated?
123 ASSERT ((UINTN
)(Destination
- Source
) > StrLen (Source
));
124 ASSERT ((UINTN
)(Source
- Destination
) >= Length
);
126 ReturnValue
= Destination
;
128 while ((*Source
!= L
'\0') && (Length
> 0)) {
129 *(Destination
++) = *(Source
++);
133 // ZeroMem (Destination, Length * sizeof (*Destination));
134 memset (Destination
, 0, Length
* sizeof (*Destination
));
139 Returns the length of a Null-terminated Unicode string.
141 This function returns the number of Unicode characters in the Null-terminated
142 Unicode string specified by String.
144 If String is NULL, then ASSERT().
145 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
146 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
148 @param String Pointer to a Null-terminated Unicode string.
150 @return The length of String.
156 IN CONST CHAR16
*String
161 ASSERT (String
!= NULL
);
163 for (Length
= 0; *String
!= L
'\0'; String
++, Length
++) {
165 // If PcdMaximumUnicodeStringLength is not zero,
166 // length should not more than PcdMaximumUnicodeStringLength
168 if (FixedPcdGet32 (PcdMaximumUnicodeStringLength
) != 0) {
169 ASSERT (Length
< FixedPcdGet32 (PcdMaximumUnicodeStringLength
));
176 Returns the size of a Null-terminated Unicode string in bytes, including the
179 This function returns the size, in bytes, of the Null-terminated Unicode
180 string specified by String.
182 If String is NULL, then ASSERT().
183 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
184 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
186 @param String Pointer to a Null-terminated Unicode string.
188 @return The size of String.
194 IN CONST CHAR16
*String
197 return (StrLen (String
) + 1) * sizeof (*String
);
201 Compares two Null-terminated Unicode strings, and returns the difference
202 between the first mismatched Unicode characters.
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.
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().
217 @param FirstString Pointer to a Null-terminated Unicode string.
218 @param SecondString Pointer to a Null-terminated Unicode string.
220 @retval 0 FirstString is identical to SecondString.
221 @retval !=0 FirstString is not identical to SecondString.
227 IN CONST CHAR16
*FirstString
,
228 IN CONST CHAR16
*SecondString
232 // ASSERT both strings are less long than PcdMaximumUnicodeStringLength
234 ASSERT (StrSize (FirstString
) != 0);
235 ASSERT (StrSize (SecondString
) != 0);
237 while ((*FirstString
!= L
'\0') && (*FirstString
== *SecondString
)) {
241 return *FirstString
- *SecondString
;
245 Compares two Null-terminated Unicode strings with maximum lengths, and
246 returns the difference between the first mismatched Unicode characters.
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.
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().
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.
266 @retval 0 FirstString is identical to SecondString.
267 @retval !=0 FirstString is not identical to SecondString.
273 IN CONST CHAR16
*FirstString
,
274 IN CONST CHAR16
*SecondString
,
283 // ASSERT both strings are less long than PcdMaximumUnicodeStringLength.
284 // Length tests are performed inside StrLen().
286 ASSERT (StrSize (FirstString
) != 0);
287 ASSERT (StrSize (SecondString
) != 0);
289 while ((*FirstString
!= L
'\0') &&
290 (*FirstString
== *SecondString
) &&
297 return *FirstString
- *SecondString
;
301 Concatenates one Null-terminated Unicode string to another Null-terminated
302 Unicode string, and returns the concatenated Unicode string.
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.
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().
321 @param Destination Pointer to a Null-terminated Unicode string.
322 @param Source Pointer to a Null-terminated Unicode string.
330 IN OUT CHAR16
*Destination
,
331 IN CONST CHAR16
*Source
334 StrCpy (Destination
+ StrLen (Destination
), Source
);
337 // Size of the resulting string should never be zero.
338 // PcdMaximumUnicodeStringLength is tested inside StrLen().
340 ASSERT (StrSize (Destination
) != 0);
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
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.
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().
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
379 IN OUT CHAR16
*Destination
,
380 IN CONST CHAR16
*Source
,
384 StrnCpy (Destination
+ StrLen (Destination
), Source
, Length
);
387 // Size of the resulting string should never be zero.
388 // PcdMaximumUnicodeStringLength is tested inside StrLen().
390 ASSERT (StrSize (Destination
) != 0);
395 Copies one Null-terminated ASCII string to another Null-terminated ASCII
396 string and returns the new ASCII string.
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.
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().
408 @param Destination Pointer to a Null-terminated ASCII string.
409 @param Source Pointer to a Null-terminated ASCII string.
417 OUT CHAR8
*Destination
,
418 IN CONST CHAR8
*Source
424 // Destination cannot be NULL
426 ASSERT (Destination
!= NULL
);
429 // Destination and source cannot overlap
431 ASSERT ((UINTN
)(Destination
- Source
) > AsciiStrLen (Source
));
432 ASSERT ((UINTN
)(Source
- Destination
) > AsciiStrLen (Source
));
434 ReturnValue
= Destination
;
436 *(Destination
++) = *(Source
++);
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
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.
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().
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.
470 OUT CHAR8
*Destination
,
471 IN CONST CHAR8
*Source
,
482 // Destination cannot be NULL
484 ASSERT (Destination
!= NULL
);
487 // Destination and source cannot overlap
489 ASSERT ((UINTN
)(Destination
- Source
) > AsciiStrLen (Source
));
490 ASSERT ((UINTN
)(Source
- Destination
) >= Length
);
492 ReturnValue
= Destination
;
494 while (*Source
&& Length
> 0) {
495 *(Destination
++) = *(Source
++);
499 // ZeroMem (Destination, Length * sizeof (*Destination));
500 memset (Destination
, 0, Length
* sizeof (*Destination
));
505 Returns the length of a Null-terminated ASCII string.
507 This function returns the number of ASCII characters in the Null-terminated
508 ASCII string specified by String.
510 If String is NULL, then ASSERT().
511 If PcdMaximumAsciiStringLength is not zero and String contains more than
512 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
514 @param String Pointer to a Null-terminated ASCII string.
516 @return The length of String.
522 IN CONST CHAR8
*String
527 ASSERT (String
!= NULL
);
529 for (Length
= 0; *String
!= '\0'; String
++, Length
++) {
531 // If PcdMaximumUnicodeStringLength is not zero,
532 // length should not more than PcdMaximumUnicodeStringLength
534 if (FixedPcdGet32 (PcdMaximumAsciiStringLength
) != 0) {
535 ASSERT (Length
< FixedPcdGet32 (PcdMaximumAsciiStringLength
));
542 Returns the size of a Null-terminated ASCII string in bytes, including the
545 This function returns the size, in bytes, of the Null-terminated ASCII string
548 If String is NULL, then ASSERT().
549 If PcdMaximumAsciiStringLength is not zero and String contains more than
550 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
552 @param String Pointer to a Null-terminated ASCII string.
554 @return The size of String.
560 IN CONST CHAR8
*String
563 return (AsciiStrLen (String
) + 1) * sizeof (*String
);
567 Compares two Null-terminated ASCII strings, and returns the difference
568 between the first mismatched ASCII characters.
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.
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().
583 @param FirstString Pointer to a Null-terminated ASCII string.
584 @param SecondString Pointer to a Null-terminated ASCII string.
586 @retval 0 FirstString is identical to SecondString.
587 @retval !=0 FirstString is not identical to SecondString.
593 IN CONST CHAR8
*FirstString
,
594 IN CONST CHAR8
*SecondString
598 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
600 ASSERT (AsciiStrSize (FirstString
));
601 ASSERT (AsciiStrSize (SecondString
));
603 while ((*FirstString
!= '\0') && (*FirstString
== *SecondString
)) {
608 return *FirstString
- *SecondString
;
618 return (Chr
>= 'a' && Chr
<= 'z') ? Chr
- ('a' - 'A') : Chr
;
622 Performs a case insensitive comparison of two Null-terminated ASCII strings,
623 and returns the difference between the first mismatched ASCII characters.
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
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().
639 @param FirstString Pointer to a Null-terminated ASCII string.
640 @param SecondString Pointer to a Null-terminated ASCII string.
642 @retval 0 FirstString is identical to SecondString using case insensitive
644 @retval !=0 FirstString is not identical to SecondString using case
645 insensitive comparisons.
651 IN CONST CHAR8
*FirstString
,
652 IN CONST CHAR8
*SecondString
656 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
658 ASSERT (AsciiStrSize (FirstString
));
659 ASSERT (AsciiStrSize (SecondString
));
661 while ((*FirstString
!= '\0') &&
662 (AsciiToUpper (*FirstString
) == AsciiToUpper (*SecondString
))) {
667 return AsciiToUpper (*FirstString
) - AsciiToUpper (*SecondString
);
671 Compares two Null-terminated ASCII strings with maximum lengths, and returns
672 the difference between the first mismatched ASCII characters.
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.
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().
688 @param FirstString Pointer to a Null-terminated ASCII string.
689 @param SecondString Pointer to a Null-terminated ASCII string.
691 @retval 0 FirstString is identical to SecondString.
692 @retval !=0 FirstString is not identical to SecondString.
698 IN CONST CHAR8
*FirstString
,
699 IN CONST CHAR8
*SecondString
,
704 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
706 ASSERT (AsciiStrSize (FirstString
));
707 ASSERT (AsciiStrSize (SecondString
));
709 while ((*FirstString
!= '\0') &&
710 (*FirstString
== *SecondString
) &&
716 return *FirstString
- *SecondString
;
720 Concatenates one Null-terminated ASCII string to another Null-terminated
721 ASCII string, and returns the concatenated ASCII string.
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
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().
738 @param Destination Pointer to a Null-terminated ASCII string.
739 @param Source Pointer to a Null-terminated ASCII string.
747 IN OUT CHAR8
*Destination
,
748 IN CONST CHAR8
*Source
751 AsciiStrCpy (Destination
+ AsciiStrLen (Destination
), Source
);
754 // Size of the resulting string should never be zero.
755 // PcdMaximumUnicodeStringLength is tested inside StrLen().
757 ASSERT (AsciiStrSize (Destination
) != 0);
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
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.
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().
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
796 IN OUT CHAR8
*Destination
,
797 IN CONST CHAR8
*Source
,
801 AsciiStrnCpy (Destination
+ AsciiStrLen (Destination
), Source
, Length
);
804 // Size of the resulting string should never be zero.
805 // PcdMaximumUnicodeStringLength is tested inside StrLen().
807 ASSERT (AsciiStrSize (Destination
) != 0);