+/**\r
+ Convert a Null-terminated Unicode decimal string to a value of type UINTN.\r
+\r
+ This function outputs a value of type UINTN by interpreting the contents of\r
+ the Unicode string specified by String as a decimal number. The format of the\r
+ input Unicode string String is:\r
+\r
+ [spaces] [decimal digits].\r
+\r
+ The valid decimal digit character is in the range [0-9]. The function will\r
+ ignore the pad space, which includes spaces or tab characters, before\r
+ [decimal digits]. The running zero in the beginning of [decimal digits] will\r
+ be ignored. Then, the function stops at the first character that is a not a\r
+ valid decimal character or a Null-terminator, whichever one comes first.\r
+\r
+ If String is NULL, then ASSERT().\r
+ If Data is NULL, then ASSERT().\r
+ If String is not aligned in a 16-bit boundary, then ASSERT().\r
+ If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
+ PcdMaximumUnicodeStringLength Unicode characters, not including the\r
+ Null-terminator, then ASSERT().\r
+\r
+ If String has no valid decimal digits in the above format, then 0 is stored\r
+ at the location pointed to by Data.\r
+ If the number represented by String exceeds the range defined by UINTN, then\r
+ MAX_UINTN is stored at the location pointed to by Data.\r
+\r
+ If EndPointer is not NULL, a pointer to the character that stopped the scan\r
+ is stored at the location pointed to by EndPointer. If String has no valid\r
+ decimal digits right after the optional pad spaces, the value of String is\r
+ stored at the location pointed to by EndPointer.\r
+\r
+ @param String Pointer to a Null-terminated Unicode string.\r
+ @param EndPointer Pointer to character that stops scan.\r
+ @param Data Pointer to the converted value.\r
+\r
+ @retval RETURN_SUCCESS Value is translated from String.\r
+ @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+ If Data is NULL.\r
+ If PcdMaximumUnicodeStringLength is not\r
+ zero, and String contains more than\r
+ PcdMaximumUnicodeStringLength Unicode\r
+ characters, not including the\r
+ Null-terminator.\r
+ @retval RETURN_UNSUPPORTED If the number represented by String exceeds\r
+ the range defined by UINTN.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StrDecimalToUintnS (\r
+ IN CONST CHAR16 *String,\r
+ OUT CHAR16 **EndPointer, OPTIONAL\r
+ OUT UINTN *Data\r
+ )\r
+{\r
+ ASSERT (((UINTN) String & BIT0) == 0);\r
+\r
+ //\r
+ // 1. Neither String nor Data shall be a null pointer.\r
+ //\r
+ SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER);\r
+ SAFE_STRING_CONSTRAINT_CHECK ((Data != NULL), RETURN_INVALID_PARAMETER);\r
+\r
+ //\r
+ // 2. The length of String shall not be greater than RSIZE_MAX.\r
+ //\r
+ if (RSIZE_MAX != 0) {\r
+ SAFE_STRING_CONSTRAINT_CHECK ((StrnLenS (String, RSIZE_MAX + 1) <= RSIZE_MAX), RETURN_INVALID_PARAMETER);\r
+ }\r
+\r
+ if (EndPointer != NULL) {\r
+ *EndPointer = (CHAR16 *) String;\r
+ }\r
+\r
+ //\r
+ // Ignore the pad spaces (space or tab)\r
+ //\r
+ while ((*String == L' ') || (*String == L'\t')) {\r
+ String++;\r
+ }\r
+\r
+ //\r
+ // Ignore leading Zeros after the spaces\r
+ //\r
+ while (*String == L'0') {\r
+ String++;\r
+ }\r
+\r
+ *Data = 0;\r
+\r
+ while (InternalIsDecimalDigitCharacter (*String)) {\r
+ //\r
+ // If the number represented by String overflows according to the range\r
+ // defined by UINTN, then MAX_UINTN is stored in *Data and\r
+ // RETURN_UNSUPPORTED is returned.\r
+ //\r
+ if (*Data > ((MAX_UINTN - (*String - L'0')) / 10)) {\r
+ *Data = MAX_UINTN;\r
+ if (EndPointer != NULL) {\r
+ *EndPointer = (CHAR16 *) String;\r
+ }\r
+ return RETURN_UNSUPPORTED;\r
+ }\r
+\r
+ *Data = *Data * 10 + (*String - L'0');\r
+ String++;\r
+ }\r
+\r
+ if (EndPointer != NULL) {\r
+ *EndPointer = (CHAR16 *) String;\r
+ }\r
+ return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+ Convert a Null-terminated Unicode decimal string to a value of type UINT64.\r
+\r
+ This function outputs a value of type UINT64 by interpreting the contents of\r
+ the Unicode string specified by String as a decimal number. The format of the\r
+ input Unicode string String is:\r
+\r
+ [spaces] [decimal digits].\r
+\r
+ The valid decimal digit character is in the range [0-9]. The function will\r
+ ignore the pad space, which includes spaces or tab characters, before\r
+ [decimal digits]. The running zero in the beginning of [decimal digits] will\r
+ be ignored. Then, the function stops at the first character that is a not a\r
+ valid decimal character or a Null-terminator, whichever one comes first.\r
+\r
+ If String is NULL, then ASSERT().\r
+ If Data is NULL, then ASSERT().\r
+ If String is not aligned in a 16-bit boundary, then ASSERT().\r
+ If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
+ PcdMaximumUnicodeStringLength Unicode characters, not including the\r
+ Null-terminator, then ASSERT().\r
+\r
+ If String has no valid decimal digits in the above format, then 0 is stored\r
+ at the location pointed to by Data.\r
+ If the number represented by String exceeds the range defined by UINT64, then\r
+ MAX_UINT64 is stored at the location pointed to by Data.\r
+\r
+ If EndPointer is not NULL, a pointer to the character that stopped the scan\r
+ is stored at the location pointed to by EndPointer. If String has no valid\r
+ decimal digits right after the optional pad spaces, the value of String is\r
+ stored at the location pointed to by EndPointer.\r
+\r
+ @param String Pointer to a Null-terminated Unicode string.\r
+ @param EndPointer Pointer to character that stops scan.\r
+ @param Data Pointer to the converted value.\r
+\r
+ @retval RETURN_SUCCESS Value is translated from String.\r
+ @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+ If Data is NULL.\r
+ If PcdMaximumUnicodeStringLength is not\r
+ zero, and String contains more than\r
+ PcdMaximumUnicodeStringLength Unicode\r
+ characters, not including the\r
+ Null-terminator.\r
+ @retval RETURN_UNSUPPORTED If the number represented by String exceeds\r
+ the range defined by UINT64.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StrDecimalToUint64S (\r
+ IN CONST CHAR16 *String,\r
+ OUT CHAR16 **EndPointer, OPTIONAL\r
+ OUT UINT64 *Data\r
+ )\r
+{\r
+ ASSERT (((UINTN) String & BIT0) == 0);\r
+\r
+ //\r
+ // 1. Neither String nor Data shall be a null pointer.\r
+ //\r
+ SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER);\r
+ SAFE_STRING_CONSTRAINT_CHECK ((Data != NULL), RETURN_INVALID_PARAMETER);\r
+\r
+ //\r
+ // 2. The length of String shall not be greater than RSIZE_MAX.\r
+ //\r
+ if (RSIZE_MAX != 0) {\r
+ SAFE_STRING_CONSTRAINT_CHECK ((StrnLenS (String, RSIZE_MAX + 1) <= RSIZE_MAX), RETURN_INVALID_PARAMETER);\r
+ }\r
+\r
+ if (EndPointer != NULL) {\r
+ *EndPointer = (CHAR16 *) String;\r
+ }\r
+\r
+ //\r
+ // Ignore the pad spaces (space or tab)\r
+ //\r
+ while ((*String == L' ') || (*String == L'\t')) {\r
+ String++;\r
+ }\r
+\r
+ //\r
+ // Ignore leading Zeros after the spaces\r
+ //\r
+ while (*String == L'0') {\r
+ String++;\r
+ }\r
+\r
+ *Data = 0;\r
+\r
+ while (InternalIsDecimalDigitCharacter (*String)) {\r
+ //\r
+ // If the number represented by String overflows according to the range\r
+ // defined by UINT64, then MAX_UINT64 is stored in *Data and\r
+ // RETURN_UNSUPPORTED is returned.\r
+ //\r
+ if (*Data > DivU64x32 (MAX_UINT64 - (*String - L'0'), 10)) {\r
+ *Data = MAX_UINT64;\r
+ if (EndPointer != NULL) {\r
+ *EndPointer = (CHAR16 *) String;\r
+ }\r
+ return RETURN_UNSUPPORTED;\r
+ }\r
+\r
+ *Data = MultU64x32 (*Data, 10) + (*String - L'0');\r
+ String++;\r
+ }\r
+\r
+ if (EndPointer != NULL) {\r
+ *EndPointer = (CHAR16 *) String;\r
+ }\r
+ return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+ Convert a Null-terminated Unicode hexadecimal string to a value of type\r
+ UINTN.\r
+\r
+ This function outputs a value of type UINTN by interpreting the contents of\r
+ the Unicode string specified by String as a hexadecimal number. The format of\r
+ the input Unicode string String is:\r
+\r
+ [spaces][zeros][x][hexadecimal digits].\r
+\r
+ The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].\r
+ The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.\r
+ If "x" appears in the input string, it must be prefixed with at least one 0.\r
+ The function will ignore the pad space, which includes spaces or tab\r
+ characters, before [zeros], [x] or [hexadecimal digit]. The running zero\r
+ before [x] or [hexadecimal digit] will be ignored. Then, the decoding starts\r
+ after [x] or the first valid hexadecimal digit. Then, the function stops at\r
+ the first character that is a not a valid hexadecimal character or NULL,\r
+ whichever one comes first.\r
+\r
+ If String is NULL, then ASSERT().\r
+ If Data is NULL, then ASSERT().\r
+ If String is not aligned in a 16-bit boundary, then ASSERT().\r
+ If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
+ PcdMaximumUnicodeStringLength Unicode characters, not including the\r
+ Null-terminator, then ASSERT().\r
+\r
+ If String has no valid hexadecimal digits in the above format, then 0 is\r
+ stored at the location pointed to by Data.\r
+ If the number represented by String exceeds the range defined by UINTN, then\r
+ MAX_UINTN is stored at the location pointed to by Data.\r
+\r
+ If EndPointer is not NULL, a pointer to the character that stopped the scan\r
+ is stored at the location pointed to by EndPointer. If String has no valid\r
+ hexadecimal digits right after the optional pad spaces, the value of String\r
+ is stored at the location pointed to by EndPointer.\r
+\r
+ @param String Pointer to a Null-terminated Unicode string.\r
+ @param EndPointer Pointer to character that stops scan.\r
+ @param Data Pointer to the converted value.\r
+\r
+ @retval RETURN_SUCCESS Value is translated from String.\r
+ @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+ If Data is NULL.\r
+ If PcdMaximumUnicodeStringLength is not\r
+ zero, and String contains more than\r
+ PcdMaximumUnicodeStringLength Unicode\r
+ characters, not including the\r
+ Null-terminator.\r
+ @retval RETURN_UNSUPPORTED If the number represented by String exceeds\r
+ the range defined by UINTN.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StrHexToUintnS (\r
+ IN CONST CHAR16 *String,\r
+ OUT CHAR16 **EndPointer, OPTIONAL\r
+ OUT UINTN *Data\r
+ )\r
+{\r
+ ASSERT (((UINTN) String & BIT0) == 0);\r
+\r
+ //\r
+ // 1. Neither String nor Data shall be a null pointer.\r
+ //\r
+ SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER);\r
+ SAFE_STRING_CONSTRAINT_CHECK ((Data != NULL), RETURN_INVALID_PARAMETER);\r
+\r
+ //\r
+ // 2. The length of String shall not be greater than RSIZE_MAX.\r
+ //\r
+ if (RSIZE_MAX != 0) {\r
+ SAFE_STRING_CONSTRAINT_CHECK ((StrnLenS (String, RSIZE_MAX + 1) <= RSIZE_MAX), RETURN_INVALID_PARAMETER);\r
+ }\r
+\r
+ if (EndPointer != NULL) {\r
+ *EndPointer = (CHAR16 *) String;\r
+ }\r
+\r
+ //\r
+ // Ignore the pad spaces (space or tab)\r
+ //\r
+ while ((*String == L' ') || (*String == L'\t')) {\r
+ String++;\r
+ }\r
+\r
+ //\r
+ // Ignore leading Zeros after the spaces\r
+ //\r
+ while (*String == L'0') {\r
+ String++;\r
+ }\r
+\r
+ if (InternalCharToUpper (*String) == L'X') {\r
+ if (*(String - 1) != L'0') {\r
+ *Data = 0;\r
+ return RETURN_SUCCESS;\r
+ }\r
+ //\r
+ // Skip the 'X'\r
+ //\r
+ String++;\r
+ }\r
+\r
+ *Data = 0;\r
+\r
+ while (InternalIsHexaDecimalDigitCharacter (*String)) {\r
+ //\r
+ // If the number represented by String overflows according to the range\r
+ // defined by UINTN, then MAX_UINTN is stored in *Data and\r
+ // RETURN_UNSUPPORTED is returned.\r
+ //\r
+ if (*Data > ((MAX_UINTN - InternalHexCharToUintn (*String)) >> 4)) {\r
+ *Data = MAX_UINTN;\r
+ if (EndPointer != NULL) {\r
+ *EndPointer = (CHAR16 *) String;\r
+ }\r
+ return RETURN_UNSUPPORTED;\r
+ }\r
+\r
+ *Data = (*Data << 4) + InternalHexCharToUintn (*String);\r
+ String++;\r
+ }\r
+\r
+ if (EndPointer != NULL) {\r
+ *EndPointer = (CHAR16 *) String;\r
+ }\r
+ return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+ Convert a Null-terminated Unicode hexadecimal string to a value of type\r
+ UINT64.\r
+\r
+ This function outputs a value of type UINT64 by interpreting the contents of\r
+ the Unicode string specified by String as a hexadecimal number. The format of\r
+ the input Unicode string String is:\r
+\r
+ [spaces][zeros][x][hexadecimal digits].\r
+\r
+ The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].\r
+ The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.\r
+ If "x" appears in the input string, it must be prefixed with at least one 0.\r
+ The function will ignore the pad space, which includes spaces or tab\r
+ characters, before [zeros], [x] or [hexadecimal digit]. The running zero\r
+ before [x] or [hexadecimal digit] will be ignored. Then, the decoding starts\r
+ after [x] or the first valid hexadecimal digit. Then, the function stops at\r
+ the first character that is a not a valid hexadecimal character or NULL,\r
+ whichever one comes first.\r
+\r
+ If String is NULL, then ASSERT().\r
+ If Data is NULL, then ASSERT().\r
+ If String is not aligned in a 16-bit boundary, then ASSERT().\r
+ If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
+ PcdMaximumUnicodeStringLength Unicode characters, not including the\r
+ Null-terminator, then ASSERT().\r
+\r
+ If String has no valid hexadecimal digits in the above format, then 0 is\r
+ stored at the location pointed to by Data.\r
+ If the number represented by String exceeds the range defined by UINT64, then\r
+ MAX_UINT64 is stored at the location pointed to by Data.\r
+\r
+ If EndPointer is not NULL, a pointer to the character that stopped the scan\r
+ is stored at the location pointed to by EndPointer. If String has no valid\r
+ hexadecimal digits right after the optional pad spaces, the value of String\r
+ is stored at the location pointed to by EndPointer.\r
+\r
+ @param String Pointer to a Null-terminated Unicode string.\r
+ @param EndPointer Pointer to character that stops scan.\r
+ @param Data Pointer to the converted value.\r
+\r
+ @retval RETURN_SUCCESS Value is translated from String.\r
+ @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+ If Data is NULL.\r
+ If PcdMaximumUnicodeStringLength is not\r
+ zero, and String contains more than\r
+ PcdMaximumUnicodeStringLength Unicode\r
+ characters, not including the\r
+ Null-terminator.\r
+ @retval RETURN_UNSUPPORTED If the number represented by String exceeds\r
+ the range defined by UINT64.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StrHexToUint64S (\r
+ IN CONST CHAR16 *String,\r
+ OUT CHAR16 **EndPointer, OPTIONAL\r
+ OUT UINT64 *Data\r
+ )\r
+{\r
+ ASSERT (((UINTN) String & BIT0) == 0);\r
+\r
+ //\r
+ // 1. Neither String nor Data shall be a null pointer.\r
+ //\r
+ SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER);\r
+ SAFE_STRING_CONSTRAINT_CHECK ((Data != NULL), RETURN_INVALID_PARAMETER);\r
+\r
+ //\r
+ // 2. The length of String shall not be greater than RSIZE_MAX.\r
+ //\r
+ if (RSIZE_MAX != 0) {\r
+ SAFE_STRING_CONSTRAINT_CHECK ((StrnLenS (String, RSIZE_MAX + 1) <= RSIZE_MAX), RETURN_INVALID_PARAMETER);\r
+ }\r
+\r
+ if (EndPointer != NULL) {\r
+ *EndPointer = (CHAR16 *) String;\r
+ }\r
+\r
+ //\r
+ // Ignore the pad spaces (space or tab)\r
+ //\r
+ while ((*String == L' ') || (*String == L'\t')) {\r
+ String++;\r
+ }\r
+\r
+ //\r
+ // Ignore leading Zeros after the spaces\r
+ //\r
+ while (*String == L'0') {\r
+ String++;\r
+ }\r
+\r
+ if (InternalCharToUpper (*String) == L'X') {\r
+ if (*(String - 1) != L'0') {\r
+ *Data = 0;\r
+ return RETURN_SUCCESS;\r
+ }\r
+ //\r
+ // Skip the 'X'\r
+ //\r
+ String++;\r
+ }\r
+\r
+ *Data = 0;\r
+\r
+ while (InternalIsHexaDecimalDigitCharacter (*String)) {\r
+ //\r
+ // If the number represented by String overflows according to the range\r
+ // defined by UINT64, then MAX_UINT64 is stored in *Data and\r
+ // RETURN_UNSUPPORTED is returned.\r
+ //\r
+ if (*Data > RShiftU64 (MAX_UINT64 - InternalHexCharToUintn (*String), 4)) {\r
+ *Data = MAX_UINT64;\r
+ if (EndPointer != NULL) {\r
+ *EndPointer = (CHAR16 *) String;\r
+ }\r
+ return RETURN_UNSUPPORTED;\r
+ }\r
+\r
+ *Data = LShiftU64 (*Data, 4) + InternalHexCharToUintn (*String);\r
+ String++;\r
+ }\r
+\r
+ if (EndPointer != NULL) {\r
+ *EndPointer = (CHAR16 *) String;\r
+ }\r
+ return RETURN_SUCCESS;\r
+}\r
+\r