2 Unicode and ASCII string primitives.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 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 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
20 [ATTENTION] This function will be deprecated for security reason.
22 Copies one Null-terminated Unicode string to another Null-terminated Unicode
23 string and returns the new Unicode string.
25 This function copies the contents of the Unicode string Source to the Unicode
26 string Destination, and returns Destination. If Source and Destination
27 overlap, then the results are undefined.
29 If Destination is NULL, then ASSERT().
30 If Destination is not aligned on a 16-bit boundary, then ASSERT().
31 If Source is NULL, then ASSERT().
32 If Source is not aligned on a 16-bit boundary, then ASSERT().
33 If Source and Destination overlap, then ASSERT().
34 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
35 PcdMaximumUnicodeStringLength Unicode characters, not including the
36 Null-terminator, then ASSERT().
38 @param Destination A pointer to a Null-terminated Unicode string.
39 @param Source A pointer to a Null-terminated Unicode string.
47 OUT CHAR16
*Destination
,
48 IN CONST CHAR16
*Source
54 // Destination cannot be NULL
56 ASSERT (Destination
!= NULL
);
57 ASSERT (((UINTN
) Destination
& BIT0
) == 0);
60 // Destination and source cannot overlap
62 ASSERT ((UINTN
)(Destination
- Source
) > StrLen (Source
));
63 ASSERT ((UINTN
)(Source
- Destination
) > StrLen (Source
));
65 ReturnValue
= Destination
;
66 while (*Source
!= 0) {
67 *(Destination
++) = *(Source
++);
74 [ATTENTION] This function will be deprecated for security reason.
76 Copies up to a specified length from one Null-terminated Unicode string to
77 another Null-terminated Unicode string and returns the new Unicode string.
79 This function copies the contents of the Unicode string Source to the Unicode
80 string Destination, and returns Destination. At most, Length Unicode
81 characters are copied from Source to Destination. If Length is 0, then
82 Destination is returned unmodified. If Length is greater that the number of
83 Unicode characters in Source, then Destination is padded with Null Unicode
84 characters. If Source and Destination overlap, then the results are
87 If Length > 0 and Destination is NULL, then ASSERT().
88 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
89 If Length > 0 and Source is NULL, then ASSERT().
90 If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().
91 If Source and Destination overlap, then ASSERT().
92 If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
93 PcdMaximumUnicodeStringLength, then ASSERT().
94 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
95 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
98 @param Destination A pointer to a Null-terminated Unicode string.
99 @param Source A pointer to a Null-terminated Unicode string.
100 @param Length The maximum number of Unicode characters to copy.
108 OUT CHAR16
*Destination
,
109 IN CONST CHAR16
*Source
,
120 // Destination cannot be NULL if Length is not zero
122 ASSERT (Destination
!= NULL
);
123 ASSERT (((UINTN
) Destination
& BIT0
) == 0);
126 // Destination and source cannot overlap
128 ASSERT ((UINTN
)(Destination
- Source
) > StrLen (Source
));
129 ASSERT ((UINTN
)(Source
- Destination
) >= Length
);
131 if (PcdGet32 (PcdMaximumUnicodeStringLength
) != 0) {
132 ASSERT (Length
<= PcdGet32 (PcdMaximumUnicodeStringLength
));
135 ReturnValue
= Destination
;
137 while ((*Source
!= L
'\0') && (Length
> 0)) {
138 *(Destination
++) = *(Source
++);
142 ZeroMem (Destination
, Length
* sizeof (*Destination
));
148 Returns the length of a Null-terminated Unicode string.
150 This function returns the number of Unicode characters in the Null-terminated
151 Unicode string specified by String.
153 If String is NULL, then ASSERT().
154 If String is not aligned on a 16-bit boundary, then ASSERT().
155 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
156 PcdMaximumUnicodeStringLength Unicode characters, not including the
157 Null-terminator, then ASSERT().
159 @param String A pointer to a Null-terminated Unicode string.
161 @return The length of String.
167 IN CONST CHAR16
*String
172 ASSERT (String
!= NULL
);
173 ASSERT (((UINTN
) String
& BIT0
) == 0);
175 for (Length
= 0; *String
!= L
'\0'; String
++, Length
++) {
177 // If PcdMaximumUnicodeStringLength is not zero,
178 // length should not more than PcdMaximumUnicodeStringLength
180 if (PcdGet32 (PcdMaximumUnicodeStringLength
) != 0) {
181 ASSERT (Length
< PcdGet32 (PcdMaximumUnicodeStringLength
));
188 Returns the size of a Null-terminated Unicode string in bytes, including the
191 This function returns the size, in bytes, of the Null-terminated Unicode string
194 If String is NULL, then ASSERT().
195 If String is not aligned on a 16-bit boundary, then ASSERT().
196 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
197 PcdMaximumUnicodeStringLength Unicode characters, not including the
198 Null-terminator, then ASSERT().
200 @param String A pointer to a Null-terminated Unicode string.
202 @return The size of String.
208 IN CONST CHAR16
*String
211 return (StrLen (String
) + 1) * sizeof (*String
);
215 Compares two Null-terminated Unicode strings, and returns the difference
216 between the first mismatched Unicode characters.
218 This function compares the Null-terminated Unicode string FirstString to the
219 Null-terminated Unicode string SecondString. If FirstString is identical to
220 SecondString, then 0 is returned. Otherwise, the value returned is the first
221 mismatched Unicode character in SecondString subtracted from the first
222 mismatched Unicode character in FirstString.
224 If FirstString is NULL, then ASSERT().
225 If FirstString is not aligned on a 16-bit boundary, then ASSERT().
226 If SecondString is NULL, then ASSERT().
227 If SecondString is not aligned on a 16-bit boundary, then ASSERT().
228 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
229 than PcdMaximumUnicodeStringLength Unicode characters, not including the
230 Null-terminator, then ASSERT().
231 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
232 than PcdMaximumUnicodeStringLength Unicode characters, not including the
233 Null-terminator, then ASSERT().
235 @param FirstString A pointer to a Null-terminated Unicode string.
236 @param SecondString A pointer to a Null-terminated Unicode string.
238 @retval 0 FirstString is identical to SecondString.
239 @return others FirstString is not identical to SecondString.
245 IN CONST CHAR16
*FirstString
,
246 IN CONST CHAR16
*SecondString
250 // ASSERT both strings are less long than PcdMaximumUnicodeStringLength
252 ASSERT (StrSize (FirstString
) != 0);
253 ASSERT (StrSize (SecondString
) != 0);
255 while ((*FirstString
!= L
'\0') && (*FirstString
== *SecondString
)) {
259 return *FirstString
- *SecondString
;
263 Compares up to a specified length the contents of two Null-terminated Unicode strings,
264 and returns the difference between the first mismatched Unicode characters.
266 This function compares the Null-terminated Unicode string FirstString to the
267 Null-terminated Unicode string SecondString. At most, Length Unicode
268 characters will be compared. If Length is 0, then 0 is returned. If
269 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
270 value returned is the first mismatched Unicode character in SecondString
271 subtracted from the first mismatched Unicode character in FirstString.
273 If Length > 0 and FirstString is NULL, then ASSERT().
274 If Length > 0 and FirstString is not aligned on a 16-bit boundary, then ASSERT().
275 If Length > 0 and SecondString is NULL, then ASSERT().
276 If Length > 0 and SecondString is not aligned on a 16-bit boundary, then ASSERT().
277 If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
278 PcdMaximumUnicodeStringLength, then ASSERT().
279 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more than
280 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
282 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more than
283 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
286 @param FirstString A pointer to a Null-terminated Unicode string.
287 @param SecondString A pointer to a Null-terminated Unicode string.
288 @param Length The maximum number of Unicode characters to compare.
290 @retval 0 FirstString is identical to SecondString.
291 @return others FirstString is not identical to SecondString.
297 IN CONST CHAR16
*FirstString
,
298 IN CONST CHAR16
*SecondString
,
307 // ASSERT both strings are less long than PcdMaximumUnicodeStringLength.
308 // Length tests are performed inside StrLen().
310 ASSERT (StrSize (FirstString
) != 0);
311 ASSERT (StrSize (SecondString
) != 0);
313 if (PcdGet32 (PcdMaximumUnicodeStringLength
) != 0) {
314 ASSERT (Length
<= PcdGet32 (PcdMaximumUnicodeStringLength
));
317 while ((*FirstString
!= L
'\0') &&
318 (*SecondString
!= L
'\0') &&
319 (*FirstString
== *SecondString
) &&
326 return *FirstString
- *SecondString
;
329 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
332 [ATTENTION] This function will be deprecated for security reason.
334 Concatenates one Null-terminated Unicode string to another Null-terminated
335 Unicode string, and returns the concatenated Unicode string.
337 This function concatenates two Null-terminated Unicode strings. The contents
338 of Null-terminated Unicode string Source are concatenated to the end of
339 Null-terminated Unicode string Destination. The Null-terminated concatenated
340 Unicode String is returned. If Source and Destination overlap, then the
341 results are undefined.
343 If Destination is NULL, then ASSERT().
344 If Destination is not aligned on a 16-bit boundary, then ASSERT().
345 If Source is NULL, then ASSERT().
346 If Source is not aligned on a 16-bit boundary, then ASSERT().
347 If Source and Destination overlap, then ASSERT().
348 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
349 than PcdMaximumUnicodeStringLength Unicode characters, not including the
350 Null-terminator, then ASSERT().
351 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
352 PcdMaximumUnicodeStringLength Unicode characters, not including the
353 Null-terminator, then ASSERT().
354 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
355 and Source results in a Unicode string with more than
356 PcdMaximumUnicodeStringLength Unicode characters, not including the
357 Null-terminator, then ASSERT().
359 @param Destination A pointer to a Null-terminated Unicode string.
360 @param Source A pointer to a Null-terminated Unicode string.
368 IN OUT CHAR16
*Destination
,
369 IN CONST CHAR16
*Source
372 StrCpy (Destination
+ StrLen (Destination
), Source
);
375 // Size of the resulting string should never be zero.
376 // PcdMaximumUnicodeStringLength is tested inside StrLen().
378 ASSERT (StrSize (Destination
) != 0);
383 [ATTENTION] This function will be deprecated for security reason.
385 Concatenates up to a specified length one Null-terminated Unicode to the end
386 of another Null-terminated Unicode string, and returns the concatenated
389 This function concatenates two Null-terminated Unicode strings. The contents
390 of Null-terminated Unicode string Source are concatenated to the end of
391 Null-terminated Unicode string Destination, and Destination is returned. At
392 most, Length Unicode characters are concatenated from Source to the end of
393 Destination, and Destination is always Null-terminated. If Length is 0, then
394 Destination is returned unmodified. If Source and Destination overlap, then
395 the results are undefined.
397 If Destination is NULL, then ASSERT().
398 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
399 If Length > 0 and Source is NULL, then ASSERT().
400 If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().
401 If Source and Destination overlap, then ASSERT().
402 If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
403 PcdMaximumUnicodeStringLength, then ASSERT().
404 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
405 than PcdMaximumUnicodeStringLength Unicode characters, not including the
406 Null-terminator, then ASSERT().
407 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
408 PcdMaximumUnicodeStringLength Unicode characters, not including the
409 Null-terminator, then ASSERT().
410 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
411 and Source results in a Unicode string with more than PcdMaximumUnicodeStringLength
412 Unicode characters, not including the Null-terminator, then ASSERT().
414 @param Destination A pointer to a Null-terminated Unicode string.
415 @param Source A pointer to a Null-terminated Unicode string.
416 @param Length The maximum number of Unicode characters to concatenate from
425 IN OUT CHAR16
*Destination
,
426 IN CONST CHAR16
*Source
,
430 UINTN DestinationLen
;
432 DestinationLen
= StrLen (Destination
);
433 StrnCpy (Destination
+ DestinationLen
, Source
, Length
);
434 Destination
[DestinationLen
+ Length
] = L
'\0';
437 // Size of the resulting string should never be zero.
438 // PcdMaximumUnicodeStringLength is tested inside StrLen().
440 ASSERT (StrSize (Destination
) != 0);
446 Returns the first occurrence of a Null-terminated Unicode sub-string
447 in a Null-terminated Unicode string.
449 This function scans the contents of the Null-terminated Unicode string
450 specified by String and returns the first occurrence of SearchString.
451 If SearchString is not found in String, then NULL is returned. If
452 the length of SearchString is zero, then String is
455 If String is NULL, then ASSERT().
456 If String is not aligned on a 16-bit boundary, then ASSERT().
457 If SearchString is NULL, then ASSERT().
458 If SearchString is not aligned on a 16-bit boundary, then ASSERT().
460 If PcdMaximumUnicodeStringLength is not zero, and SearchString
461 or String contains more than PcdMaximumUnicodeStringLength Unicode
462 characters, not including the Null-terminator, then ASSERT().
464 @param String A pointer to a Null-terminated Unicode string.
465 @param SearchString A pointer to a Null-terminated Unicode string to search for.
467 @retval NULL If the SearchString does not appear in String.
468 @return others If there is a match.
474 IN CONST CHAR16
*String
,
475 IN CONST CHAR16
*SearchString
478 CONST CHAR16
*FirstMatch
;
479 CONST CHAR16
*SearchStringTmp
;
482 // ASSERT both strings are less long than PcdMaximumUnicodeStringLength.
483 // Length tests are performed inside StrLen().
485 ASSERT (StrSize (String
) != 0);
486 ASSERT (StrSize (SearchString
) != 0);
488 if (*SearchString
== L
'\0') {
489 return (CHAR16
*) String
;
492 while (*String
!= L
'\0') {
493 SearchStringTmp
= SearchString
;
496 while ((*String
== *SearchStringTmp
)
497 && (*String
!= L
'\0')) {
502 if (*SearchStringTmp
== L
'\0') {
503 return (CHAR16
*) FirstMatch
;
506 if (*String
== L
'\0') {
510 String
= FirstMatch
+ 1;
517 Check if a Unicode character is a decimal character.
519 This internal function checks if a Unicode character is a
520 decimal character. The valid decimal character is from
523 @param Char The character to check against.
525 @retval TRUE If the Char is a decmial character.
526 @retval FALSE If the Char is not a decmial character.
531 InternalIsDecimalDigitCharacter (
535 return (BOOLEAN
) (Char
>= L
'0' && Char
<= L
'9');
539 Convert a Unicode character to upper case only if
540 it maps to a valid small-case ASCII character.
542 This internal function only deal with Unicode character
543 which maps to a valid small-case ASCII character, i.e.
544 L'a' to L'z'. For other Unicode character, the input character
545 is returned directly.
547 @param Char The character to convert.
549 @retval LowerCharacter If the Char is with range L'a' to L'z'.
550 @retval Unchanged Otherwise.
555 InternalCharToUpper (
559 if (Char
>= L
'a' && Char
<= L
'z') {
560 return (CHAR16
) (Char
- (L
'a' - L
'A'));
567 Convert a Unicode character to numerical value.
569 This internal function only deal with Unicode character
570 which maps to a valid hexadecimal ASII character, i.e.
571 L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other
572 Unicode character, the value returned does not make sense.
574 @param Char The character to convert.
576 @return The numerical value converted.
581 InternalHexCharToUintn (
585 if (InternalIsDecimalDigitCharacter (Char
)) {
589 return (10 + InternalCharToUpper (Char
) - L
'A');
593 Check if a Unicode character is a hexadecimal character.
595 This internal function checks if a Unicode character is a
596 decimal character. The valid hexadecimal character is
597 L'0' to L'9', L'a' to L'f', or L'A' to L'F'.
600 @param Char The character to check against.
602 @retval TRUE If the Char is a hexadecmial character.
603 @retval FALSE If the Char is not a hexadecmial character.
608 InternalIsHexaDecimalDigitCharacter (
613 return (BOOLEAN
) (InternalIsDecimalDigitCharacter (Char
) ||
614 (Char
>= L
'A' && Char
<= L
'F') ||
615 (Char
>= L
'a' && Char
<= L
'f'));
619 Convert a Null-terminated Unicode decimal string to a value of
622 This function returns a value of type UINTN by interpreting the contents
623 of the Unicode string specified by String as a decimal number. The format
624 of the input Unicode string String is:
626 [spaces] [decimal digits].
628 The valid decimal digit character is in the range [0-9]. The
629 function will ignore the pad space, which includes spaces or
630 tab characters, before [decimal digits]. The running zero in the
631 beginning of [decimal digits] will be ignored. Then, the function
632 stops at the first character that is a not a valid decimal character
633 or a Null-terminator, whichever one comes first.
635 If String is NULL, then ASSERT().
636 If String is not aligned in a 16-bit boundary, then ASSERT().
637 If String has only pad spaces, then 0 is returned.
638 If String has no pad spaces or valid decimal digits,
640 If the number represented by String overflows according
641 to the range defined by UINTN, then MAX_UINTN is returned.
643 If PcdMaximumUnicodeStringLength is not zero, and String contains
644 more than PcdMaximumUnicodeStringLength Unicode characters, not including
645 the Null-terminator, then ASSERT().
647 @param String A pointer to a Null-terminated Unicode string.
649 @retval Value translated from String.
655 IN CONST CHAR16
*String
660 StrDecimalToUintnS (String
, (CHAR16
**) NULL
, &Result
);
666 Convert a Null-terminated Unicode decimal string to a value of
669 This function returns a value of type UINT64 by interpreting the contents
670 of the Unicode string specified by String as a decimal number. The format
671 of the input Unicode string String is:
673 [spaces] [decimal digits].
675 The valid decimal digit character is in the range [0-9]. The
676 function will ignore the pad space, which includes spaces or
677 tab characters, before [decimal digits]. The running zero in the
678 beginning of [decimal digits] will be ignored. Then, the function
679 stops at the first character that is a not a valid decimal character
680 or a Null-terminator, whichever one comes first.
682 If String is NULL, then ASSERT().
683 If String is not aligned in a 16-bit boundary, then ASSERT().
684 If String has only pad spaces, then 0 is returned.
685 If String has no pad spaces or valid decimal digits,
687 If the number represented by String overflows according
688 to the range defined by UINT64, then MAX_UINT64 is returned.
690 If PcdMaximumUnicodeStringLength is not zero, and String contains
691 more than PcdMaximumUnicodeStringLength Unicode characters, not including
692 the Null-terminator, then ASSERT().
694 @param String A pointer to a Null-terminated Unicode string.
696 @retval Value translated from String.
702 IN CONST CHAR16
*String
707 StrDecimalToUint64S (String
, (CHAR16
**) NULL
, &Result
);
712 Convert a Null-terminated Unicode hexadecimal string to a value of type UINTN.
714 This function returns a value of type UINTN by interpreting the contents
715 of the Unicode string specified by String as a hexadecimal number.
716 The format of the input Unicode string String is:
718 [spaces][zeros][x][hexadecimal digits].
720 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
721 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
722 If "x" appears in the input string, it must be prefixed with at least one 0.
723 The function will ignore the pad space, which includes spaces or tab characters,
724 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
725 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
726 first valid hexadecimal digit. Then, the function stops at the first character that is
727 a not a valid hexadecimal character or NULL, whichever one comes first.
729 If String is NULL, then ASSERT().
730 If String is not aligned in a 16-bit boundary, then ASSERT().
731 If String has only pad spaces, then zero is returned.
732 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
733 then zero is returned.
734 If the number represented by String overflows according to the range defined by
735 UINTN, then MAX_UINTN is returned.
737 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
738 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
741 @param String A pointer to a Null-terminated Unicode string.
743 @retval Value translated from String.
749 IN CONST CHAR16
*String
754 StrHexToUintnS (String
, (CHAR16
**) NULL
, &Result
);
760 Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.
762 This function returns a value of type UINT64 by interpreting the contents
763 of the Unicode string specified by String as a hexadecimal number.
764 The format of the input Unicode string String is
766 [spaces][zeros][x][hexadecimal digits].
768 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
769 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
770 If "x" appears in the input string, it must be prefixed with at least one 0.
771 The function will ignore the pad space, which includes spaces or tab characters,
772 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
773 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
774 first valid hexadecimal digit. Then, the function stops at the first character that is
775 a not a valid hexadecimal character or NULL, whichever one comes first.
777 If String is NULL, then ASSERT().
778 If String is not aligned in a 16-bit boundary, then ASSERT().
779 If String has only pad spaces, then zero is returned.
780 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
781 then zero is returned.
782 If the number represented by String overflows according to the range defined by
783 UINT64, then MAX_UINT64 is returned.
785 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
786 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
789 @param String A pointer to a Null-terminated Unicode string.
791 @retval Value translated from String.
797 IN CONST CHAR16
*String
802 StrHexToUint64S (String
, (CHAR16
**) NULL
, &Result
);
807 Check if a ASCII character is a decimal character.
809 This internal function checks if a Unicode character is a
810 decimal character. The valid decimal character is from
813 @param Char The character to check against.
815 @retval TRUE If the Char is a decmial character.
816 @retval FALSE If the Char is not a decmial character.
821 InternalAsciiIsDecimalDigitCharacter (
825 return (BOOLEAN
) (Char
>= '0' && Char
<= '9');
829 Check if a ASCII character is a hexadecimal character.
831 This internal function checks if a ASCII character is a
832 decimal character. The valid hexadecimal character is
833 L'0' to L'9', L'a' to L'f', or L'A' to L'F'.
836 @param Char The character to check against.
838 @retval TRUE If the Char is a hexadecmial character.
839 @retval FALSE If the Char is not a hexadecmial character.
844 InternalAsciiIsHexaDecimalDigitCharacter (
849 return (BOOLEAN
) (InternalAsciiIsDecimalDigitCharacter (Char
) ||
850 (Char
>= 'A' && Char
<= 'F') ||
851 (Char
>= 'a' && Char
<= 'f'));
854 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
857 [ATTENTION] This function is deprecated for security reason.
859 Convert a Null-terminated Unicode string to a Null-terminated
860 ASCII string and returns the ASCII string.
862 This function converts the content of the Unicode string Source
863 to the ASCII string Destination by copying the lower 8 bits of
864 each Unicode character. It returns Destination.
866 The caller is responsible to make sure Destination points to a buffer with size
867 equal or greater than ((StrLen (Source) + 1) * sizeof (CHAR8)) in bytes.
869 If any Unicode characters in Source contain non-zero value in
870 the upper 8 bits, then ASSERT().
872 If Destination is NULL, then ASSERT().
873 If Source is NULL, then ASSERT().
874 If Source is not aligned on a 16-bit boundary, then ASSERT().
875 If Source and Destination overlap, then ASSERT().
877 If PcdMaximumUnicodeStringLength is not zero, and Source contains
878 more than PcdMaximumUnicodeStringLength Unicode characters, not including
879 the Null-terminator, then ASSERT().
881 If PcdMaximumAsciiStringLength is not zero, and Source contains more
882 than PcdMaximumAsciiStringLength Unicode characters, not including the
883 Null-terminator, then ASSERT().
885 @param Source A pointer to a Null-terminated Unicode string.
886 @param Destination A pointer to a Null-terminated ASCII string.
893 UnicodeStrToAsciiStr (
894 IN CONST CHAR16
*Source
,
895 OUT CHAR8
*Destination
900 ASSERT (Destination
!= NULL
);
903 // ASSERT if Source is long than PcdMaximumUnicodeStringLength.
904 // Length tests are performed inside StrLen().
906 ASSERT (StrSize (Source
) != 0);
909 // Source and Destination should not overlap
911 ASSERT ((UINTN
) (Destination
- (CHAR8
*) Source
) >= StrSize (Source
));
912 ASSERT ((UINTN
) ((CHAR8
*) Source
- Destination
) > StrLen (Source
));
915 ReturnValue
= Destination
;
916 while (*Source
!= '\0') {
918 // If any Unicode characters in Source contain
919 // non-zero value in the upper 8 bits, then ASSERT().
921 ASSERT (*Source
< 0x100);
922 *(Destination
++) = (CHAR8
) *(Source
++);
928 // ASSERT Original Destination is less long than PcdMaximumAsciiStringLength.
929 // Length tests are performed inside AsciiStrLen().
931 ASSERT (AsciiStrSize (ReturnValue
) != 0);
937 [ATTENTION] This function will be deprecated for security reason.
939 Copies one Null-terminated ASCII string to another Null-terminated ASCII
940 string and returns the new ASCII string.
942 This function copies the contents of the ASCII string Source to the ASCII
943 string Destination, and returns Destination. If Source and Destination
944 overlap, then the results are undefined.
946 If Destination is NULL, then ASSERT().
947 If Source is NULL, then ASSERT().
948 If Source and Destination overlap, then ASSERT().
949 If PcdMaximumAsciiStringLength is not zero and Source contains more than
950 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
953 @param Destination A pointer to a Null-terminated ASCII string.
954 @param Source A pointer to a Null-terminated ASCII string.
962 OUT CHAR8
*Destination
,
963 IN CONST CHAR8
*Source
969 // Destination cannot be NULL
971 ASSERT (Destination
!= NULL
);
974 // Destination and source cannot overlap
976 ASSERT ((UINTN
)(Destination
- Source
) > AsciiStrLen (Source
));
977 ASSERT ((UINTN
)(Source
- Destination
) > AsciiStrLen (Source
));
979 ReturnValue
= Destination
;
980 while (*Source
!= 0) {
981 *(Destination
++) = *(Source
++);
988 [ATTENTION] This function will be deprecated for security reason.
990 Copies up to a specified length one Null-terminated ASCII string to another
991 Null-terminated ASCII string and returns the new ASCII string.
993 This function copies the contents of the ASCII string Source to the ASCII
994 string Destination, and returns Destination. At most, Length ASCII characters
995 are copied from Source to Destination. If Length is 0, then Destination is
996 returned unmodified. If Length is greater that the number of ASCII characters
997 in Source, then Destination is padded with Null ASCII characters. If Source
998 and Destination overlap, then the results are undefined.
1000 If Destination is NULL, then ASSERT().
1001 If Source is NULL, then ASSERT().
1002 If Source and Destination overlap, then ASSERT().
1003 If PcdMaximumAsciiStringLength is not zero, and Length is greater than
1004 PcdMaximumAsciiStringLength, then ASSERT().
1005 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1006 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1009 @param Destination A pointer to a Null-terminated ASCII string.
1010 @param Source A pointer to a Null-terminated ASCII string.
1011 @param Length The maximum number of ASCII characters to copy.
1019 OUT CHAR8
*Destination
,
1020 IN CONST CHAR8
*Source
,
1031 // Destination cannot be NULL
1033 ASSERT (Destination
!= NULL
);
1036 // Destination and source cannot overlap
1038 ASSERT ((UINTN
)(Destination
- Source
) > AsciiStrLen (Source
));
1039 ASSERT ((UINTN
)(Source
- Destination
) >= Length
);
1041 if (PcdGet32 (PcdMaximumAsciiStringLength
) != 0) {
1042 ASSERT (Length
<= PcdGet32 (PcdMaximumAsciiStringLength
));
1045 ReturnValue
= Destination
;
1047 while (*Source
!= 0 && Length
> 0) {
1048 *(Destination
++) = *(Source
++);
1052 ZeroMem (Destination
, Length
* sizeof (*Destination
));
1058 Returns the length of a Null-terminated ASCII string.
1060 This function returns the number of ASCII characters in the Null-terminated
1061 ASCII string specified by String.
1063 If Length > 0 and Destination is NULL, then ASSERT().
1064 If Length > 0 and Source is NULL, then ASSERT().
1065 If PcdMaximumAsciiStringLength is not zero and String contains more than
1066 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1069 @param String A pointer to a Null-terminated ASCII string.
1071 @return The length of String.
1077 IN CONST CHAR8
*String
1082 ASSERT (String
!= NULL
);
1084 for (Length
= 0; *String
!= '\0'; String
++, Length
++) {
1086 // If PcdMaximumUnicodeStringLength is not zero,
1087 // length should not more than PcdMaximumUnicodeStringLength
1089 if (PcdGet32 (PcdMaximumAsciiStringLength
) != 0) {
1090 ASSERT (Length
< PcdGet32 (PcdMaximumAsciiStringLength
));
1097 Returns the size of a Null-terminated ASCII string in bytes, including the
1100 This function returns the size, in bytes, of the Null-terminated ASCII string
1101 specified by String.
1103 If String is NULL, then ASSERT().
1104 If PcdMaximumAsciiStringLength is not zero and String contains more than
1105 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1108 @param String A pointer to a Null-terminated ASCII string.
1110 @return The size of String.
1116 IN CONST CHAR8
*String
1119 return (AsciiStrLen (String
) + 1) * sizeof (*String
);
1123 Compares two Null-terminated ASCII strings, and returns the difference
1124 between the first mismatched ASCII characters.
1126 This function compares the Null-terminated ASCII string FirstString to the
1127 Null-terminated ASCII string SecondString. If FirstString is identical to
1128 SecondString, then 0 is returned. Otherwise, the value returned is the first
1129 mismatched ASCII character in SecondString subtracted from the first
1130 mismatched ASCII character in FirstString.
1132 If FirstString is NULL, then ASSERT().
1133 If SecondString is NULL, then ASSERT().
1134 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
1135 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1137 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
1138 than PcdMaximumAsciiStringLength ASCII characters, not including the
1139 Null-terminator, then ASSERT().
1141 @param FirstString A pointer to a Null-terminated ASCII string.
1142 @param SecondString A pointer to a Null-terminated ASCII string.
1144 @retval ==0 FirstString is identical to SecondString.
1145 @retval !=0 FirstString is not identical to SecondString.
1151 IN CONST CHAR8
*FirstString
,
1152 IN CONST CHAR8
*SecondString
1156 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
1158 ASSERT (AsciiStrSize (FirstString
));
1159 ASSERT (AsciiStrSize (SecondString
));
1161 while ((*FirstString
!= '\0') && (*FirstString
== *SecondString
)) {
1166 return *FirstString
- *SecondString
;
1170 Converts a lowercase Ascii character to upper one.
1172 If Chr is lowercase Ascii character, then converts it to upper one.
1174 If Value >= 0xA0, then ASSERT().
1175 If (Value & 0x0F) >= 0x0A, then ASSERT().
1177 @param Chr one Ascii character
1179 @return The uppercase value of Ascii character
1184 InternalBaseLibAsciiToUpper (
1188 return (UINT8
) ((Chr
>= 'a' && Chr
<= 'z') ? Chr
- ('a' - 'A') : Chr
);
1192 Convert a ASCII character to numerical value.
1194 This internal function only deal with Unicode character
1195 which maps to a valid hexadecimal ASII character, i.e.
1196 '0' to '9', 'a' to 'f' or 'A' to 'F'. For other
1197 ASCII character, the value returned does not make sense.
1199 @param Char The character to convert.
1201 @return The numerical value converted.
1206 InternalAsciiHexCharToUintn (
1210 if (InternalIsDecimalDigitCharacter (Char
)) {
1214 return (10 + InternalBaseLibAsciiToUpper (Char
) - 'A');
1219 Performs a case insensitive comparison of two Null-terminated ASCII strings,
1220 and returns the difference between the first mismatched ASCII characters.
1222 This function performs a case insensitive comparison of the Null-terminated
1223 ASCII string FirstString to the Null-terminated ASCII string SecondString. If
1224 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
1225 value returned is the first mismatched lower case ASCII character in
1226 SecondString subtracted from the first mismatched lower case ASCII character
1229 If FirstString is NULL, then ASSERT().
1230 If SecondString is NULL, then ASSERT().
1231 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
1232 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1234 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
1235 than PcdMaximumAsciiStringLength ASCII characters, not including the
1236 Null-terminator, then ASSERT().
1238 @param FirstString A pointer to a Null-terminated ASCII string.
1239 @param SecondString A pointer to a Null-terminated ASCII string.
1241 @retval ==0 FirstString is identical to SecondString using case insensitive
1243 @retval !=0 FirstString is not identical to SecondString using case
1244 insensitive comparisons.
1250 IN CONST CHAR8
*FirstString
,
1251 IN CONST CHAR8
*SecondString
1254 CHAR8 UpperFirstString
;
1255 CHAR8 UpperSecondString
;
1258 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
1260 ASSERT (AsciiStrSize (FirstString
));
1261 ASSERT (AsciiStrSize (SecondString
));
1263 UpperFirstString
= InternalBaseLibAsciiToUpper (*FirstString
);
1264 UpperSecondString
= InternalBaseLibAsciiToUpper (*SecondString
);
1265 while ((*FirstString
!= '\0') && (*SecondString
!= '\0') && (UpperFirstString
== UpperSecondString
)) {
1268 UpperFirstString
= InternalBaseLibAsciiToUpper (*FirstString
);
1269 UpperSecondString
= InternalBaseLibAsciiToUpper (*SecondString
);
1272 return UpperFirstString
- UpperSecondString
;
1276 Compares two Null-terminated ASCII strings with maximum lengths, and returns
1277 the difference between the first mismatched ASCII characters.
1279 This function compares the Null-terminated ASCII string FirstString to the
1280 Null-terminated ASCII string SecondString. At most, Length ASCII characters
1281 will be compared. If Length is 0, then 0 is returned. If FirstString is
1282 identical to SecondString, then 0 is returned. Otherwise, the value returned
1283 is the first mismatched ASCII character in SecondString subtracted from the
1284 first mismatched ASCII character in FirstString.
1286 If Length > 0 and FirstString is NULL, then ASSERT().
1287 If Length > 0 and SecondString is NULL, then ASSERT().
1288 If PcdMaximumAsciiStringLength is not zero, and Length is greater than
1289 PcdMaximumAsciiStringLength, then ASSERT().
1290 If PcdMaximumAsciiStringLength is not zero, and FirstString contains more than
1291 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1293 If PcdMaximumAsciiStringLength is not zero, and SecondString contains more than
1294 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1297 @param FirstString A pointer to a Null-terminated ASCII string.
1298 @param SecondString A pointer to a Null-terminated ASCII string.
1299 @param Length The maximum number of ASCII characters for compare.
1301 @retval ==0 FirstString is identical to SecondString.
1302 @retval !=0 FirstString is not identical to SecondString.
1308 IN CONST CHAR8
*FirstString
,
1309 IN CONST CHAR8
*SecondString
,
1318 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
1320 ASSERT (AsciiStrSize (FirstString
));
1321 ASSERT (AsciiStrSize (SecondString
));
1323 if (PcdGet32 (PcdMaximumAsciiStringLength
) != 0) {
1324 ASSERT (Length
<= PcdGet32 (PcdMaximumAsciiStringLength
));
1327 while ((*FirstString
!= '\0') &&
1328 (*SecondString
!= '\0') &&
1329 (*FirstString
== *SecondString
) &&
1335 return *FirstString
- *SecondString
;
1338 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
1341 [ATTENTION] This function will be deprecated for security reason.
1343 Concatenates one Null-terminated ASCII string to another Null-terminated
1344 ASCII string, and returns the concatenated ASCII string.
1346 This function concatenates two Null-terminated ASCII strings. The contents of
1347 Null-terminated ASCII string Source are concatenated to the end of Null-
1348 terminated ASCII string Destination. The Null-terminated concatenated ASCII
1351 If Destination is NULL, then ASSERT().
1352 If Source is NULL, then ASSERT().
1353 If PcdMaximumAsciiStringLength is not zero and Destination contains more than
1354 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1356 If PcdMaximumAsciiStringLength is not zero and Source contains more than
1357 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1359 If PcdMaximumAsciiStringLength is not zero and concatenating Destination and
1360 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
1361 ASCII characters, then ASSERT().
1363 @param Destination A pointer to a Null-terminated ASCII string.
1364 @param Source A pointer to a Null-terminated ASCII string.
1372 IN OUT CHAR8
*Destination
,
1373 IN CONST CHAR8
*Source
1376 AsciiStrCpy (Destination
+ AsciiStrLen (Destination
), Source
);
1379 // Size of the resulting string should never be zero.
1380 // PcdMaximumUnicodeStringLength is tested inside StrLen().
1382 ASSERT (AsciiStrSize (Destination
) != 0);
1387 [ATTENTION] This function will be deprecated for security reason.
1389 Concatenates up to a specified length one Null-terminated ASCII string to
1390 the end of another Null-terminated ASCII string, and returns the
1391 concatenated ASCII string.
1393 This function concatenates two Null-terminated ASCII strings. The contents
1394 of Null-terminated ASCII string Source are concatenated to the end of Null-
1395 terminated ASCII string Destination, and Destination is returned. At most,
1396 Length ASCII characters are concatenated from Source to the end of
1397 Destination, and Destination is always Null-terminated. If Length is 0, then
1398 Destination is returned unmodified. If Source and Destination overlap, then
1399 the results are undefined.
1401 If Length > 0 and Destination is NULL, then ASSERT().
1402 If Length > 0 and Source is NULL, then ASSERT().
1403 If Source and Destination overlap, then ASSERT().
1404 If PcdMaximumAsciiStringLength is not zero, and Length is greater than
1405 PcdMaximumAsciiStringLength, then ASSERT().
1406 If PcdMaximumAsciiStringLength is not zero, and Destination contains more than
1407 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1409 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1410 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1412 If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and
1413 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
1414 ASCII characters, not including the Null-terminator, then ASSERT().
1416 @param Destination A pointer to a Null-terminated ASCII string.
1417 @param Source A pointer to a Null-terminated ASCII string.
1418 @param Length The maximum number of ASCII characters to concatenate from
1427 IN OUT CHAR8
*Destination
,
1428 IN CONST CHAR8
*Source
,
1432 UINTN DestinationLen
;
1434 DestinationLen
= AsciiStrLen (Destination
);
1435 AsciiStrnCpy (Destination
+ DestinationLen
, Source
, Length
);
1436 Destination
[DestinationLen
+ Length
] = '\0';
1439 // Size of the resulting string should never be zero.
1440 // PcdMaximumUnicodeStringLength is tested inside StrLen().
1442 ASSERT (AsciiStrSize (Destination
) != 0);
1448 Returns the first occurrence of a Null-terminated ASCII sub-string
1449 in a Null-terminated ASCII string.
1451 This function scans the contents of the ASCII string specified by String
1452 and returns the first occurrence of SearchString. If SearchString is not
1453 found in String, then NULL is returned. If the length of SearchString is zero,
1454 then String is returned.
1456 If String is NULL, then ASSERT().
1457 If SearchString is NULL, then ASSERT().
1459 If PcdMaximumAsciiStringLength is not zero, and SearchString or
1460 String contains more than PcdMaximumAsciiStringLength Unicode characters
1461 not including the Null-terminator, then ASSERT().
1463 @param String A pointer to a Null-terminated ASCII string.
1464 @param SearchString A pointer to a Null-terminated ASCII string to search for.
1466 @retval NULL If the SearchString does not appear in String.
1467 @retval others If there is a match return the first occurrence of SearchingString.
1468 If the length of SearchString is zero,return String.
1474 IN CONST CHAR8
*String
,
1475 IN CONST CHAR8
*SearchString
1478 CONST CHAR8
*FirstMatch
;
1479 CONST CHAR8
*SearchStringTmp
;
1482 // ASSERT both strings are less long than PcdMaximumAsciiStringLength
1484 ASSERT (AsciiStrSize (String
) != 0);
1485 ASSERT (AsciiStrSize (SearchString
) != 0);
1487 if (*SearchString
== '\0') {
1488 return (CHAR8
*) String
;
1491 while (*String
!= '\0') {
1492 SearchStringTmp
= SearchString
;
1493 FirstMatch
= String
;
1495 while ((*String
== *SearchStringTmp
)
1496 && (*String
!= '\0')) {
1501 if (*SearchStringTmp
== '\0') {
1502 return (CHAR8
*) FirstMatch
;
1505 if (*String
== '\0') {
1509 String
= FirstMatch
+ 1;
1516 Convert a Null-terminated ASCII decimal string to a value of type
1519 This function returns a value of type UINTN by interpreting the contents
1520 of the ASCII string String as a decimal number. The format of the input
1521 ASCII string String is:
1523 [spaces] [decimal digits].
1525 The valid decimal digit character is in the range [0-9]. The function will
1526 ignore the pad space, which includes spaces or tab characters, before the digits.
1527 The running zero in the beginning of [decimal digits] will be ignored. Then, the
1528 function stops at the first character that is a not a valid decimal character or
1529 Null-terminator, whichever on comes first.
1531 If String has only pad spaces, then 0 is returned.
1532 If String has no pad spaces or valid decimal digits, then 0 is returned.
1533 If the number represented by String overflows according to the range defined by
1534 UINTN, then MAX_UINTN is returned.
1535 If String is NULL, then ASSERT().
1536 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1537 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1540 @param String A pointer to a Null-terminated ASCII string.
1542 @retval Value translated from String.
1547 AsciiStrDecimalToUintn (
1548 IN CONST CHAR8
*String
1553 AsciiStrDecimalToUintnS (String
, (CHAR8
**) NULL
, &Result
);
1559 Convert a Null-terminated ASCII decimal string to a value of type
1562 This function returns a value of type UINT64 by interpreting the contents
1563 of the ASCII string String as a decimal number. The format of the input
1564 ASCII string String is:
1566 [spaces] [decimal digits].
1568 The valid decimal digit character is in the range [0-9]. The function will
1569 ignore the pad space, which includes spaces or tab characters, before the digits.
1570 The running zero in the beginning of [decimal digits] will be ignored. Then, the
1571 function stops at the first character that is a not a valid decimal character or
1572 Null-terminator, whichever on comes first.
1574 If String has only pad spaces, then 0 is returned.
1575 If String has no pad spaces or valid decimal digits, then 0 is returned.
1576 If the number represented by String overflows according to the range defined by
1577 UINT64, then MAX_UINT64 is returned.
1578 If String is NULL, then ASSERT().
1579 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1580 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1583 @param String A pointer to a Null-terminated ASCII string.
1585 @retval Value translated from String.
1590 AsciiStrDecimalToUint64 (
1591 IN CONST CHAR8
*String
1596 AsciiStrDecimalToUint64S (String
, (CHAR8
**) NULL
, &Result
);
1601 Convert a Null-terminated ASCII hexadecimal string to a value of type UINTN.
1603 This function returns a value of type UINTN by interpreting the contents of
1604 the ASCII string String as a hexadecimal number. The format of the input ASCII
1607 [spaces][zeros][x][hexadecimal digits].
1609 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1610 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1611 appears in the input string, it must be prefixed with at least one 0. The function
1612 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1613 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1614 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1615 digit. Then, the function stops at the first character that is a not a valid
1616 hexadecimal character or Null-terminator, whichever on comes first.
1618 If String has only pad spaces, then 0 is returned.
1619 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1622 If the number represented by String overflows according to the range defined by UINTN,
1623 then MAX_UINTN is returned.
1624 If String is NULL, then ASSERT().
1625 If PcdMaximumAsciiStringLength is not zero,
1626 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1627 the Null-terminator, then ASSERT().
1629 @param String A pointer to a Null-terminated ASCII string.
1631 @retval Value translated from String.
1636 AsciiStrHexToUintn (
1637 IN CONST CHAR8
*String
1642 AsciiStrHexToUintnS (String
, (CHAR8
**) NULL
, &Result
);
1648 Convert a Null-terminated ASCII hexadecimal string to a value of type UINT64.
1650 This function returns a value of type UINT64 by interpreting the contents of
1651 the ASCII string String as a hexadecimal number. The format of the input ASCII
1654 [spaces][zeros][x][hexadecimal digits].
1656 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1657 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1658 appears in the input string, it must be prefixed with at least one 0. The function
1659 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1660 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1661 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1662 digit. Then, the function stops at the first character that is a not a valid
1663 hexadecimal character or Null-terminator, whichever on comes first.
1665 If String has only pad spaces, then 0 is returned.
1666 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1669 If the number represented by String overflows according to the range defined by UINT64,
1670 then MAX_UINT64 is returned.
1671 If String is NULL, then ASSERT().
1672 If PcdMaximumAsciiStringLength is not zero,
1673 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1674 the Null-terminator, then ASSERT().
1676 @param String A pointer to a Null-terminated ASCII string.
1678 @retval Value translated from String.
1683 AsciiStrHexToUint64 (
1684 IN CONST CHAR8
*String
1689 AsciiStrHexToUint64S (String
, (CHAR8
**) NULL
, &Result
);
1693 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
1696 [ATTENTION] This function is deprecated for security reason.
1698 Convert one Null-terminated ASCII string to a Null-terminated
1699 Unicode string and returns the Unicode string.
1701 This function converts the contents of the ASCII string Source to the Unicode
1702 string Destination, and returns Destination. The function terminates the
1703 Unicode string Destination by appending a Null-terminator character at the end.
1704 The caller is responsible to make sure Destination points to a buffer with size
1705 equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.
1707 If Destination is NULL, then ASSERT().
1708 If Destination is not aligned on a 16-bit boundary, then ASSERT().
1709 If Source is NULL, then ASSERT().
1710 If Source and Destination overlap, then ASSERT().
1711 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1712 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1714 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
1715 PcdMaximumUnicodeStringLength ASCII characters not including the
1716 Null-terminator, then ASSERT().
1718 @param Source A pointer to a Null-terminated ASCII string.
1719 @param Destination A pointer to a Null-terminated Unicode string.
1721 @return Destination.
1726 AsciiStrToUnicodeStr (
1727 IN CONST CHAR8
*Source
,
1728 OUT CHAR16
*Destination
1731 CHAR16
*ReturnValue
;
1733 ASSERT (Destination
!= NULL
);
1736 // ASSERT Source is less long than PcdMaximumAsciiStringLength
1738 ASSERT (AsciiStrSize (Source
) != 0);
1741 // Source and Destination should not overlap
1743 ASSERT ((UINTN
) ((CHAR8
*) Destination
- Source
) > AsciiStrLen (Source
));
1744 ASSERT ((UINTN
) (Source
- (CHAR8
*) Destination
) >= (AsciiStrSize (Source
) * sizeof (CHAR16
)));
1747 ReturnValue
= Destination
;
1748 while (*Source
!= '\0') {
1749 *(Destination
++) = (CHAR16
)(UINT8
) *(Source
++);
1752 // End the Destination with a NULL.
1754 *Destination
= '\0';
1757 // ASSERT Original Destination is less long than PcdMaximumUnicodeStringLength
1759 ASSERT (StrSize (ReturnValue
) != 0);
1767 Converts an 8-bit value to an 8-bit BCD value.
1769 Converts the 8-bit value specified by Value to BCD. The BCD value is
1772 If Value >= 100, then ASSERT().
1774 @param Value The 8-bit value to convert to BCD. Range 0..99.
1776 @return The BCD value.
1785 ASSERT (Value
< 100);
1786 return (UINT8
) (((Value
/ 10) << 4) | (Value
% 10));
1790 Converts an 8-bit BCD value to an 8-bit value.
1792 Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit
1795 If Value >= 0xA0, then ASSERT().
1796 If (Value & 0x0F) >= 0x0A, then ASSERT().
1798 @param Value The 8-bit BCD value to convert to an 8-bit value.
1800 @return The 8-bit value is returned.
1809 ASSERT (Value
< 0xa0);
1810 ASSERT ((Value
& 0xf) < 0xa);
1811 return (UINT8
) ((Value
>> 4) * 10 + (Value
& 0xf));