2 Unicode and ASCII string primatives.
4 Copyright (c) 2006 - 2008, 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.
15 #include "BaseLibInternals.h"
17 #define QUOTIENT_MAX_UINTN_DIVIDED_BY_10 ((UINTN) -1 / 10)
18 #define REMAINDER_MAX_UINTN_DIVIDED_BY_10 ((UINTN) -1 % 10)
20 #define QUOTIENT_MAX_UINTN_DIVIDED_BY_16 ((UINTN) -1 / 16)
21 #define REMAINDER_MAX_UINTN_DIVIDED_BY_16 ((UINTN) -1 % 16)
23 #define QUOTIENT_MAX_UINT64_DIVIDED_BY_10 ((UINT64) -1 / 10)
24 #define REMAINDER_MAX_UINT64_DIVIDED_BY_10 ((UINT64) -1 % 10)
26 #define QUOTIENT_MAX_UINT64_DIVIDED_BY_16 ((UINT64) -1 / 16)
27 #define REMAINDER_MAX_UINT64_DIVIDED_BY_16 ((UINT64) -1 % 16)
30 Copies one Null-terminated Unicode string to another Null-terminated Unicode
31 string and returns the new Unicode string.
33 This function copies the contents of the Unicode string Source to the Unicode
34 string Destination, and returns Destination. If Source and Destination
35 overlap, then the results are undefined.
37 If Destination is NULL, then ASSERT().
38 If Destination is not aligned on a 16-bit boundary, then ASSERT().
39 If Source is NULL, then ASSERT().
40 If Source is not aligned on a 16-bit boundary, then ASSERT().
41 If Source and Destination overlap, then ASSERT().
42 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
43 PcdMaximumUnicodeStringLength Unicode characters not including the
44 Null-terminator, then ASSERT().
46 @param Destination Pointer to a Null-terminated Unicode string.
47 @param Source Pointer to a Null-terminated Unicode string.
55 OUT CHAR16
*Destination
,
56 IN CONST CHAR16
*Source
62 // Destination cannot be NULL
64 ASSERT (Destination
!= NULL
);
65 ASSERT (((UINTN
) Destination
& BIT0
) == 0);
68 // Destination and source cannot overlap
70 ASSERT ((UINTN
)(Destination
- Source
) > StrLen (Source
));
71 ASSERT ((UINTN
)(Source
- Destination
) > StrLen (Source
));
73 ReturnValue
= Destination
;
74 while (*Source
!= 0) {
75 *(Destination
++) = *(Source
++);
82 Copies up to a specified length from one Null-terminated Unicode string to
83 another Null-terminated Unicode string and returns the new Unicode string.
85 This function copies the contents of the Unicode string Source to the Unicode
86 string Destination, and returns Destination. At most, Length Unicode
87 characters are copied from Source to Destination. If Length is 0, then
88 Destination is returned unmodified. If Length is greater that the number of
89 Unicode characters in Source, then Destination is padded with Null Unicode
90 characters. If Source and Destination overlap, then the results are
93 If Length > 0 and Destination is NULL, then ASSERT().
94 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
95 If Length > 0 and Source is NULL, then ASSERT().
96 If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().
97 If Source and Destination overlap, then ASSERT().
98 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
99 PcdMaximumUnicodeStringLength Unicode characters not including the
100 Null-terminator, then ASSERT().
102 @param Destination Pointer to a Null-terminated Unicode string.
103 @param Source Pointer to a Null-terminated Unicode string.
104 @param Length Maximum number of Unicode characters to copy.
112 OUT CHAR16
*Destination
,
113 IN CONST CHAR16
*Source
,
124 // Destination cannot be NULL if Length is not zero
126 ASSERT (Destination
!= NULL
);
127 ASSERT (((UINTN
) Destination
& BIT0
) == 0);
130 // Destination and source cannot overlap
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
& BIT0
) == 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 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 @return others 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 up to a specified length the contents of two Null-terminated Unicode strings,
263 and 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 boundary, 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 boundary, then ASSERT().
276 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
277 than PcdMaximumUnicodeStringLength Unicode characters not including the
278 Null-terminator, then ASSERT().
279 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
280 than PcdMaximumUnicodeStringLength Unicode characters not including the
281 Null-terminator, then ASSERT().
283 @param FirstString Pointer to a Null-terminated Unicode string.
284 @param SecondString Pointer to a Null-terminated Unicode string.
285 @param Length Maximum number of Unicode characters to compare.
287 @retval 0 FirstString is identical to SecondString.
288 @return others FirstString is not identical to SecondString.
294 IN CONST CHAR16
*FirstString
,
295 IN CONST CHAR16
*SecondString
,
304 // ASSERT both strings are less long than PcdMaximumUnicodeStringLength.
305 // Length tests are performed inside StrLen().
307 ASSERT (StrSize (FirstString
) != 0);
308 ASSERT (StrSize (SecondString
) != 0);
310 while ((*FirstString
!= L
'\0') &&
311 (*FirstString
== *SecondString
) &&
318 return *FirstString
- *SecondString
;
322 Concatenates one Null-terminated Unicode string to another Null-terminated
323 Unicode string, and returns the concatenated Unicode string.
325 This function concatenates two Null-terminated Unicode strings. The contents
326 of Null-terminated Unicode string Source are concatenated to the end of
327 Null-terminated Unicode string Destination. The Null-terminated concatenated
328 Unicode String is returned. If Source and Destination overlap, then the
329 results are undefined.
331 If Destination is NULL, then ASSERT().
332 If Destination is not aligned on a 16-bit boundary, then ASSERT().
333 If Source is NULL, then ASSERT().
334 If Source is not aligned on a 16-bit boundary, 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 up to a specified length one Null-terminated Unicode to the end
372 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 Destination contains more
389 than PcdMaximumUnicodeStringLength Unicode characters not including the
390 Null-terminator, then ASSERT().
391 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
392 PcdMaximumUnicodeStringLength Unicode characters not including the
393 Null-terminator, then ASSERT().
394 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
395 and Source results in a Unicode string with more than
396 PcdMaximumUnicodeStringLength Unicode characters not including the
397 Null-terminator, then ASSERT().
399 @param Destination Pointer to a Null-terminated Unicode string.
400 @param Source Pointer to a Null-terminated Unicode string.
401 @param Length Maximum number of Unicode characters to concatenate from
410 IN OUT CHAR16
*Destination
,
411 IN CONST CHAR16
*Source
,
415 StrnCpy (Destination
+ StrLen (Destination
), Source
, Length
);
418 // Size of the resulting string should never be zero.
419 // PcdMaximumUnicodeStringLength is tested inside StrLen().
421 ASSERT (StrSize (Destination
) != 0);
426 Returns the first occurrence of a Null-terminated Unicode sub-string
427 in a Null-terminated Unicode string.
429 This function scans the contents of the Null-terminated Unicode string
430 specified by String and returns the first occurrence of SearchString.
431 If SearchString is not found in String, then NULL is returned. If
432 the length of SearchString is zero, then String is
435 If String is NULL, then ASSERT().
436 If String is not aligned on a 16-bit boundary, then ASSERT().
437 If SearchString is NULL, then ASSERT().
438 If SearchString is not aligned on a 16-bit boundary, then ASSERT().
440 If PcdMaximumUnicodeStringLength is not zero, and SearchString
441 or String contains more than PcdMaximumUnicodeStringLength Unicode
442 characters not including the Null-terminator, then ASSERT().
444 @param String Pointer to a Null-terminated Unicode string.
445 @param SearchString Pointer to a Null-terminated Unicode string to search for.
447 @retval NULL If the SearchString does not appear in String.
448 @return others If there is a match.
454 IN CONST CHAR16
*String
,
455 IN CONST CHAR16
*SearchString
458 CONST CHAR16
*FirstMatch
;
459 CONST CHAR16
*SearchStringTmp
;
462 // ASSERT both strings are less long than PcdMaximumUnicodeStringLength.
463 // Length tests are performed inside StrLen().
465 ASSERT (StrSize (String
) != 0);
466 ASSERT (StrSize (SearchString
) != 0);
468 while (*String
!= '\0') {
469 SearchStringTmp
= SearchString
;
472 while ((*String
== *SearchStringTmp
)
473 && (*SearchStringTmp
!= '\0')
474 && (*String
!= '\0')) {
479 if (*SearchStringTmp
== '\0') {
480 return (CHAR16
*) FirstMatch
;
483 if (SearchStringTmp
== SearchString
) {
485 // If no character from SearchString match,
486 // move the pointer to the String under search
497 Check if a Unicode character is a decimal character.
499 This internal function checks if a Unicode character is a
500 decimal character. The valid decimal character is from
503 @param Char The character to check against.
505 @retval TRUE If the Char is a decmial character.
506 @retval FALSE If the Char is not a decmial character.
511 InternalIsDecimalDigitCharacter (
515 return (BOOLEAN
) (Char
>= L
'0' && Char
<= L
'9');
519 Convert a Unicode character to upper case only if
520 it maps to a valid small-case ASCII character.
522 This internal function only deal with Unicode character
523 which maps to a valid small-case ASCII character, i.e.
524 L'a' to L'z'. For other Unicode character, the input character
525 is returned directly.
527 @param Char The character to convert.
529 @retval LowerCharacter If the Char is with range L'a' to L'z'.
530 @retval Unchanged Otherwise.
535 InternalCharToUpper (
539 if (Char
>= L
'a' && Char
<= L
'z') {
540 return (CHAR16
) (Char
- (L
'a' - L
'A'));
547 Convert a Unicode character to numerical value.
549 This internal function only deal with Unicode character
550 which maps to a valid hexadecimal ASII character, i.e.
551 L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other
552 Unicode character, the value returned does not make sense.
554 @param Char The character to convert.
556 @return The numerical value converted.
561 InternalHexCharToUintn (
565 if (InternalIsDecimalDigitCharacter (Char
)) {
569 return (UINTN
) (10 + InternalCharToUpper (Char
) - L
'A');
573 Check if a Unicode character is a hexadecimal character.
575 This internal function checks if a Unicode character is a
576 decimal character. The valid hexadecimal character is
577 L'0' to L'9', L'a' to L'f', or L'A' to L'F'.
580 @param Char The character to check against.
582 @retval TRUE If the Char is a hexadecmial character.
583 @retval FALSE If the Char is not a hexadecmial character.
588 InternalIsHexaDecimalDigitCharacter (
593 return (BOOLEAN
) (InternalIsDecimalDigitCharacter (Char
) ||
594 (Char
>= L
'A' && Char
<= L
'F') ||
595 (Char
>= L
'a' && Char
<= L
'f'));
599 Convert a Null-terminated Unicode decimal string to a value of
602 This function returns a value of type UINTN by interpreting the contents
603 of the Unicode string specified by String as a decimal number. The format
604 of the input Unicode string String is:
606 [spaces] [decimal digits].
608 The valid decimal digit character is in the range [0-9]. The
609 function will ignore the pad space, which includes spaces or
610 tab characters, before [decimal digits]. The running zero in the
611 beginning of [decimal digits] will be ignored. Then, the function
612 stops at the first character that is a not a valid decimal character
613 or a Null-terminator, whichever one comes first.
615 If String is NULL, then ASSERT().
616 If String is not aligned in a 16-bit boundary, then ASSERT().
617 If String has only pad spaces, then 0 is returned.
618 If String has no pad spaces or valid decimal digits,
620 If the number represented by String overflows according
621 to the range defined by UINTN, then ASSERT().
623 If PcdMaximumUnicodeStringLength is not zero, and String contains
624 more than PcdMaximumUnicodeStringLength Unicode characters not including
625 the Null-terminator, then ASSERT().
627 @param String Pointer to a Null-terminated Unicode string.
629 @retval Value translated from String.
635 IN CONST CHAR16
*String
641 // ASSERT String is less long than PcdMaximumUnicodeStringLength.
642 // Length tests are performed inside StrLen().
644 ASSERT (StrSize (String
) != 0);
647 // Ignore the pad spaces (space or tab)
649 while ((*String
== L
' ') || (*String
== L
'\t')) {
654 // Ignore leading Zeros after the spaces
656 while (*String
== L
'0') {
662 while (InternalIsDecimalDigitCharacter (*String
)) {
664 // If the number represented by String overflows according
665 // to the range defined by UINTN, then ASSERT().
667 ASSERT ((Result
< QUOTIENT_MAX_UINTN_DIVIDED_BY_10
) ||
668 ((Result
== QUOTIENT_MAX_UINTN_DIVIDED_BY_10
) &&
669 (*String
- L
'0') <= REMAINDER_MAX_UINTN_DIVIDED_BY_10
)
672 Result
= Result
* 10 + (*String
- L
'0');
681 Convert a Null-terminated Unicode decimal string to a value of
684 This function returns a value of type UINT64 by interpreting the contents
685 of the Unicode string specified by String as a decimal number. The format
686 of the input Unicode string String is:
688 [spaces] [decimal digits].
690 The valid decimal digit character is in the range [0-9]. The
691 function will ignore the pad space, which includes spaces or
692 tab characters, before [decimal digits]. The running zero in the
693 beginning of [decimal digits] will be ignored. Then, the function
694 stops at the first character that is a not a valid decimal character
695 or a Null-terminator, whichever one comes first.
697 If String is NULL, then ASSERT().
698 If String is not aligned in a 16-bit boundary, then ASSERT().
699 If String has only pad spaces, then 0 is returned.
700 If String has no pad spaces or valid decimal digits,
702 If the number represented by String overflows according
703 to the range defined by UINT64, then ASSERT().
705 If PcdMaximumUnicodeStringLength is not zero, and String contains
706 more than PcdMaximumUnicodeStringLength Unicode characters not including
707 the Null-terminator, then ASSERT().
709 @param String Pointer to a Null-terminated Unicode string.
711 @retval Value translated from String.
717 IN CONST CHAR16
*String
723 // ASSERT String is less long than PcdMaximumUnicodeStringLength.
724 // Length tests are performed inside StrLen().
726 ASSERT (StrSize (String
) != 0);
729 // Ignore the pad spaces (space or tab)
731 while ((*String
== L
' ') || (*String
== L
'\t')) {
736 // Ignore leading Zeros after the spaces
738 while (*String
== L
'0') {
744 while (InternalIsDecimalDigitCharacter (*String
)) {
746 // If the number represented by String overflows according
747 // to the range defined by UINTN, then ASSERT().
749 ASSERT ((Result
< QUOTIENT_MAX_UINT64_DIVIDED_BY_10
) ||
750 ((Result
== QUOTIENT_MAX_UINT64_DIVIDED_BY_10
) &&
751 (*String
- L
'0') <= REMAINDER_MAX_UINT64_DIVIDED_BY_10
)
754 Result
= MultU64x32 (Result
, 10) + (*String
- L
'0');
762 Convert a Null-terminated Unicode hexadecimal string to a value of type UINTN.
764 This function returns a value of type UINTN by interpreting the contents
765 of the Unicode string specified by String as a hexadecimal number.
766 The format of the input Unicode string String is:
768 [spaces][zeros][x][hexadecimal digits].
770 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
771 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
772 If "x" appears in the input string, it must be prefixed with at least one 0.
773 The function will ignore the pad space, which includes spaces or tab characters,
774 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
775 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
776 first valid hexadecimal digit. Then, the function stops at the first character that is
777 a not a valid hexadecimal character or NULL, whichever one comes first.
779 If String is NULL, then ASSERT().
780 If String is not aligned in a 16-bit boundary, then ASSERT().
781 If String has only pad spaces, then zero is returned.
782 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
783 then zero is returned.
784 If the number represented by String overflows according to the range defined by
785 UINTN, then ASSERT().
787 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
788 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
791 @param String Pointer to a Null-terminated Unicode string.
793 @retval Value translated from String.
799 IN CONST CHAR16
*String
805 // ASSERT String is less long than PcdMaximumUnicodeStringLength.
806 // Length tests are performed inside StrLen().
808 ASSERT (StrSize (String
) != 0);
811 // Ignore the pad spaces (space or tab)
813 while ((*String
== L
' ') || (*String
== L
'\t')) {
818 // Ignore leading Zeros after the spaces
820 while (*String
== L
'0') {
824 if (InternalCharToUpper (*String
) == L
'X') {
825 ASSERT (*(String
- 1) == L
'0');
826 if (*(String
- 1) != L
'0') {
837 while (InternalIsHexaDecimalDigitCharacter (*String
)) {
839 // If the Hex Number represented by String overflows according
840 // to the range defined by UINTN, then ASSERT().
842 ASSERT ((Result
< QUOTIENT_MAX_UINTN_DIVIDED_BY_16
) ||
843 ((Result
== QUOTIENT_MAX_UINTN_DIVIDED_BY_16
) &&
844 (InternalHexCharToUintn (*String
) <= REMAINDER_MAX_UINTN_DIVIDED_BY_16
))
847 Result
= (Result
<< 4) + InternalHexCharToUintn (*String
);
856 Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.
858 This function returns a value of type UINT64 by interpreting the contents
859 of the Unicode string specified by String as a hexadecimal number.
860 The format of the input Unicode string String is
862 [spaces][zeros][x][hexadecimal digits].
864 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
865 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
866 If "x" appears in the input string, it must be prefixed with at least one 0.
867 The function will ignore the pad space, which includes spaces or tab characters,
868 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
869 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
870 first valid hexadecimal digit. Then, the function stops at the first character that is
871 a not a valid hexadecimal character or NULL, whichever one comes first.
873 If String is NULL, then ASSERT().
874 If String is not aligned in a 16-bit boundary, then ASSERT().
875 If String has only pad spaces, then zero is returned.
876 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
877 then zero is returned.
878 If the number represented by String overflows according to the range defined by
879 UINT64, then ASSERT().
881 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
882 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
885 @param String Pointer to a Null-terminated Unicode string.
887 @retval Value translated from String.
893 IN CONST CHAR16
*String
899 // ASSERT String is less long than PcdMaximumUnicodeStringLength.
900 // Length tests are performed inside StrLen().
902 ASSERT (StrSize (String
) != 0);
905 // Ignore the pad spaces (space or tab)
907 while ((*String
== L
' ') || (*String
== L
'\t')) {
912 // Ignore leading Zeros after the spaces
914 while (*String
== L
'0') {
918 if (InternalCharToUpper (*String
) == L
'X') {
919 ASSERT (*(String
- 1) == L
'0');
920 if (*(String
- 1) != L
'0') {
931 while (InternalIsHexaDecimalDigitCharacter (*String
)) {
933 // If the Hex Number represented by String overflows according
934 // to the range defined by UINTN, then ASSERT().
936 ASSERT ((Result
< QUOTIENT_MAX_UINT64_DIVIDED_BY_16
)||
937 ((Result
== QUOTIENT_MAX_UINT64_DIVIDED_BY_16
) &&
938 (InternalHexCharToUintn (*String
) <= REMAINDER_MAX_UINT64_DIVIDED_BY_16
))
941 Result
= LShiftU64 (Result
, 4);
942 Result
= Result
+ InternalHexCharToUintn (*String
);
950 Check if a ASCII character is a decimal character.
952 This internal function checks if a Unicode character is a
953 decimal character. The valid decimal character is from
956 @param Char The character to check against.
958 @retval TRUE If the Char is a decmial character.
959 @retval FALSE If the Char is not a decmial character.
964 InternalAsciiIsDecimalDigitCharacter (
968 return (BOOLEAN
) (Char
>= '0' && Char
<= '9');
972 Check if a ASCII character is a hexadecimal character.
974 This internal function checks if a ASCII character is a
975 decimal character. The valid hexadecimal character is
976 L'0' to L'9', L'a' to L'f', or L'A' to L'F'.
979 @param Char The character to check against.
981 @retval TRUE If the Char is a hexadecmial character.
982 @retval FALSE If the Char is not a hexadecmial character.
987 InternalAsciiIsHexaDecimalDigitCharacter (
992 return (BOOLEAN
) (InternalAsciiIsDecimalDigitCharacter (Char
) ||
993 (Char
>= 'A' && Char
<= 'F') ||
994 (Char
>= 'a' && Char
<= 'f'));
998 Convert a Null-terminated Unicode string to a Null-terminated
999 ASCII string and returns the ASCII string.
1001 This function converts the content of the Unicode string Source
1002 to the ASCII string Destination by copying the lower 8 bits of
1003 each Unicode character. It returns Destination.
1005 If any Unicode characters in Source contain non-zero value in
1006 the upper 8 bits, then ASSERT().
1008 If Destination is NULL, then ASSERT().
1009 If Source is NULL, then ASSERT().
1010 If Source is not aligned on a 16-bit boundary, then ASSERT().
1011 If Source and Destination overlap, then ASSERT().
1013 If PcdMaximumUnicodeStringLength is not zero, and Source contains
1014 more than PcdMaximumUnicodeStringLength Unicode characters not including
1015 the Null-terminator, then ASSERT().
1017 If PcdMaximumAsciiStringLength is not zero, and Source contains more
1018 than PcdMaximumAsciiStringLength Unicode characters not including the
1019 Null-terminator, then ASSERT().
1021 @param Source Pointer to a Null-terminated Unicode string.
1022 @param Destination Pointer to a Null-terminated ASCII string.
1024 @return Destination.
1029 UnicodeStrToAsciiStr (
1030 IN CONST CHAR16
*Source
,
1031 OUT CHAR8
*Destination
1036 ASSERT (Destination
!= NULL
);
1039 // ASSERT if Source is long than PcdMaximumUnicodeStringLength.
1040 // Length tests are performed inside StrLen().
1042 ASSERT (StrSize (Source
) != 0);
1045 // Source and Destination should not overlap
1047 ASSERT ((UINTN
) ((CHAR16
*) Destination
- Source
) > StrLen (Source
));
1048 ASSERT ((UINTN
) ((CHAR8
*) Source
- Destination
) > StrLen (Source
));
1051 ReturnValue
= Destination
;
1052 while (*Source
!= '\0') {
1054 // If any Unicode characters in Source contain
1055 // non-zero value in the upper 8 bits, then ASSERT().
1057 ASSERT (*Source
< 0x100);
1058 *(Destination
++) = (CHAR8
) *(Source
++);
1061 *Destination
= '\0';
1064 // ASSERT Original Destination is less long than PcdMaximumAsciiStringLength.
1065 // Length tests are performed inside AsciiStrLen().
1067 ASSERT (AsciiStrSize (ReturnValue
) != 0);
1074 Copies one Null-terminated ASCII string to another Null-terminated ASCII
1075 string and returns the new ASCII string.
1077 This function copies the contents of the ASCII string Source to the ASCII
1078 string Destination, and returns Destination. If Source and Destination
1079 overlap, then the results are undefined.
1081 If Destination is NULL, then ASSERT().
1082 If Source is NULL, then ASSERT().
1083 If Source and Destination overlap, then ASSERT().
1084 If PcdMaximumAsciiStringLength is not zero and Source contains more than
1085 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1088 @param Destination Pointer to a Null-terminated ASCII string.
1089 @param Source Pointer to a Null-terminated ASCII string.
1097 OUT CHAR8
*Destination
,
1098 IN CONST CHAR8
*Source
1104 // Destination cannot be NULL
1106 ASSERT (Destination
!= NULL
);
1109 // Destination and source cannot overlap
1111 ASSERT ((UINTN
)(Destination
- Source
) > AsciiStrLen (Source
));
1112 ASSERT ((UINTN
)(Source
- Destination
) > AsciiStrLen (Source
));
1114 ReturnValue
= Destination
;
1115 while (*Source
!= 0) {
1116 *(Destination
++) = *(Source
++);
1123 Copies up to a specified length one Null-terminated ASCII string to another
1124 Null-terminated ASCII string and returns the new ASCII string.
1126 This function copies the contents of the ASCII string Source to the ASCII
1127 string Destination, and returns Destination. At most, Length ASCII characters
1128 are copied from Source to Destination. If Length is 0, then Destination is
1129 returned unmodified. If Length is greater that the number of ASCII characters
1130 in Source, then Destination is padded with Null ASCII characters. If Source
1131 and Destination overlap, then the results are undefined.
1133 If Destination is NULL, then ASSERT().
1134 If Source is NULL, then ASSERT().
1135 If Source and Destination overlap, then ASSERT().
1136 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1137 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1140 @param Destination Pointer to a Null-terminated ASCII string.
1141 @param Source Pointer to a Null-terminated ASCII string.
1142 @param Length Maximum number of ASCII characters to copy.
1150 OUT CHAR8
*Destination
,
1151 IN CONST CHAR8
*Source
,
1162 // Destination cannot be NULL
1164 ASSERT (Destination
!= NULL
);
1167 // Destination and source cannot overlap
1169 ASSERT ((UINTN
)(Destination
- Source
) > AsciiStrLen (Source
));
1170 ASSERT ((UINTN
)(Source
- Destination
) >= Length
);
1172 ReturnValue
= Destination
;
1174 while (*Source
!= 0 && Length
> 0) {
1175 *(Destination
++) = *(Source
++);
1179 ZeroMem (Destination
, Length
* sizeof (*Destination
));
1184 Returns the length of a Null-terminated ASCII string.
1186 This function returns the number of ASCII characters in the Null-terminated
1187 ASCII string specified by String.
1189 If Length > 0 and Destination is NULL, then ASSERT().
1190 If Length > 0 and Source is NULL, then ASSERT().
1191 If PcdMaximumAsciiStringLength is not zero and String contains more than
1192 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1195 @param String Pointer to a Null-terminated ASCII string.
1197 @return The length of String.
1203 IN CONST CHAR8
*String
1208 ASSERT (String
!= NULL
);
1210 for (Length
= 0; *String
!= '\0'; String
++, Length
++) {
1212 // If PcdMaximumUnicodeStringLength is not zero,
1213 // length should not more than PcdMaximumUnicodeStringLength
1215 if (PcdGet32 (PcdMaximumAsciiStringLength
) != 0) {
1216 ASSERT (Length
< PcdGet32 (PcdMaximumAsciiStringLength
));
1223 Returns the size of a Null-terminated ASCII string in bytes, including the
1226 This function returns the size, in bytes, of the Null-terminated ASCII string
1227 specified by String.
1229 If String is NULL, then ASSERT().
1230 If PcdMaximumAsciiStringLength is not zero and String contains more than
1231 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1234 @param String Pointer to a Null-terminated ASCII string.
1236 @return The size of String.
1242 IN CONST CHAR8
*String
1245 return (AsciiStrLen (String
) + 1) * sizeof (*String
);
1249 Compares two Null-terminated ASCII strings, and returns the difference
1250 between the first mismatched ASCII characters.
1252 This function compares the Null-terminated ASCII string FirstString to the
1253 Null-terminated ASCII string SecondString. If FirstString is identical to
1254 SecondString, then 0 is returned. Otherwise, the value returned is the first
1255 mismatched ASCII character in SecondString subtracted from the first
1256 mismatched ASCII character in FirstString.
1258 If FirstString is NULL, then ASSERT().
1259 If SecondString is NULL, then ASSERT().
1260 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
1261 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1263 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
1264 than PcdMaximumAsciiStringLength ASCII characters not including the
1265 Null-terminator, then ASSERT().
1267 @param FirstString Pointer to a Null-terminated ASCII string.
1268 @param SecondString Pointer to a Null-terminated ASCII string.
1270 @retval ==0 FirstString is identical to SecondString.
1271 @retval !=0 FirstString is not identical to SecondString.
1277 IN CONST CHAR8
*FirstString
,
1278 IN CONST CHAR8
*SecondString
1282 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
1284 ASSERT (AsciiStrSize (FirstString
));
1285 ASSERT (AsciiStrSize (SecondString
));
1287 while ((*FirstString
!= '\0') && (*FirstString
== *SecondString
)) {
1292 return *FirstString
- *SecondString
;
1296 Converts a lowercase Ascii character to upper one.
1298 If Chr is lowercase Ascii character, then converts it to upper one.
1300 If Value >= 0xA0, then ASSERT().
1301 If (Value & 0x0F) >= 0x0A, then ASSERT().
1303 @param Chr one Ascii character
1305 @return The uppercase value of Ascii character
1314 return (UINT8
) ((Chr
>= 'a' && Chr
<= 'z') ? Chr
- ('a' - 'A') : Chr
);
1318 Convert a ASCII character to numerical value.
1320 This internal function only deal with Unicode character
1321 which maps to a valid hexadecimal ASII character, i.e.
1322 '0' to '9', 'a' to 'f' or 'A' to 'F'. For other
1323 ASCII character, the value returned does not make sense.
1325 @param Char The character to convert.
1327 @return The numerical value converted.
1332 InternalAsciiHexCharToUintn (
1336 if (InternalIsDecimalDigitCharacter (Char
)) {
1340 return (UINTN
) (10 + AsciiToUpper (Char
) - 'A');
1345 Performs a case insensitive comparison of two Null-terminated ASCII strings,
1346 and returns the difference between the first mismatched ASCII characters.
1348 This function performs a case insensitive comparison of the Null-terminated
1349 ASCII string FirstString to the Null-terminated ASCII string SecondString. If
1350 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
1351 value returned is the first mismatched lower case ASCII character in
1352 SecondString subtracted from the first mismatched lower case ASCII character
1355 If FirstString is NULL, then ASSERT().
1356 If SecondString is NULL, then ASSERT().
1357 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
1358 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1360 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
1361 than PcdMaximumAsciiStringLength ASCII characters not including the
1362 Null-terminator, then ASSERT().
1364 @param FirstString Pointer to a Null-terminated ASCII string.
1365 @param SecondString Pointer to a Null-terminated ASCII string.
1367 @retval ==0 FirstString is identical to SecondString using case insensitive
1369 @retval !=0 FirstString is not identical to SecondString using case
1370 insensitive comparisons.
1376 IN CONST CHAR8
*FirstString
,
1377 IN CONST CHAR8
*SecondString
1380 CHAR8 UpperFirstString
;
1381 CHAR8 UpperSecondString
;
1384 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
1386 ASSERT (AsciiStrSize (FirstString
));
1387 ASSERT (AsciiStrSize (SecondString
));
1389 UpperFirstString
= AsciiToUpper (*FirstString
);
1390 UpperSecondString
= AsciiToUpper (*SecondString
);
1391 while ((*FirstString
!= '\0') && (UpperFirstString
== UpperSecondString
)) {
1394 UpperFirstString
= AsciiToUpper (*FirstString
);
1395 UpperSecondString
= AsciiToUpper (*SecondString
);
1398 return UpperFirstString
- UpperSecondString
;
1402 Compares two Null-terminated ASCII strings with maximum lengths, and returns
1403 the difference between the first mismatched ASCII characters.
1405 This function compares the Null-terminated ASCII string FirstString to the
1406 Null-terminated ASCII string SecondString. At most, Length ASCII characters
1407 will be compared. If Length is 0, then 0 is returned. If FirstString is
1408 identical to SecondString, then 0 is returned. Otherwise, the value returned
1409 is the first mismatched ASCII character in SecondString subtracted from the
1410 first mismatched ASCII character in FirstString.
1412 If Length > 0 and FirstString is NULL, then ASSERT().
1413 If Length > 0 and SecondString is NULL, then ASSERT().
1414 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
1415 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1417 If PcdMaximumAsciiStringLength is not zero and SecondString contains more than
1418 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1421 @param FirstString Pointer to a Null-terminated ASCII string.
1422 @param SecondString Pointer to a Null-terminated ASCII string.
1423 @param Length Maximum number of ASCII characters for compare.
1425 @retval ==0 FirstString is identical to SecondString.
1426 @retval !=0 FirstString is not identical to SecondString.
1432 IN CONST CHAR8
*FirstString
,
1433 IN CONST CHAR8
*SecondString
,
1442 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
1444 ASSERT (AsciiStrSize (FirstString
));
1445 ASSERT (AsciiStrSize (SecondString
));
1447 while ((*FirstString
!= '\0') &&
1448 (*FirstString
== *SecondString
) &&
1454 return *FirstString
- *SecondString
;
1458 Concatenates one Null-terminated ASCII string to another Null-terminated
1459 ASCII string, and returns the concatenated ASCII string.
1461 This function concatenates two Null-terminated ASCII strings. The contents of
1462 Null-terminated ASCII string Source are concatenated to the end of Null-
1463 terminated ASCII string Destination. The Null-terminated concatenated ASCII
1466 If Destination is NULL, then ASSERT().
1467 If Source is NULL, then ASSERT().
1468 If PcdMaximumAsciiStringLength is not zero and Destination contains more than
1469 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1471 If PcdMaximumAsciiStringLength is not zero and Source contains more than
1472 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1474 If PcdMaximumAsciiStringLength is not zero and concatenating Destination and
1475 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
1476 ASCII characters, then ASSERT().
1478 @param Destination Pointer to a Null-terminated ASCII string.
1479 @param Source Pointer to a Null-terminated ASCII string.
1487 IN OUT CHAR8
*Destination
,
1488 IN CONST CHAR8
*Source
1491 AsciiStrCpy (Destination
+ AsciiStrLen (Destination
), Source
);
1494 // Size of the resulting string should never be zero.
1495 // PcdMaximumUnicodeStringLength is tested inside StrLen().
1497 ASSERT (AsciiStrSize (Destination
) != 0);
1502 Concatenates up to a specified length one Null-terminated ASCII string to
1503 the end of another Null-terminated ASCII string, and returns the
1504 concatenated ASCII string.
1506 This function concatenates two Null-terminated ASCII strings. The contents
1507 of Null-terminated ASCII string Source are concatenated to the end of Null-
1508 terminated ASCII string Destination, and Destination is returned. At most,
1509 Length ASCII characters are concatenated from Source to the end of
1510 Destination, and Destination is always Null-terminated. If Length is 0, then
1511 Destination is returned unmodified. If Source and Destination overlap, then
1512 the results are undefined.
1514 If Length > 0 and Destination is NULL, then ASSERT().
1515 If Length > 0 and Source is NULL, then ASSERT().
1516 If Source and Destination overlap, then ASSERT().
1517 If PcdMaximumAsciiStringLength is not zero, and Destination contains more than
1518 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1520 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1521 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1523 If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and
1524 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
1525 ASCII characters not including the Null-terminator, then ASSERT().
1527 @param Destination Pointer to a Null-terminated ASCII string.
1528 @param Source Pointer to a Null-terminated ASCII string.
1529 @param Length Maximum number of ASCII characters to concatenate from
1538 IN OUT CHAR8
*Destination
,
1539 IN CONST CHAR8
*Source
,
1543 AsciiStrnCpy (Destination
+ AsciiStrLen (Destination
), Source
, Length
);
1546 // Size of the resulting string should never be zero.
1547 // PcdMaximumUnicodeStringLength is tested inside StrLen().
1549 ASSERT (AsciiStrSize (Destination
) != 0);
1554 Returns the first occurrence of a Null-terminated ASCII sub-string
1555 in a Null-terminated ASCII string.
1557 This function scans the contents of the ASCII string specified by String
1558 and returns the first occurrence of SearchString. If SearchString is not
1559 found in String, then NULL is returned. If the length of SearchString is zero,
1560 then String is returned.
1562 If String is NULL, then ASSERT().
1563 If SearchString is NULL, then ASSERT().
1565 If PcdMaximumAsciiStringLength is not zero, and SearchString or
1566 String contains more than PcdMaximumAsciiStringLength Unicode characters
1567 not including the Null-terminator, then ASSERT().
1569 @param String Pointer to a Null-terminated ASCII string.
1570 @param SearchString Pointer to a Null-terminated ASCII string to search for.
1572 @retval NULL If the SearchString does not appear in String.
1573 @retval others If there is a match return the first occurrence of SearchingString.
1574 If the length of SearchString is zero,return String.
1580 IN CONST CHAR8
*String
,
1581 IN CONST CHAR8
*SearchString
1584 CONST CHAR8
*FirstMatch
;
1585 CONST CHAR8
*SearchStringTmp
;
1588 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
1590 ASSERT (AsciiStrSize (String
) != 0);
1591 ASSERT (AsciiStrSize (SearchString
) != 0);
1593 while (*String
!= '\0') {
1594 SearchStringTmp
= SearchString
;
1595 FirstMatch
= String
;
1597 while ((*String
== *SearchStringTmp
)
1598 && (*SearchStringTmp
!= '\0')
1599 && (*String
!= '\0')) {
1604 if (*SearchStringTmp
== '\0') {
1605 return (CHAR8
*) FirstMatch
;
1608 if (SearchStringTmp
== SearchString
) {
1610 // If no character from SearchString match,
1611 // move the pointer to the String under search
1612 // by one character.
1623 Convert a Null-terminated ASCII decimal string to a value of type
1626 This function returns a value of type UINTN by interpreting the contents
1627 of the ASCII string String as a decimal number. The format of the input
1628 ASCII string String is:
1630 [spaces] [decimal digits].
1632 The valid decimal digit character is in the range [0-9]. The function will
1633 ignore the pad space, which includes spaces or tab characters, before the digits.
1634 The running zero in the beginning of [decimal digits] will be ignored. Then, the
1635 function stops at the first character that is a not a valid decimal character or
1636 Null-terminator, whichever on comes first.
1638 If String has only pad spaces, then 0 is returned.
1639 If String has no pad spaces or valid decimal digits, then 0 is returned.
1640 If the number represented by String overflows according to the range defined by
1641 UINTN, then ASSERT().
1642 If String is NULL, then ASSERT().
1643 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1644 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1647 @param String Pointer to a Null-terminated ASCII string.
1649 @retval Value translated from String.
1654 AsciiStrDecimalToUintn (
1655 IN CONST CHAR8
*String
1661 // ASSERT Strings is less long than PcdMaximumAsciiStringLength
1663 ASSERT (AsciiStrSize (String
) != 0);
1666 // Ignore the pad spaces (space or tab)
1668 while ((*String
== ' ') || (*String
== '\t' )) {
1673 // Ignore leading Zeros after the spaces
1675 while (*String
== '0') {
1681 while (InternalAsciiIsDecimalDigitCharacter (*String
)) {
1683 // If the number represented by String overflows according
1684 // to the range defined by UINTN, then ASSERT().
1686 ASSERT ((Result
< QUOTIENT_MAX_UINTN_DIVIDED_BY_10
) ||
1687 ((Result
== QUOTIENT_MAX_UINTN_DIVIDED_BY_10
) &&
1688 (*String
- '0') <= REMAINDER_MAX_UINTN_DIVIDED_BY_10
)
1691 Result
= Result
* 10 + (*String
- '0');
1700 Convert a Null-terminated ASCII decimal string to a value of type
1703 This function returns a value of type UINT64 by interpreting the contents
1704 of the ASCII string String as a decimal number. The format of the input
1705 ASCII string String is:
1707 [spaces] [decimal digits].
1709 The valid decimal digit character is in the range [0-9]. The function will
1710 ignore the pad space, which includes spaces or tab characters, before the digits.
1711 The running zero in the beginning of [decimal digits] will be ignored. Then, the
1712 function stops at the first character that is a not a valid decimal character or
1713 Null-terminator, whichever on comes first.
1715 If String has only pad spaces, then 0 is returned.
1716 If String has no pad spaces or valid decimal digits, then 0 is returned.
1717 If the number represented by String overflows according to the range defined by
1718 UINT64, then ASSERT().
1719 If String is NULL, then ASSERT().
1720 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1721 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1724 @param String Pointer to a Null-terminated ASCII string.
1726 @retval Value translated from String.
1731 AsciiStrDecimalToUint64 (
1732 IN CONST CHAR8
*String
1738 // ASSERT Strings is less long than PcdMaximumAsciiStringLength
1740 ASSERT (AsciiStrSize (String
) != 0);
1743 // Ignore the pad spaces (space or tab)
1745 while ((*String
== ' ') || (*String
== '\t' )) {
1750 // Ignore leading Zeros after the spaces
1752 while (*String
== '0') {
1758 while (InternalAsciiIsDecimalDigitCharacter (*String
)) {
1760 // If the number represented by String overflows according
1761 // to the range defined by UINTN, then ASSERT().
1763 ASSERT ((Result
< QUOTIENT_MAX_UINT64_DIVIDED_BY_10
) ||
1764 ((Result
== QUOTIENT_MAX_UINT64_DIVIDED_BY_10
) &&
1765 (*String
- '0') <= REMAINDER_MAX_UINT64_DIVIDED_BY_10
)
1768 Result
= MultU64x32 (Result
, 10) + (*String
- '0');
1776 Convert a Null-terminated ASCII hexadecimal string to a value of type UINTN.
1778 This function returns a value of type UINTN by interpreting the contents of
1779 the ASCII string String as a hexadecimal number. The format of the input ASCII
1782 [spaces][zeros][x][hexadecimal digits].
1784 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1785 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1786 appears in the input string, it must be prefixed with at least one 0. The function
1787 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1788 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1789 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1790 digit. Then, the function stops at the first character that is a not a valid
1791 hexadecimal character or Null-terminator, whichever on comes first.
1793 If String has only pad spaces, then 0 is returned.
1794 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1797 If the number represented by String overflows according to the range defined by UINTN,
1799 If String is NULL, then ASSERT().
1800 If PcdMaximumAsciiStringLength is not zero,
1801 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1802 the Null-terminator, then ASSERT().
1804 @param String Pointer to a Null-terminated ASCII string.
1806 @retval Value translated from String.
1811 AsciiStrHexToUintn (
1812 IN CONST CHAR8
*String
1818 // ASSERT Strings is less long than PcdMaximumAsciiStringLength
1820 ASSERT (AsciiStrSize (String
) != 0);
1823 // Ignore the pad spaces (space or tab)
1825 while ((*String
== ' ') || (*String
== '\t' )) {
1830 // Ignore leading Zeros after the spaces
1832 while (*String
== '0') {
1836 if (AsciiToUpper (*String
) == 'X') {
1837 ASSERT (*(String
- 1) == '0');
1838 if (*(String
- 1) != '0') {
1849 while (InternalAsciiIsHexaDecimalDigitCharacter (*String
)) {
1851 // If the Hex Number represented by String overflows according
1852 // to the range defined by UINTN, then ASSERT().
1854 ASSERT ((Result
< QUOTIENT_MAX_UINTN_DIVIDED_BY_16
) ||
1855 ((Result
== QUOTIENT_MAX_UINTN_DIVIDED_BY_16
) &&
1856 (InternalAsciiHexCharToUintn (*String
) <= REMAINDER_MAX_UINTN_DIVIDED_BY_16
))
1859 Result
= (Result
<< 4) + InternalAsciiHexCharToUintn (*String
);
1868 Convert a Null-terminated ASCII hexadecimal string to a value of type UINT64.
1870 This function returns a value of type UINT64 by interpreting the contents of
1871 the ASCII string String as a hexadecimal number. The format of the input ASCII
1874 [spaces][zeros][x][hexadecimal digits].
1876 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1877 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1878 appears in the input string, it must be prefixed with at least one 0. The function
1879 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1880 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1881 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1882 digit. Then, the function stops at the first character that is a not a valid
1883 hexadecimal character or Null-terminator, whichever on comes first.
1885 If String has only pad spaces, then 0 is returned.
1886 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1889 If the number represented by String overflows according to the range defined by UINT64,
1891 If String is NULL, then ASSERT().
1892 If PcdMaximumAsciiStringLength is not zero,
1893 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1894 the Null-terminator, then ASSERT().
1896 @param String Pointer to a Null-terminated ASCII string.
1898 @retval Value translated from String.
1903 AsciiStrHexToUint64 (
1904 IN CONST CHAR8
*String
1910 // ASSERT Strings is less long than PcdMaximumAsciiStringLength
1912 ASSERT (AsciiStrSize (String
) != 0);
1915 // Ignore the pad spaces (space or tab) and leading Zeros
1918 // Ignore the pad spaces (space or tab)
1920 while ((*String
== ' ') || (*String
== '\t' )) {
1925 // Ignore leading Zeros after the spaces
1927 while (*String
== '0') {
1931 if (AsciiToUpper (*String
) == 'X') {
1932 ASSERT (*(String
- 1) == '0');
1933 if (*(String
- 1) != '0') {
1944 while (InternalAsciiIsHexaDecimalDigitCharacter (*String
)) {
1946 // If the Hex Number represented by String overflows according
1947 // to the range defined by UINTN, then ASSERT().
1949 ASSERT ((Result
< QUOTIENT_MAX_UINT64_DIVIDED_BY_16
) ||
1950 ((Result
== QUOTIENT_MAX_UINT64_DIVIDED_BY_16
) &&
1951 (InternalAsciiHexCharToUintn (*String
) <= REMAINDER_MAX_UINT64_DIVIDED_BY_16
))
1954 Result
= LShiftU64 (Result
, 4);
1955 Result
= Result
+ InternalAsciiHexCharToUintn (*String
);
1964 Convert one Null-terminated ASCII string to a Null-terminated
1965 Unicode string and returns the Unicode string.
1967 This function converts the contents of the ASCII string Source to the Unicode
1968 string Destination, and returns Destination. The function terminates the
1969 Unicode string Destination by appending a Null-terminator character at the end.
1970 The caller is responsible to make sure Destination points to a buffer with size
1971 equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.
1973 If Destination is NULL, then ASSERT().
1974 If Destination is not aligned on a 16-bit boundary, then ASSERT().
1975 If Source is NULL, then ASSERT().
1976 If Source and Destination overlap, then ASSERT().
1977 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1978 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1980 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
1981 PcdMaximumUnicodeStringLength ASCII characters not including the
1982 Null-terminator, then ASSERT().
1984 @param Source Pointer to a Null-terminated ASCII string.
1985 @param Destination Pointer to a Null-terminated Unicode string.
1987 @return Destination.
1992 AsciiStrToUnicodeStr (
1993 IN CONST CHAR8
*Source
,
1994 OUT CHAR16
*Destination
1997 CHAR16
*ReturnValue
;
1999 ASSERT (Destination
!= NULL
);
2002 // ASSERT Source is less long than PcdMaximumAsciiStringLength
2004 ASSERT (AsciiStrSize (Source
) != 0);
2007 // Source and Destination should not overlap
2009 ASSERT ((UINTN
) ((CHAR8
*) Destination
- Source
) > AsciiStrLen (Source
));
2010 ASSERT ((UINTN
) (Source
- (CHAR8
*) Destination
) > (AsciiStrLen (Source
) * sizeof (CHAR16
)));
2013 ReturnValue
= Destination
;
2014 while (*Source
!= '\0') {
2015 *(Destination
++) = (CHAR16
) *(Source
++);
2018 // End the Destination with a NULL.
2020 *Destination
= '\0';
2023 // ASSERT Original Destination is less long than PcdMaximumUnicodeStringLength
2025 ASSERT (StrSize (ReturnValue
) != 0);
2031 Converts an 8-bit value to an 8-bit BCD value.
2033 Converts the 8-bit value specified by Value to BCD. The BCD value is
2036 If Value >= 100, then ASSERT().
2038 @param Value The 8-bit value to convert to BCD. Range 0..99.
2040 @return The BCD value.
2049 ASSERT (Value
< 100);
2050 return (UINT8
) (((Value
/ 10) << 4) | (Value
% 10));
2054 Converts an 8-bit BCD value to an 8-bit value.
2056 Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit
2059 If Value >= 0xA0, then ASSERT().
2060 If (Value & 0x0F) >= 0x0A, then ASSERT().
2062 @param Value The 8-bit BCD value to convert to an 8-bit value.
2064 @return The 8-bit value is returned.
2073 ASSERT (Value
< 0xa0);
2074 ASSERT ((Value
& 0xf) < 0xa);
2075 return (UINT8
) ((Value
>> 4) * 10 + (Value
& 0xf));