3 Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Unicode string primatives.
23 #include "BaseLibInternals.h"
26 Copies one Null-terminated Unicode string to another Null-terminated Unicode
27 string and returns the new Unicode string.
29 This function copies the contents of the Unicode string Source to the Unicode
30 string Destination, and returns Destination. If Source and Destination
31 overlap, then the results are undefined.
33 If Destination is NULL, then ASSERT().
34 If Destination is not aligned on a 16-bit boundary, then ASSERT().
35 If Source is NULL, then ASSERT().
36 If Source is not aligned on a 16-bit boundary, then ASSERT().
37 If Source and Destination overlap, then ASSERT().
38 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
39 PcdMaximumUnicodeStringLength Unicode characters not including the
40 Null-terminator, then ASSERT().
42 @param Destination Pointer to a Null-terminated Unicode string.
43 @param Source Pointer to a Null-terminated Unicode string.
51 OUT CHAR16
*Destination
,
52 IN CONST CHAR16
*Source
58 // Destination cannot be NULL
60 ASSERT (Destination
!= NULL
);
61 ASSERT (((UINTN
) Destination
& 0x01) == 0);
64 // Destination and source cannot overlap
66 ASSERT ((UINTN
)(Destination
- Source
) > StrLen (Source
));
67 ASSERT ((UINTN
)(Source
- Destination
) > StrLen (Source
));
69 ReturnValue
= Destination
;
71 *(Destination
++) = *(Source
++);
78 Copies one Null-terminated Unicode string with a maximum length to another
79 Null-terminated Unicode string with a maximum length and returns the new
82 This function copies the contents of the Unicode string Source to the Unicode
83 string Destination, and returns Destination. At most, Length Unicode
84 characters are copied from Source to Destination. If Length is 0, then
85 Destination is returned unmodified. If Length is greater that the number of
86 Unicode characters in Source, then Destination is padded with Null Unicode
87 characters. If Source and Destination overlap, then the results are
90 If Length > 0 and Destination is NULL, then ASSERT().
91 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
92 If Length > 0 and Source is NULL, then ASSERT().
93 If Length > 0 and Source is not aligned on a 16-bit bounadry, then ASSERT().
94 If Source and Destination overlap, then ASSERT().
95 If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
96 PcdMaximumUnicodeStringLength, then ASSERT().
97 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
98 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
101 @param Destination Pointer to a Null-terminated Unicode string.
102 @param Source Pointer to a Null-terminated Unicode string.
103 @param Length Maximum number of Unicode characters to copy.
111 OUT CHAR16
*Destination
,
112 IN CONST CHAR16
*Source
,
123 // Destination cannot be NULL if Length is not zero
125 ASSERT (Destination
!= NULL
);
126 ASSERT (((UINTN
) Destination
& 0x01) == 0);
129 // Destination and source cannot overlap
130 // Q: Does Source have to be NULL-terminated?
132 ASSERT ((UINTN
)(Destination
- Source
) > StrLen (Source
));
133 ASSERT ((UINTN
)(Source
- Destination
) >= Length
);
135 ReturnValue
= Destination
;
137 while ((*Source
!= L
'\0') && (Length
> 0)) {
138 *(Destination
++) = *(Source
++);
142 ZeroMem (Destination
, Length
* sizeof (*Destination
));
147 Returns the length of a Null-terminated Unicode string.
149 This function returns the number of Unicode characters in the Null-terminated
150 Unicode string specified by String.
152 If String is NULL, then ASSERT().
153 If String is not aligned on a 16-bit boundary, then ASSERT().
154 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
155 PcdMaximumUnicodeStringLength Unicode characters not including the
156 Null-terminator, then ASSERT().
158 @param String Pointer to a Null-terminated Unicode string.
160 @return The length of String.
166 IN CONST CHAR16
*String
171 ASSERT (String
!= NULL
);
172 ASSERT (((UINTN
) String
& 0x01) == 0);
174 for (Length
= 0; *String
!= L
'\0'; String
++, Length
++) {
176 // If PcdMaximumUnicodeStringLength is not zero,
177 // length should not more than PcdMaximumUnicodeStringLength
179 if (PcdGet32 (PcdMaximumUnicodeStringLength
) != 0) {
180 ASSERT (Length
< PcdGet32 (PcdMaximumUnicodeStringLength
));
187 Returns the size of a Null-terminated Unicode string in bytes, including the
190 This function returns the size, in bytes, of the Null-terminated Unicode
191 string specified by String.
193 If String is NULL, then ASSERT().
194 If String is not aligned on a 16-bit boundary, then ASSERT().
195 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
196 PcdMaximumUnicodeStringLength Unicode characters not including the
197 Null-terminator, then ASSERT().
199 @param String Pointer to a Null-terminated Unicode string.
201 @return The size of String.
207 IN CONST CHAR16
*String
210 return (StrLen (String
) + 1) * sizeof (*String
);
214 Compares two Null-terminated Unicode strings, and returns the difference
215 between the first mismatched Unicode characters.
217 This function compares the Null-terminated Unicode string FirstString to the
218 Null-terminated Unicode string SecondString. If FirstString is identical to
219 SecondString, then 0 is returned. Otherwise, the value returned is the first
220 mismatched Unicode character in SecondString subtracted from the first
221 mismatched Unicode character in FirstString.
223 If FirstString is NULL, then ASSERT().
224 If FirstString is not aligned on a 16-bit boundary, then ASSERT().
225 If SecondString is NULL, then ASSERT().
226 If SecondString is not aligned on a 16-bit boundary, then ASSERT().
227 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
228 than PcdMaximumUnicodeStringLength Unicode characters not including the
229 Null-terminator, then ASSERT().
230 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
231 than PcdMaximumUnicodeStringLength Unicode characters not including the
232 Null-terminator, then ASSERT().
234 @param FirstString Pointer to a Null-terminated Unicode string.
235 @param SecondString Pointer to a Null-terminated Unicode string.
237 @retval 0 FirstString is identical to SecondString.
238 @retval !=0 FirstString is not identical to SecondString.
244 IN CONST CHAR16
*FirstString
,
245 IN CONST CHAR16
*SecondString
249 // ASSERT both strings are less long than PcdMaximumUnicodeStringLength
251 ASSERT (StrSize (FirstString
) != 0);
252 ASSERT (StrSize (SecondString
) != 0);
254 while ((*FirstString
!= L
'\0') && (*FirstString
== *SecondString
)) {
258 return *FirstString
- *SecondString
;
262 Compares two Null-terminated Unicode strings with maximum lengths, and
263 returns the difference between the first mismatched Unicode characters.
265 This function compares the Null-terminated Unicode string FirstString to the
266 Null-terminated Unicode string SecondString. At most, Length Unicode
267 characters will be compared. If Length is 0, then 0 is returned. If
268 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
269 value returned is the first mismatched Unicode character in SecondString
270 subtracted from the first mismatched Unicode character in FirstString.
272 If Length > 0 and FirstString is NULL, then ASSERT().
273 If Length > 0 and FirstString is not aligned on a 16-bit bounadary, then ASSERT().
274 If Length > 0 and SecondString is NULL, then ASSERT().
275 If Length > 0 and SecondString is not aligned on a 16-bit bounadary, then ASSERT().
276 If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
277 PcdMaximumUnicodeStringLength, then ASSERT().
278 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more than
279 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
281 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more than
282 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
285 @param FirstString Pointer to a Null-terminated Unicode string.
286 @param SecondString Pointer to a Null-terminated Unicode string.
287 @param Length Maximum number of Unicode characters to compare.
289 @retval 0 FirstString is identical to SecondString.
290 @retval !=0 FirstString is not identical to SecondString.
296 IN CONST CHAR16
*FirstString
,
297 IN CONST CHAR16
*SecondString
,
306 // ASSERT both strings are less long than PcdMaximumUnicodeStringLength.
307 // Length tests are performed inside StrLen().
309 ASSERT (StrSize (FirstString
) != 0);
310 ASSERT (StrSize (SecondString
) != 0);
312 while ((*FirstString
!= L
'\0') &&
313 (*FirstString
== *SecondString
) &&
320 return *FirstString
- *SecondString
;
324 Concatenates one Null-terminated Unicode string to another Null-terminated
325 Unicode string, and returns the concatenated Unicode string.
327 This function concatenates two Null-terminated Unicode strings. The contents
328 of Null-terminated Unicode string Source are concatenated to the end of
329 Null-terminated Unicode string Destination. The Null-terminated concatenated
330 Unicode String is returned. If Source and Destination overlap, then the
331 results are undefined.
333 If Destination is NULL, then ASSERT().
334 If Source is NULL, then ASSERT().
335 If Source and Destination overlap, then ASSERT().
336 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
337 than PcdMaximumUnicodeStringLength Unicode characters not including the
338 Null-terminator, then ASSERT().
339 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
340 PcdMaximumUnicodeStringLength Unicode characters not including the
341 Null-terminator, then ASSERT().
342 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
343 and Source results in a Unicode string with more than
344 PcdMaximumUnicodeStringLength Unicode characters not including the
345 Null-terminator, then ASSERT().
347 @param Destination Pointer to a Null-terminated Unicode string.
348 @param Source Pointer to a Null-terminated Unicode string.
356 IN OUT CHAR16
*Destination
,
357 IN CONST CHAR16
*Source
360 StrCpy (Destination
+ StrLen (Destination
), Source
);
363 // Size of the resulting string should never be zero.
364 // PcdMaximumUnicodeStringLength is tested inside StrLen().
366 ASSERT (StrSize (Destination
) != 0);
371 Concatenates one Null-terminated Unicode string with a maximum length to the
372 end of another Null-terminated Unicode string, and returns the concatenated
375 This function concatenates two Null-terminated Unicode strings. The contents
376 of Null-terminated Unicode string Source are concatenated to the end of
377 Null-terminated Unicode string Destination, and Destination is returned. At
378 most, Length Unicode characters are concatenated from Source to the end of
379 Destination, and Destination is always Null-terminated. If Length is 0, then
380 Destination is returned unmodified. If Source and Destination overlap, then
381 the results are undefined.
383 If Destination is NULL, then ASSERT().
384 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
385 If Length > 0 and Source is NULL, then ASSERT().
386 If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().
387 If Source and Destination overlap, then ASSERT().
388 If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
389 PcdMaximumUnicodeStringLength, then ASSERT().
390 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
391 than PcdMaximumUnicodeStringLength Unicode characters, not including the
392 Null-terminator, then ASSERT().
393 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
394 PcdMaximumUnicodeStringLength Unicode characters, not including the
395 Null-terminator, then ASSERT().
396 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
397 and Source results in a Unicode string with more than PcdMaximumUnicodeStringLength
398 Unicode characters, not including the Null-terminator, then ASSERT().
400 @param Destination Pointer to a Null-terminated Unicode string.
401 @param Source Pointer to a Null-terminated Unicode string.
402 @param Length Maximum number of Unicode characters to concatenate from
411 IN OUT CHAR16
*Destination
,
412 IN CONST CHAR16
*Source
,
416 StrnCpy (Destination
+ StrLen (Destination
), Source
, Length
);
419 // Size of the resulting string should never be zero.
420 // PcdMaximumUnicodeStringLength is tested inside StrLen().
422 ASSERT (StrSize (Destination
) != 0);
427 Returns the first occurance of a Null-terminated Unicode sub-string
428 in a Null-terminated Unicode string.
430 This function scans the contents of the Null-terminated Unicode string
431 specified by String and returns the first occurrence of SearchString.
432 If SearchString is not found in String, then NULL is returned. If
433 the length of SearchString is zero, then String is
436 If String is NULL, then ASSERT().
437 If String is not aligned on a 16-bit boundary, then ASSERT().
438 If SearchString is NULL, then ASSERT().
439 If SearchString is not aligned on a 16-bit boundary, then ASSERT().
441 If PcdMaximumUnicodeStringLength is not zero, and SearchString
442 or String contains more than PcdMaximumUnicodeStringLength Unicode
443 characters not including the Null-terminator, then ASSERT().
445 @param String Pointer to a Null-terminated Unicode string.
446 @param SearchString Pointer to a Null-terminated Unicode string to search for.
448 @retval NULL If the SearchString does not appear in String.
449 @retval !NULL If there is a match.
455 IN CONST CHAR16
*String
,
456 IN CONST CHAR16
*SearchString
459 CONST CHAR16
*FirstMatch
;
460 CONST CHAR16
*SearchStringTmp
;
462 ASSERT (String
!= NULL
);
463 ASSERT (((UINTN
) String
& 0x01) == 0);
464 ASSERT (SearchString
!= NULL
);
465 ASSERT (((UINTN
) SearchString
& 0x01) == 0);
468 // If PcdMaximumUnicodeStringLength is not zero,
469 // length of String should not more than PcdMaximumUnicodeStringLength
471 if (PcdGet32 (PcdMaximumUnicodeStringLength
) != 0) {
472 ASSERT (StrLen (String
) < PcdGet32 (PcdMaximumUnicodeStringLength
));
476 // If PcdMaximumUnicodeStringLength is not zero,
477 // length of SearchString should not more than PcdMaximumUnicodeStringLength
479 if (PcdGet32 (PcdMaximumUnicodeStringLength
) != 0) {
480 ASSERT (StrLen (SearchString
) < PcdGet32 (PcdMaximumAsciiStringLength
));
483 while (*String
!= '\0') {
484 SearchStringTmp
= SearchString
;
487 while ((*String
== *SearchStringTmp
)
488 && (*SearchStringTmp
!= '\0')
489 && (*String
!= '\0')) {
494 if (*SearchStringTmp
== '\0') {
495 return (CHAR16
*) FirstMatch
;
498 if (SearchStringTmp
== SearchString
) {
500 // If no character from SearchString match,
501 // move the pointer to the String under search
512 Check if a Unicode character is a decimal character.
514 This internal function checks if a Unicode character is a
515 decimal character. The valid decimal character is from
519 @param Char The character to check against.
521 @retval TRUE If the Char is a decmial character.
522 @retval FALSE Otherwise.
527 InternalIsDecimalDigitCharacter (
531 return (BOOLEAN
) (Char
>= L
'0' && Char
<= L
'9');
535 Convert a Unicode character to upper case only if
536 it maps to a valid small-case ASCII character.
538 This internal function only deal with Unicode character
539 which maps to a valid small-case ASII character, i.e.
540 L'a' to L'z'. For other Unicode character, the input character
541 is returned directly.
544 @param Char The character to convert.
546 @retval LowerCharacter If the Char is with range L'a' to L'z'.
547 @retval Unchanged Otherwise.
552 InternalCharToUpper (
556 if (Char
>= L
'a' && Char
<= L
'z') {
557 return (CHAR16
) (Char
- (L
'a' - L
'A'));
564 Convert a Unicode character to numerical value.
566 This internal function only deal with Unicode character
567 which maps to a valid hexadecimal ASII character, i.e.
568 L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other
569 Unicode character, the value returned does not make sense.
571 @param Char The character to convert.
573 @retval UINTN The numerical value converted.
578 InternalHexCharToUintn (
582 if (InternalIsDecimalDigitCharacter (Char
)) {
586 return (UINTN
) (10 + InternalCharToUpper (Char
) - L
'A');
590 Check if a Unicode character is a hexadecimal character.
592 This internal function checks if a Unicode character is a
593 decimal character. The valid hexadecimal character is
594 L'0' to L'9', L'a' to L'f', or L'A' to L'F'.
597 @param Char The character to check against.
599 @retval TRUE If the Char is a hexadecmial character.
600 @retval FALSE Otherwise.
605 InternalIsHexaDecimalDigitCharacter (
610 return (BOOLEAN
) (InternalIsDecimalDigitCharacter (Char
) ||
611 (Char
>= L
'A' && Char
<= L
'F') ||
612 (Char
>= L
'a' && Char
<= L
'f'));
616 Convert a Null-terminated Unicode decimal string to a value of
619 This function returns a value of type UINTN by interpreting the contents
620 of the Unicode string specified by String as a decimal number. The format
621 of the input Unicode string String is:
623 [spaces] [decimal digits].
625 The valid decimal digit character is in the range [0-9]. The
626 function will ignore the pad space, which includes spaces or
627 tab characters, before [decimal digits]. The running zero in the
628 beginning of [decimal digits] will be ignored. Then, the function
629 stops at the first character that is a not a valid decimal character
630 or a Null-terminator, whichever one comes first.
632 If String is NULL, then ASSERT().
633 If String is not aligned in a 16-bit boundary, then ASSERT().
634 If String has only pad spaces, then 0 is returned.
635 If String has no pad spaces or valid decimal digits,
637 If the number represented by String overflows according
638 to the range defined by UINTN, then ASSERT().
640 If PcdMaximumUnicodeStringLength is not zero, and String contains
641 more than PcdMaximumUnicodeStringLength Unicode characters not including
642 the Null-terminator, then ASSERT().
644 @param String Pointer to a Null-terminated Unicode string.
652 IN CONST CHAR16
*String
657 ASSERT (String
!= NULL
);
658 ASSERT (((UINTN
) String
& 0x01) == 0);
659 ASSERT (StrLen (String
) < PcdGet32 (PcdMaximumUnicodeStringLength
));
662 // Ignore the pad spaces (space or tab)
664 while ((*String
== L
' ') || (*String
== L
'\t')) {
669 // Ignore leading Zeros after the spaces
671 while (*String
== L
'0') {
677 while (InternalIsDecimalDigitCharacter (*String
)) {
679 // If the number represented by String overflows according
680 // to the range defined by UINTN, then ASSERT().
682 ASSERT ((Result
< QUIENT_MAX_UINTN_DIVIDED_BY_10
) ||
683 ((Result
== QUIENT_MAX_UINTN_DIVIDED_BY_10
) &&
684 (*String
- L
'0') <= REMINDER_MAX_UINTN_DIVIDED_BY_10
)
687 Result
= Result
* 10 + (*String
- L
'0');
696 Convert a Null-terminated Unicode decimal string to a value of
699 This function returns a value of type UINT64 by interpreting the contents
700 of the Unicode string specified by String as a decimal number. The format
701 of the input Unicode string String is:
703 [spaces] [decimal digits].
705 The valid decimal digit character is in the range [0-9]. The
706 function will ignore the pad space, which includes spaces or
707 tab characters, before [decimal digits]. The running zero in the
708 beginning of [decimal digits] will be ignored. Then, the function
709 stops at the first character that is a not a valid decimal character
710 or a Null-terminator, whichever one comes first.
712 If String is NULL, then ASSERT().
713 If String is not aligned in a 16-bit boundary, then ASSERT().
714 If String has only pad spaces, then 0 is returned.
715 If String has no pad spaces or valid decimal digits,
717 If the number represented by String overflows according
718 to the range defined by UINT64, then ASSERT().
720 If PcdMaximumUnicodeStringLength is not zero, and String contains
721 more than PcdMaximumUnicodeStringLength Unicode characters not including
722 the Null-terminator, then ASSERT().
724 @param String Pointer to a Null-terminated Unicode string.
732 IN CONST CHAR16
*String
737 ASSERT (String
!= NULL
);
738 ASSERT (((UINTN
) String
& 0x01) == 0);
739 ASSERT (StrLen (String
) < PcdGet32 (PcdMaximumUnicodeStringLength
));
742 // Ignore the pad spaces (space or tab)
744 while ((*String
== L
' ') || (*String
== L
'\t')) {
749 // Ignore leading Zeros after the spaces
751 while (*String
== L
'0') {
757 while (InternalIsDecimalDigitCharacter (*String
)) {
759 // If the number represented by String overflows according
760 // to the range defined by UINTN, then ASSERT().
762 ASSERT ((Result
< QUIENT_MAX_UINT64_DIVIDED_BY_10
) ||
763 ((Result
== QUIENT_MAX_UINT64_DIVIDED_BY_10
) &&
764 (*String
- L
'0') <= REMINDER_MAX_UINT64_DIVIDED_BY_10
)
767 Result
= MultU64x32 (Result
, 10) + (*String
- L
'0');
775 Convert a Null-terminated Unicode hexadecimal string to a value of type UINTN.
777 This function returns a value of type UINTN by interpreting the contents
778 of the Unicode string specified by String as a hexadecimal number.
779 The format of the input Unicode string String is:
781 [spaces][zeros][x][hexadecimal digits].
783 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
784 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
785 If "x" appears in the input string, it must be prefixed with at least one 0.
786 The function will ignore the pad space, which includes spaces or tab characters,
787 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
788 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
789 first valid hexadecimal digit. Then, the function stops at the first character that is
790 a not a valid hexadecimal character or NULL, whichever one comes first.
792 If String is NULL, then ASSERT().
793 If String is not aligned in a 16-bit boundary, then ASSERT().
794 If String has only pad spaces, then zero is returned.
795 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
796 then zero is returned.
797 If the number represented by String overflows according to the range defined by
798 UINTN, then ASSERT().
800 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
801 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
804 @param String Pointer to a Null-terminated Unicode string.
812 IN CONST CHAR16
*String
817 ASSERT (String
!= NULL
);
818 ASSERT (((UINTN
) String
& 0x01) == 0);
819 ASSERT (StrLen (String
) < PcdGet32 (PcdMaximumUnicodeStringLength
));
822 // Ignore the pad spaces (space or tab)
824 while ((*String
== L
' ') || (*String
== L
'\t')) {
829 // Ignore leading Zeros after the spaces
831 while (*String
== L
'0') {
835 if (InternalCharToUpper (*String
) == L
'X') {
836 ASSERT (*(String
- 1) == L
'0');
837 if (*(String
- 1) != L
'0') {
848 while (InternalIsHexaDecimalDigitCharacter (*String
)) {
850 // If the Hex Number represented by String overflows according
851 // to the range defined by UINTN, then ASSERT().
853 ASSERT ((Result
< QUIENT_MAX_UINTN_DIVIDED_BY_16
) ||
854 ((Result
== QUIENT_MAX_UINTN_DIVIDED_BY_16
) &&
855 (InternalHexCharToUintn (*String
) <= REMINDER_MAX_UINTN_DIVIDED_BY_16
))
858 Result
= (Result
<< 4) + InternalHexCharToUintn (*String
);
867 Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.
869 This function returns a value of type UINT64 by interpreting the contents
870 of the Unicode string specified by String as a hexadecimal number.
871 The format of the input Unicode string String is
873 [spaces][zeros][x][hexadecimal digits].
875 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
876 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
877 If "x" appears in the input string, it must be prefixed with at least one 0.
878 The function will ignore the pad space, which includes spaces or tab characters,
879 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
880 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
881 first valid hexadecimal digit. Then, the function stops at the first character that is
882 a not a valid hexadecimal character or NULL, whichever one comes first.
884 If String is NULL, then ASSERT().
885 If String is not aligned in a 16-bit boundary, then ASSERT().
886 If String has only pad spaces, then zero is returned.
887 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
888 then zero is returned.
889 If the number represented by String overflows according to the range defined by
890 UINT64, then ASSERT().
892 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
893 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
896 @param String Pointer to a Null-terminated Unicode string.
904 IN CONST CHAR16
*String
909 ASSERT (String
!= NULL
);
910 ASSERT (((UINTN
) String
& 0x01) == 0);
911 ASSERT (StrLen (String
) < PcdGet32 (PcdMaximumUnicodeStringLength
));
914 // Ignore the pad spaces (space or tab)
916 while ((*String
== L
' ') || (*String
== L
'\t')) {
921 // Ignore leading Zeros after the spaces
923 while (*String
== L
'0') {
927 if (InternalCharToUpper (*String
) == L
'X') {
928 ASSERT (*(String
- 1) == L
'0');
929 if (*(String
- 1) != L
'0') {
940 while (InternalIsHexaDecimalDigitCharacter (*String
)) {
942 // If the Hex Number represented by String overflows according
943 // to the range defined by UINTN, then ASSERT().
945 ASSERT ((Result
< QUIENT_MAX_UINT64_DIVIDED_BY_16
)||
946 ((Result
== QUIENT_MAX_UINT64_DIVIDED_BY_16
) &&
947 (InternalHexCharToUintn (*String
) <= REMINDER_MAX_UINT64_DIVIDED_BY_16
))
950 Result
= LShiftU64 (Result
, 4);
951 Result
= Result
+ InternalHexCharToUintn (*String
);
959 Check if a ASCII character is a decimal character.
961 This internal function checks if a Unicode character is a
962 decimal character. The valid decimal character is from
965 @param Char The character to check against.
967 @retval TRUE If the Char is a decmial character.
968 @retval FALSE Otherwise.
973 InternalAsciiIsDecimalDigitCharacter (
977 return (BOOLEAN
) (Char
>= '0' && Char
<= '9');
981 Check if a ASCII character is a hexadecimal character.
983 This internal function checks if a ASCII character is a
984 decimal character. The valid hexadecimal character is
985 L'0' to L'9', L'a' to L'f', or L'A' to L'F'.
988 @param Char The character to check against.
990 @retval TRUE If the Char is a hexadecmial character.
991 @retval FALSE Otherwise.
996 InternalAsciiIsHexaDecimalDigitCharacter (
1001 return (BOOLEAN
) (InternalAsciiIsDecimalDigitCharacter (Char
) ||
1002 (Char
>= 'A' && Char
<= 'F') ||
1003 (Char
>= 'a' && Char
<= 'f'));
1007 Convert a Null-terminated Unicode string to a Null-terminated
1008 ASCII string and returns the ASCII string.
1010 This function converts the content of the Unicode string Source
1011 to the ASCII string Destination by copying the lower 8 bits of
1012 each Unicode character. It returns Destination. The function terminates
1013 the ASCII string Destination by appending a Null-terminator character
1014 at the end. The caller is responsible to make sure Destination points
1015 to a buffer with size equal or greater than (StrLen (Source) + 1) in bytes.
1017 If Destination is NULL, then ASSERT().
1018 If Source is NULL, then ASSERT().
1019 If Source is not aligned on a 16-bit boundary, then ASSERT().
1020 If Source and Destination overlap, then ASSERT().
1022 If any Unicode characters in Source contain non-zero value in
1023 the upper 8 bits, then ASSERT().
1025 If PcdMaximumUnicodeStringLength is not zero, and Source contains
1026 more than PcdMaximumUnicodeStringLength Unicode characters not including
1027 the Null-terminator, then ASSERT().
1029 If PcdMaximumAsciiStringLength is not zero, and Source contains more
1030 than PcdMaximumAsciiStringLength Unicode characters not including the
1031 Null-terminator, then ASSERT().
1033 @param Source Pointer to a Null-terminated Unicode string.
1034 @param Destination Pointer to a Null-terminated ASCII string.
1041 UnicodeStrToAsciiStr (
1042 IN CONST CHAR16
*Source
,
1043 OUT CHAR8
*Destination
1046 ASSERT (Destination
!= NULL
);
1047 ASSERT (Source
!= NULL
);
1048 ASSERT (((UINTN
) Source
& 0x01) == 0);
1051 // Source and Destination should not overlap
1053 ASSERT ((UINTN
) ((CHAR16
*) Destination
- Source
) > StrLen (Source
));
1054 ASSERT ((UINTN
) ((CHAR8
*) Source
- Destination
) > StrLen (Source
));
1057 // If PcdMaximumUnicodeStringLength is not zero,
1058 // length of Source should not more than PcdMaximumUnicodeStringLength
1060 if (PcdGet32 (PcdMaximumUnicodeStringLength
) != 0) {
1061 ASSERT (StrLen (Source
) < PcdGet32 (PcdMaximumUnicodeStringLength
));
1064 while (*Source
!= '\0') {
1066 // If any Unicode characters in Source contain
1067 // non-zero value in the upper 8 bits, then ASSERT().
1069 ASSERT (*Source
< 0x100);
1070 *(Destination
++) = (CHAR8
) *(Source
++);
1073 *Destination
= '\0';
1080 Copies one Null-terminated ASCII string to another Null-terminated ASCII
1081 string and returns the new ASCII string.
1083 This function copies the contents of the ASCII string Source to the ASCII
1084 string Destination, and returns Destination. If Source and Destination
1085 overlap, then the results are undefined.
1087 If Destination is NULL, then ASSERT().
1088 If Source is NULL, then ASSERT().
1089 If Source and Destination overlap, then ASSERT().
1090 If PcdMaximumAsciiStringLength is not zero and Source contains more than
1091 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1094 @param Destination Pointer to a Null-terminated ASCII string.
1095 @param Source Pointer to a Null-terminated ASCII string.
1103 OUT CHAR8
*Destination
,
1104 IN CONST CHAR8
*Source
1110 // Destination cannot be NULL
1112 ASSERT (Destination
!= NULL
);
1115 // Destination and source cannot overlap
1117 ASSERT ((UINTN
)(Destination
- Source
) > AsciiStrLen (Source
));
1118 ASSERT ((UINTN
)(Source
- Destination
) > AsciiStrLen (Source
));
1120 ReturnValue
= Destination
;
1122 *(Destination
++) = *(Source
++);
1129 Copies one Null-terminated ASCII string with a maximum length to another
1130 Null-terminated ASCII string with a maximum length and returns the new ASCII
1133 This function copies the contents of the ASCII string Source to the ASCII
1134 string Destination, and returns Destination. At most, Length ASCII characters
1135 are copied from Source to Destination. If Length is 0, then Destination is
1136 returned unmodified. If Length is greater that the number of ASCII characters
1137 in Source, then Destination is padded with Null ASCII characters. If Source
1138 and Destination overlap, then the results are undefined.
1140 If Destination is NULL, then ASSERT().
1141 If Source is NULL, then ASSERT().
1142 If Source and Destination overlap, then ASSERT().
1143 If PcdMaximumAsciiStringLength is not zero, and Length is greater than
1144 PcdMaximumAsciiStringLength, then ASSERT().
1145 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1146 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1149 @param Destination Pointer to a Null-terminated ASCII string.
1150 @param Source Pointer to a Null-terminated ASCII string.
1151 @param Length Maximum number of ASCII characters to copy.
1159 OUT CHAR8
*Destination
,
1160 IN CONST CHAR8
*Source
,
1171 // Destination cannot be NULL
1173 ASSERT (Destination
!= NULL
);
1176 // Destination and source cannot overlap
1178 ASSERT ((UINTN
)(Destination
- Source
) > AsciiStrLen (Source
));
1179 ASSERT ((UINTN
)(Source
- Destination
) >= Length
);
1181 ReturnValue
= Destination
;
1183 while (*Source
&& Length
> 0) {
1184 *(Destination
++) = *(Source
++);
1188 ZeroMem (Destination
, Length
* sizeof (*Destination
));
1193 Returns the length of a Null-terminated ASCII string.
1195 This function returns the number of ASCII characters in the Null-terminated
1196 ASCII string specified by String.
1198 If String is NULL, then ASSERT().
1199 If PcdMaximumAsciiStringLength is not zero and String contains more than
1200 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1203 @param String Pointer to a Null-terminated ASCII string.
1205 @return The length of String.
1211 IN CONST CHAR8
*String
1216 ASSERT (String
!= NULL
);
1218 for (Length
= 0; *String
!= '\0'; String
++, Length
++) {
1220 // If PcdMaximumUnicodeStringLength is not zero,
1221 // length should not more than PcdMaximumUnicodeStringLength
1223 if (PcdGet32 (PcdMaximumAsciiStringLength
) != 0) {
1224 ASSERT (Length
< PcdGet32 (PcdMaximumAsciiStringLength
));
1231 Returns the size of a Null-terminated ASCII string in bytes, including the
1234 This function returns the size, in bytes, of the Null-terminated ASCII string
1235 specified by String.
1237 If String is NULL, then ASSERT().
1238 If PcdMaximumAsciiStringLength is not zero and String contains more than
1239 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1242 @param String Pointer to a Null-terminated ASCII string.
1244 @return The size of String.
1250 IN CONST CHAR8
*String
1253 return (AsciiStrLen (String
) + 1) * sizeof (*String
);
1257 Compares two Null-terminated ASCII strings, and returns the difference
1258 between the first mismatched ASCII characters.
1260 This function compares the Null-terminated ASCII string FirstString to the
1261 Null-terminated ASCII string SecondString. If FirstString is identical to
1262 SecondString, then 0 is returned. Otherwise, the value returned is the first
1263 mismatched ASCII character in SecondString subtracted from the first
1264 mismatched ASCII character in FirstString.
1266 If FirstString is NULL, then ASSERT().
1267 If SecondString is NULL, then ASSERT().
1268 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
1269 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1271 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
1272 than PcdMaximumAsciiStringLength ASCII characters not including the
1273 Null-terminator, then ASSERT().
1275 @param FirstString Pointer to a Null-terminated ASCII string.
1276 @param SecondString Pointer to a Null-terminated ASCII string.
1278 @retval 0 FirstString is identical to SecondString.
1279 @retval !=0 FirstString is not identical to SecondString.
1285 IN CONST CHAR8
*FirstString
,
1286 IN CONST CHAR8
*SecondString
1290 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
1292 ASSERT (AsciiStrSize (FirstString
));
1293 ASSERT (AsciiStrSize (SecondString
));
1295 while ((*FirstString
!= '\0') && (*FirstString
== *SecondString
)) {
1300 return *FirstString
- *SecondString
;
1304 Converts a lowercase Ascii character to upper one
1306 If Chr is lowercase Ascii character, then converts it to upper one.
1308 If Value >= 0xA0, then ASSERT().
1309 If (Value & 0x0F) >= 0x0A, then ASSERT().
1311 @param chr one Ascii character
1313 @return The uppercase value of Ascii character
1322 return (UINT8
) ((Chr
>= 'a' && Chr
<= 'z') ? Chr
- ('a' - 'A') : Chr
);
1326 Convert a ASCII character to numerical value.
1328 This internal function only deal with Unicode character
1329 which maps to a valid hexadecimal ASII character, i.e.
1330 '0' to '9', 'a' to 'f' or 'A' to 'F'. For other
1331 ASCII character, the value returned does not make sense.
1333 @param Char The character to convert.
1335 @retval UINTN The numerical value converted.
1340 InternalAsciiHexCharToUintn (
1344 if (InternalIsDecimalDigitCharacter (Char
)) {
1348 return (UINTN
) (10 + AsciiToUpper (Char
) - 'A');
1353 Performs a case insensitive comparison of two Null-terminated ASCII strings,
1354 and returns the difference between the first mismatched ASCII characters.
1356 This function performs a case insensitive comparison of the Null-terminated
1357 ASCII string FirstString to the Null-terminated ASCII string SecondString. If
1358 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
1359 value returned is the first mismatched lower case ASCII character in
1360 SecondString subtracted from the first mismatched lower case ASCII character
1363 If FirstString is NULL, then ASSERT().
1364 If SecondString is NULL, then ASSERT().
1365 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
1366 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1368 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
1369 than PcdMaximumAsciiStringLength ASCII characters not including the
1370 Null-terminator, then ASSERT().
1372 @param FirstString Pointer to a Null-terminated ASCII string.
1373 @param SecondString Pointer to a Null-terminated ASCII string.
1375 @retval 0 FirstString is identical to SecondString using case insensitive
1377 @retval !=0 FirstString is not identical to SecondString using case
1378 insensitive comparisons.
1384 IN CONST CHAR8
*FirstString
,
1385 IN CONST CHAR8
*SecondString
1388 CHAR8 UpperFirstString
;
1389 CHAR8 UpperSecondString
;
1392 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
1394 ASSERT (AsciiStrSize (FirstString
));
1395 ASSERT (AsciiStrSize (SecondString
));
1397 UpperFirstString
= AsciiToUpper (*FirstString
);
1398 UpperSecondString
= AsciiToUpper (*SecondString
);
1399 while ((*FirstString
!= '\0') && (UpperFirstString
== UpperSecondString
)) {
1402 UpperFirstString
= AsciiToUpper (*FirstString
);
1403 UpperSecondString
= AsciiToUpper (*SecondString
);
1406 return UpperFirstString
- UpperSecondString
;
1410 Compares two Null-terminated ASCII strings with maximum lengths, and returns
1411 the difference between the first mismatched ASCII characters.
1413 This function compares the Null-terminated ASCII string FirstString to the
1414 Null-terminated ASCII string SecondString. At most, Length ASCII characters
1415 will be compared. If Length is 0, then 0 is returned. If FirstString is
1416 identical to SecondString, then 0 is returned. Otherwise, the value returned
1417 is the first mismatched ASCII character in SecondString subtracted from the
1418 first mismatched ASCII character in FirstString.
1420 If FirstString is NULL, then ASSERT().
1421 If SecondString is NULL, then ASSERT().
1422 If PcdMaximumAsciiStringLength is not zero, and Length is greater than
1423 PcdMaximumAsciiStringLength, then ASSERT().
1424 If PcdMaximumAsciiStringLength is not zero, and FirstString contains more than
1425 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1427 If PcdMaximumAsciiStringLength is not zero, and SecondString contains more than
1428 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1431 @param FirstString Pointer to a Null-terminated ASCII string.
1432 @param SecondString Pointer to a Null-terminated ASCII string.
1434 @retval 0 FirstString is identical to SecondString.
1435 @retval !=0 FirstString is not identical to SecondString.
1441 IN CONST CHAR8
*FirstString
,
1442 IN CONST CHAR8
*SecondString
,
1451 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
1453 ASSERT (AsciiStrSize (FirstString
));
1454 ASSERT (AsciiStrSize (SecondString
));
1456 while ((*FirstString
!= '\0') &&
1457 (*FirstString
== *SecondString
) &&
1463 return *FirstString
- *SecondString
;
1467 Concatenates one Null-terminated ASCII string to another Null-terminated
1468 ASCII string, and returns the concatenated ASCII string.
1470 This function concatenates two Null-terminated ASCII strings. The contents of
1471 Null-terminated ASCII string Source are concatenated to the end of Null-
1472 terminated ASCII string Destination. The Null-terminated concatenated ASCII
1475 If Destination is NULL, then ASSERT().
1476 If Source is NULL, then ASSERT().
1477 If PcdMaximumAsciiStringLength is not zero and Destination contains more than
1478 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1480 If PcdMaximumAsciiStringLength is not zero and Source contains more than
1481 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1483 If PcdMaximumAsciiStringLength is not zero and concatenating Destination and
1484 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
1485 ASCII characters, then ASSERT().
1487 @param Destination Pointer to a Null-terminated ASCII string.
1488 @param Source Pointer to a Null-terminated ASCII string.
1496 IN OUT CHAR8
*Destination
,
1497 IN CONST CHAR8
*Source
1500 AsciiStrCpy (Destination
+ AsciiStrLen (Destination
), Source
);
1503 // Size of the resulting string should never be zero.
1504 // PcdMaximumUnicodeStringLength is tested inside StrLen().
1506 ASSERT (AsciiStrSize (Destination
) != 0);
1511 Concatenates one Null-terminated ASCII string with a maximum length to the
1512 end of another Null-terminated ASCII string, and returns the concatenated
1515 This function concatenates two Null-terminated ASCII strings. The contents
1516 of Null-terminated ASCII string Source are concatenated to the end of Null-
1517 terminated ASCII string Destination, and Destination is returned. At most,
1518 Length ASCII characters are concatenated from Source to the end of
1519 Destination, and Destination is always Null-terminated. If Length is 0, then
1520 Destination is returned unmodified. If Source and Destination overlap, then
1521 the results are undefined.
1523 If Destination is NULL, then ASSERT().
1524 If Source is NULL, then ASSERT().
1525 If Source and Destination overlap, then ASSERT().
1526 If PcdMaximumAsciiStringLength is not zero, and Length is greater than
1527 PcdMaximumAsciiStringLength, then ASSERT().
1528 If PcdMaximumAsciiStringLength is not zero, and Destination contains more than
1529 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1531 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1532 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1534 If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and
1535 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
1536 ASCII characters, not including the Null-terminator, then ASSERT().
1538 @param Destination Pointer to a Null-terminated ASCII string.
1539 @param Source Pointer to a Null-terminated ASCII string.
1540 @param Length Maximum number of ASCII characters to concatenate from
1549 IN OUT CHAR8
*Destination
,
1550 IN CONST CHAR8
*Source
,
1554 AsciiStrnCpy (Destination
+ AsciiStrLen (Destination
), Source
, Length
);
1557 // Size of the resulting string should never be zero.
1558 // PcdMaximumUnicodeStringLength is tested inside StrLen().
1560 ASSERT (AsciiStrSize (Destination
) != 0);
1565 Returns the first occurance of a Null-terminated ASCII sub-string
1566 in a Null-terminated ASCII string.
1568 This function scans the contents of the ASCII string specified by String
1569 and returns the first occurrence of SearchString. If SearchString is not
1570 found in String, then NULL is returned. If the length of SearchString is zero,
1571 then String is returned.
1573 If String is NULL, then ASSERT().
1574 If SearchString is NULL, then ASSERT().
1576 If PcdMaximumAsciiStringLength is not zero, and SearchString or
1577 String contains more than PcdMaximumAsciiStringLength Unicode characters
1578 not including the Null-terminator, then ASSERT().
1580 @param String Pointer to a Null-terminated ASCII string.
1581 @param SearchString Pointer to a Null-terminated ASCII string to search for.
1583 @retval NULL If the SearchString does not appear in String.
1584 @retval !NULL If there is a match.
1590 IN CONST CHAR8
*String
,
1591 IN CONST CHAR8
*SearchString
1594 CONST CHAR8
*FirstMatch
;
1595 CONST CHAR8
*SearchStringTmp
;
1597 ASSERT (String
!= NULL
);
1598 ASSERT (SearchString
!= NULL
);
1601 // If PcdMaximumUnicodeStringLength is not zero,
1602 // length of String should not more than PcdMaximumUnicodeStringLength
1604 if (PcdGet32 (PcdMaximumAsciiStringLength
) != 0) {
1605 ASSERT (AsciiStrLen (String
) < PcdGet32 (PcdMaximumAsciiStringLength
));
1609 // If PcdMaximumUnicodeStringLength is not zero,
1610 // length of SearchString should not more than PcdMaximumUnicodeStringLength
1612 if (PcdGet32 (PcdMaximumAsciiStringLength
) != 0) {
1613 ASSERT (AsciiStrLen (SearchString
) < PcdGet32 (PcdMaximumAsciiStringLength
));
1616 while (*String
!= '\0') {
1617 SearchStringTmp
= SearchString
;
1618 FirstMatch
= String
;
1620 while ((*String
== *SearchStringTmp
)
1621 && (*SearchStringTmp
!= '\0')
1622 && (*String
!= '\0')) {
1627 if (*SearchStringTmp
== '\0') {
1628 return (CHAR8
*) FirstMatch
;
1631 if (SearchStringTmp
== SearchString
) {
1633 // If no character from SearchString match,
1634 // move the pointer to the String under search
1635 // by one character.
1646 Convert a Null-terminated ASCII decimal string to a value of type
1649 This function returns a value of type UINTN by interpreting the contents
1650 of the ASCII string String as a decimal number. The format of the input
1651 ASCII string String is:
1653 [spaces] [decimal digits].
1655 The valid decimal digit character is in the range [0-9]. The function will
1656 ignore the pad space, which includes spaces or tab characters, before the digits.
1657 The running zero in the beginning of [decimal digits] will be ignored. Then, the
1658 function stops at the first character that is a not a valid decimal character or
1659 Null-terminator, whichever on comes first.
1661 If String has only pad spaces, then 0 is returned.
1662 If String has no pad spaces or valid decimal digits, then 0 is returned.
1663 If the number represented by String overflows according to the range defined by
1664 UINTN, then ASSERT().
1665 If String is NULL, then ASSERT().
1666 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1667 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1670 @param String Pointer to a Null-terminated ASCII string.
1677 AsciiStrDecimalToUintn (
1678 IN CONST CHAR8
*String
1683 ASSERT (String
!= NULL
);
1684 ASSERT (AsciiStrLen (String
) < PcdGet32 (PcdMaximumAsciiStringLength
));
1687 // Ignore the pad spaces (space or tab)
1689 while ((*String
== ' ') || (*String
== '\t')) {
1694 // Ignore leading Zeros after the spaces
1696 while (*String
== '0') {
1702 while (InternalAsciiIsDecimalDigitCharacter (*String
)) {
1704 // If the number represented by String overflows according
1705 // to the range defined by UINTN, then ASSERT().
1707 ASSERT ((Result
< QUIENT_MAX_UINTN_DIVIDED_BY_10
) ||
1708 ((Result
== QUIENT_MAX_UINTN_DIVIDED_BY_10
) &&
1709 (*String
- '0') <= REMINDER_MAX_UINTN_DIVIDED_BY_10
)
1712 Result
= Result
* 10 + (*String
- '0');
1721 Convert a Null-terminated ASCII decimal string to a value of type
1724 This function returns a value of type UINT64 by interpreting the contents
1725 of the ASCII string String as a decimal number. The format of the input
1726 ASCII string String is:
1728 [spaces] [decimal digits].
1730 The valid decimal digit character is in the range [0-9]. The function will
1731 ignore the pad space, which includes spaces or tab characters, before the digits.
1732 The running zero in the beginning of [decimal digits] will be ignored. Then, the
1733 function stops at the first character that is a not a valid decimal character or
1734 Null-terminator, whichever on comes first.
1736 If String has only pad spaces, then 0 is returned.
1737 If String has no pad spaces or valid decimal digits, then 0 is returned.
1738 If the number represented by String overflows according to the range defined by
1739 UINT64, then ASSERT().
1740 If String is NULL, then ASSERT().
1741 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1742 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1745 @param String Pointer to a Null-terminated ASCII string.
1752 AsciiStrDecimalToUint64 (
1753 IN CONST CHAR8
*String
1758 ASSERT (String
!= NULL
);
1759 ASSERT (AsciiStrLen (String
) < PcdGet32 (PcdMaximumAsciiStringLength
));
1762 // Ignore the pad spaces (space or tab)
1764 while ((*String
== ' ') || (*String
== '\t')) {
1769 // Ignore leading Zeros after the spaces
1771 while (*String
== '0') {
1777 while (InternalAsciiIsDecimalDigitCharacter (*String
)) {
1779 // If the number represented by String overflows according
1780 // to the range defined by UINTN, then ASSERT().
1782 ASSERT ((Result
< QUIENT_MAX_UINT64_DIVIDED_BY_10
) ||
1783 ((Result
== QUIENT_MAX_UINT64_DIVIDED_BY_10
) &&
1784 (*String
- '0') <= REMINDER_MAX_UINT64_DIVIDED_BY_10
)
1787 Result
= MultU64x32 (Result
, 10) + (*String
- '0');
1795 Convert a Null-terminated ASCII hexadecimal string to a value of type UINTN.
1797 This function returns a value of type UINTN by interpreting the contents of
1798 the ASCII string String as a hexadecimal number. The format of the input ASCII
1801 [spaces][zeros][x][hexadecimal digits].
1803 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1804 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1805 appears in the input string, it must be prefixed with at least one 0. The function
1806 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1807 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1808 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1809 digit. Then, the function stops at the first character that is a not a valid
1810 hexadecimal character or Null-terminator, whichever on comes first.
1812 If String has only pad spaces, then 0 is returned.
1813 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1816 If the number represented by String overflows according to the range defined by UINTN,
1818 If String is NULL, then ASSERT().
1819 If PcdMaximumAsciiStringLength is not zero,
1820 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1821 the Null-terminator, then ASSERT().
1823 @param String Pointer to a Null-terminated ASCII string.
1830 AsciiStrHexToUintn (
1831 IN CONST CHAR8
*String
1836 ASSERT (String
!= NULL
);
1837 ASSERT (AsciiStrLen (String
) < PcdGet32 (PcdMaximumAsciiStringLength
));
1840 // Ignore the pad spaces (space or tab)
1842 while ((*String
== ' ') || (*String
== '\t')) {
1847 // Ignore leading Zeros after the spaces
1849 while (*String
== '0') {
1853 if (AsciiToUpper (*String
) == 'X') {
1854 ASSERT (*(String
- 1) == '0');
1855 if (*(String
- 1) != '0') {
1866 while (InternalAsciiIsHexaDecimalDigitCharacter (*String
)) {
1868 // If the Hex Number represented by String overflows according
1869 // to the range defined by UINTN, then ASSERT().
1871 ASSERT ((Result
< QUIENT_MAX_UINTN_DIVIDED_BY_16
) ||
1872 ((Result
== QUIENT_MAX_UINTN_DIVIDED_BY_16
) &&
1873 (InternalAsciiHexCharToUintn (*String
) <= REMINDER_MAX_UINTN_DIVIDED_BY_16
))
1876 Result
= (Result
<< 4) + InternalAsciiHexCharToUintn (*String
);
1885 Convert a Null-terminated ASCII hexadecimal string to a value of type UINT64.
1887 This function returns a value of type UINT64 by interpreting the contents of
1888 the ASCII string String as a hexadecimal number. The format of the input ASCII
1891 [spaces][zeros][x][hexadecimal digits].
1893 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1894 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1895 appears in the input string, it must be prefixed with at least one 0. The function
1896 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1897 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1898 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1899 digit. Then, the function stops at the first character that is a not a valid
1900 hexadecimal character or Null-terminator, whichever on comes first.
1902 If String has only pad spaces, then 0 is returned.
1903 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1906 If the number represented by String overflows according to the range defined by UINT64,
1908 If String is NULL, then ASSERT().
1909 If PcdMaximumAsciiStringLength is not zero,
1910 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1911 the Null-terminator, then ASSERT().
1913 @param String Pointer to a Null-terminated ASCII string.
1920 AsciiStrHexToUint64 (
1921 IN CONST CHAR8
*String
1926 ASSERT (String
!= NULL
);
1927 ASSERT (AsciiStrLen (String
) < PcdGet32 (PcdMaximumUnicodeStringLength
));
1930 // Ignore the pad spaces (space or tab) and leading Zeros
1933 // Ignore the pad spaces (space or tab)
1935 while ((*String
== ' ') || (*String
== '\t')) {
1940 // Ignore leading Zeros after the spaces
1942 while (*String
== '0') {
1946 if (AsciiToUpper (*String
) == 'X') {
1947 ASSERT (*(String
- 1) == '0');
1948 if (*(String
- 1) != '0') {
1959 while (InternalAsciiIsHexaDecimalDigitCharacter (*String
)) {
1961 // If the Hex Number represented by String overflows according
1962 // to the range defined by UINTN, then ASSERT().
1964 ASSERT ((Result
< QUIENT_MAX_UINT64_DIVIDED_BY_16
) ||
1965 ((Result
== QUIENT_MAX_UINT64_DIVIDED_BY_16
) &&
1966 (InternalAsciiHexCharToUintn (*String
) <= REMINDER_MAX_UINT64_DIVIDED_BY_16
))
1969 Result
= LShiftU64 (Result
, 4);
1970 Result
= Result
+ InternalAsciiHexCharToUintn (*String
);
1979 Convert one Null-terminated ASCII string to a Null-terminated
1980 Unicode string and returns the Unicode string.
1982 This function converts the contents of the ASCII string Source to the Unicode
1983 string Destination, and returns Destination. The function terminates the
1984 Unicode string Destination by appending a Null-terminator character at the end.
1985 The caller is responsible to make sure Destination points to a buffer with size
1986 equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.
1988 If Destination is NULL, then ASSERT().
1989 If Destination is not aligned on a 16-bit boundary, then ASSERT().
1990 If Source is NULL, then ASSERT().
1991 If Source and Destination overlap, then ASSERT().
1992 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1993 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1995 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
1996 PcdMaximumUnicodeStringLength ASCII characters not including the
1997 Null-terminator, then ASSERT().
1999 @param Source Pointer to a Null-terminated ASCII string.
2000 @param Destination Pointer to a Null-terminated Unicode string.
2007 AsciiStrToUnicodeStr (
2008 IN CONST CHAR8
*Source
,
2009 OUT CHAR16
*Destination
2012 ASSERT (Destination
!= NULL
);
2013 ASSERT (Source
!= NULL
);
2016 // Source and Destination should not overlap
2018 ASSERT ((UINTN
) ((CHAR8
*) Destination
- Source
) > AsciiStrLen (Source
));
2019 ASSERT ((UINTN
) (Source
- (CHAR8
*) Destination
) > (AsciiStrLen (Source
) * sizeof (CHAR16
)));
2022 // If PcdMaximumAsciiStringLength is not zero,
2023 // length of Source should not more than PcdMaximumUnicodeStringLength
2025 if (PcdGet32 (PcdMaximumAsciiStringLength
) != 0) {
2026 ASSERT (AsciiStrLen (Source
) < PcdGet32 (PcdMaximumAsciiStringLength
));
2029 while (*Source
!= '\0') {
2030 *(Destination
++) = (CHAR16
) *(Source
++);
2033 // End the Destination with a NULL.
2035 *Destination
= '\0';
2041 Converts an 8-bit value to an 8-bit BCD value.
2043 Converts the 8-bit value specified by Value to BCD. The BCD value is
2046 If Value >= 100, then ASSERT().
2048 @param Value The 8-bit value to convert to BCD. Range 0..99.
2050 @return The BCD value
2059 ASSERT (Value
< 100);
2060 return (UINT8
) (((Value
/ 10) << 4) | (Value
% 10));
2064 Converts an 8-bit BCD value to an 8-bit value.
2066 Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit
2069 If Value >= 0xA0, then ASSERT().
2070 If (Value & 0x0F) >= 0x0A, then ASSERT().
2072 @param Value The 8-bit BCD value to convert to an 8-bit value.
2074 @return The 8-bit value is returned.
2083 ASSERT (Value
< 0xa0);
2084 ASSERT ((Value
& 0xf) < 0xa);
2085 return (UINT8
) ((Value
>> 4) * 10 + (Value
& 0xf));