Common basic Library Functions\r
\r
Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
return !InternalSafeStringIsOverlap (Str1, Size1 * sizeof(CHAR16), Str2, Size2 * sizeof(CHAR16));\r
}\r
\r
-RETURN_STATUS\r
-StrDecimalToUintnS (\r
- CONST CHAR16 *String,\r
- CHAR16 **EndPointer, OPTIONAL\r
- 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
\r
/**\r
Convert a Null-terminated Unicode hexadecimal string to a value of type\r
- UINTN.\r
+ UINT64.\r
\r
- This function outputs a value of type UINTN by interpreting the contents of\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
\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
+ 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
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
+ the range defined by UINT64.\r
\r
**/\r
RETURN_STATUS\r
-StrHexToUintnS (\r
- CONST CHAR16 *String,\r
- CHAR16 **EndPointer, OPTIONAL\r
- 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
-RETURN_STATUS\r
StrHexToUint64S (\r
CONST CHAR16 *String,\r
CHAR16 **EndPointer, OPTIONAL\r
return Result;\r
}\r
\r
-UINTN\r
-StrDecimalToUintn (\r
- CONST CHAR16 *String\r
- )\r
-{\r
- UINTN Result;\r
-\r
- StrDecimalToUintnS (String, (CHAR16 **) NULL, &Result);\r
- return Result;\r
-}\r
-\r
-UINTN\r
-StrHexToUintn (\r
- CONST CHAR16 *String\r
- )\r
-{\r
- UINTN Result;\r
-\r
- StrHexToUintnS (String, (CHAR16 **) NULL, &Result);\r
- return Result;\r
-}\r
-\r
UINTN\r
StrSize (\r
CONST CHAR16 *String\r
VOID *Memory;\r
\r
ASSERT (Buffer != NULL);\r
- ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));\r
\r
Memory = malloc (AllocationSize);\r
if (Memory != NULL) {\r
)\r
{\r
//\r
- // skip preceeding white space\r
+ // skip preceding white space\r
//\r
while ((*Str != 0) && *Str == L' ') {\r
Str ++;\r
}\r
//\r
- // skip preceeding zeros\r
+ // skip preceding zeros\r
//\r
while ((*Str != 0) && *Str == L'0') {\r
Str ++;\r
)\r
{\r
if (IsHexStr (Str)) {\r
- return StrHexToUintn (Str);\r
+ return (UINTN)StrHexToUint64 (Str);\r
} else {\r
- return StrDecimalToUintn (Str);\r
+ return (UINTN)StrDecimalToUint64 (Str);\r
}\r
}\r
\r