This struct provides a namespace for a suite of stateless procedures that perform parsing functionality for numbers.
See bdlb_numericparseutil
|
| static int | characterToDigit (char character, int base) |
| |
| static int | parseDouble (double *result, const bsl::string_view &inputString) |
| |
| static int | parseDouble (double *result, bsl::string_view *remainder, const bsl::string_view &inputString) |
| |
| static int | parseInt (int *result, const bsl::string_view &inputString, int base=10) |
| |
| static int | parseInt (int *result, bsl::string_view *remainder, const bsl::string_view &inputString, int base=10) |
| |
| static int | parseInt64 (bsls::Types::Int64 *result, const bsl::string_view &inputString, int base=10) |
| |
| static int | parseInt64 (bsls::Types::Int64 *result, bsl::string_view *remainder, const bsl::string_view &inputString, int base=10) |
| |
| static int | parseShort (short *result, const bsl::string_view &inputString, int base=10) |
| |
| static int | parseShort (short *result, bsl::string_view *remainder, const bsl::string_view &inputString, int base=10) |
| |
| static int | parseUint (unsigned int *result, const bsl::string_view &inputString, int base=10) |
| |
| static int | parseUint (unsigned int *result, bsl::string_view *remainder, const bsl::string_view &inputString, int base=10) |
| |
| static int | parseUint64 (bsls::Types::Uint64 *result, const bsl::string_view &inputString, int base=10) |
| |
| static int | parseUint64 (bsls::Types::Uint64 *result, bsl::string_view *remainder, const bsl::string_view &inputString, int base=10) |
| |
| static int | parseUshort (unsigned short *result, const bsl::string_view &inputString, int base=10) |
| |
| static int | parseUshort (unsigned short *result, bsl::string_view *remainder, const bsl::string_view &inputString, int base=10) |
| |
| static int | parseSignedInteger (bsls::Types::Int64 *result, const bsl::string_view &inputString, int base, const bsls::Types::Int64 minValue, const bsls::Types::Int64 maxValue) |
| |
| static int | parseSignedInteger (bsls::Types::Int64 *result, bsl::string_view *remainder, const bsl::string_view &inputString, int base, const bsls::Types::Int64 minValue, const bsls::Types::Int64 maxValue) |
| |
| static int | parseUnsignedInteger (bsls::Types::Uint64 *result, const bsl::string_view &inputString, int base, const bsls::Types::Uint64 maxValue) |
| |
| static int | parseUnsignedInteger (bsls::Types::Uint64 *result, bsl::string_view *remainder, const bsl::string_view &inputString, int base, const bsls::Types::Uint64 maxValue) |
| |
| static int | parseUnsignedInteger (bsls::Types::Uint64 *result, const bsl::string_view &inputString, int base, const bsls::Types::Uint64 maxValue, int maxNumDigits) |
| |
| static int | parseUnsignedInteger (bsls::Types::Uint64 *result, bsl::string_view *remainder, const bsl::string_view &inputString, int base, const bsls::Types::Uint64 maxValue, int maxNumDigits) |
| |
| int bdlb::NumericParseUtil::parseInt |
( |
int * |
result, |
|
|
const bsl::string_view & |
inputString, |
|
|
int |
base = 10 |
|
) |
| |
|
inlinestatic |
Parse the specified inputString for the maximal sequence of characters forming an <INT> (see {Grammar Production Rules}) in the optionally specified base or in base 10 if base is not specified, and place into the specified result the corresponding value. Optionally specify remainder, in which to store the remainder of the inputString immediately following the successfully parsed text, or the position at which a parse failure was detected. If the parsed number is outside of the [INT_MIN .. INT_MAX] range the result will be the longest number that does not over/underflow and remainder start at the first digit that would make the number too large/small. Return zero on success, and a non-zero value otherwise. The value of result is unchanged if a parse failure occurs.
- Precondition
- The behavior is undefined unless
2 <= base and base <= 36 (i.e., bases where digits are representable by characters in the range [0-9], [a-z], or [A-Z]).
A parse failure can occur for the following reasons:
- The
inputString is empty.
- The first character of
inputString is not a valid digit in base, or an optional sign followed by a valid digit.
Parse the specified inputString for the maximal sequence of characters forming a valid <INT64> (see {Grammar Production Rules}) in the optionally specified base or in base 10 if base is not specified, and place into the specified result the corresponding value. Optionally specify remainder, in which to store the remainder of the inputString immediately following the successfully parsed text, or the position at which a parse failure was detected. If the parsed number is outside of the [-0x8000000000000000uLL .. 0x7FFFFFFFFFFFFFFFull] range the result will be the longest number that does not over/underflow and remainder will start at the first digit that would make the number too large/small. Return zero on success, and a non-zero value otherwise. The value of result is unchanged if a parse failure occurs.
- Precondition
- The behavior is undefined unless
2 <= base and base <= 36 (i.e., bases where digits are representable by characters in the range [0-9], [a-z], or [A-Z]).
A parse failure can occur for the following reasons:
- The
inputString is empty.
- The first character of
inputString is not a valid digit in base, or an optional sign followed by a valid digit.
| int bdlb::NumericParseUtil::parseShort |
( |
short * |
result, |
|
|
const bsl::string_view & |
inputString, |
|
|
int |
base = 10 |
|
) |
| |
|
inlinestatic |
Parse the specified inputString for the maximal sequence of characters forming a valid <SHORT> (see {Grammar Production Rules}) in the optionally specified base or in base 10 if base is not specified, and place into the specified result the corresponding value. Optionally specify remainder, in which to store the remainder of the inputString immediately following the successfully parsed text, or the position at which a parse failure was detected. If the parsed number is outside of the [SHRT_MIN .. SHRT_MAX] range the result will be the longest number that does not over/underflow and remainder will start at the first digit that would make the number too large/small. Return zero on success, and a non-zero value otherwise. The value of result is unchanged if a parse failure occurs.
- Precondition
- The behavior is undefined unless
2 <= base and base <= 36 (i.e., bases where digits are representable by characters in the range [0-9], [a-z] or [A-Z]).
A parse failure can occur for the following reasons:
- The
inputString is empty.
- The first character of
inputString is not a valid digit in base, or an optional sign followed by a valid digit.
Parse the specified inputString for an optional sign followed by a sequence of characters representing digits in the specified base, consuming the maximum that will form a number whose value is less than or equal to the specified maxValue and greater than or equal to the specified minValue. Place into the specified result the extracted value. Optionally specify remainder, in which to store the remainder of the inputString immediately following the successfully parsed text, or the position at which a parse failure was detected. Return 0 on success, and a non-zero value otherwise. The value of result is unchanged if a parse failure occurs.
- Precondition
- The behavior is undefined unless
maxValue a positive integer, and minValue is negative (this is required to allow for efficient implementation). The behavior is also undefined unless 2 <= base and base <= 36, (i.e., bases where digits are representable by characters [ 0 .. 9 ], [ a .. z ] or [ A .. Z ]).
A parse failure can occur for the following reasons:
- The parsed string is not a
<NUMBER>, i.e., does not contain an optional sign followed by at least one digit.
- The first digit in
inputString is larger than maxValue or smaller than minValue.
- The first digit is not a valid number for the
base.
| int bdlb::NumericParseUtil::parseUint |
( |
unsigned int * |
result, |
|
|
const bsl::string_view & |
inputString, |
|
|
int |
base = 10 |
|
) |
| |
|
inlinestatic |
Parse the specified inputString for the maximal sequence of characters forming an <UNSIGNED> (see {Grammar Production Rules}) in the optionally specified base or in base 10 if base is not specified, and place into the specified result the corresponding value. Optionally specify remainder, in which to store the remainder of the inputString immediately following the successfully parsed text, or the position at which a parse failure was detected. If the parsed number is outside of the [0 .. UINT_MAX] range the result will be the longest number that does not overflow and remainder will start at the first digit that would make the number too large. Return zero on success, and a non-zero value otherwise. The value of result is unchanged if a parse failure occurs.
- Precondition
- The behavior is undefined unless
2 <= base and base <= 36 (i.e., bases where digits are representable by characters in the range [0-9], [a-z], or [A-Z]).
A parse failure can occur for the following reasons:
- The
inputString is empty.
- The first character of
inputString is not a valid digit in base, or an optional sign followed by a valid digit.
Parse the specified inputString for the maximal sequence of characters forming a valid <UNSIGNED64> (see {Grammar Production Rules}) in the optionally specified base or in base 10 if base is not specified, and place into the specified result the corresponding value. Optionally specify remainder, in which to store the remainder of the inputString immediately following the successfully parsed text, or the position at which a parse failure was detected. If the parsed number is outside of the [0 .. 0XFFFFFFFFFFFFFFFF] range the result will be the longest number that does not overflow and remainder will start at the first digit that would make the number too large. Return zero on success, and a non-zero value otherwise. The value of result is unchanged if a parse failure occurs.
- Precondition
- The behavior is undefined unless
2 <= base and base <= 36 (i.e., bases where digits are representable by characters in the range [0-9], [a-z], or [A-Z]).
A parse failure can occur for the following reasons:
- The
inputString is empty.
- The first character of
inputString is not a valid digit in base, or an optional sign followed by a valid digit.
Parse the specified inputString for a sequence of characters representing digits in the specified base, consuming the maximum up to the optionally specified maxNumDigits that form a number whose value does not exceed the specified maxValue. Place into the specified result the extracted value. Optionally specify remainder, in which to store the remainder of the inputString immediately following the successfully parsed text, or the position at which a parse failure was detected. Return 0 on success, and a non-zero value otherwise. The value of result is unchanged if a parse failure occurs. If maxNumDigits is not specified, it defaults to a number larger than the number of possible digits in an unsigned 64-bit integer.
- Precondition
- The behavior is undefined unless
2 < = base and base <= 36 (i.e., bases where digits are representable by characters [ 0 .. 9 ], [ a .. z ] or [ A .. Z ]).
A parse failure can occur for the following reasons:
- The
inputString is not a <POSITIVE_NUMBER>, i.e., does not begin with a digit.
- The first digit in
inputString is larger than maxValue.
- The first digit is not a valid number for the
base.
| int bdlb::NumericParseUtil::parseUshort |
( |
unsigned short * |
result, |
|
|
const bsl::string_view & |
inputString, |
|
|
int |
base = 10 |
|
) |
| |
|
inlinestatic |
Parse the specified inputString for the maximal sequence of characters forming a valid <USHORT> (see {Grammar Production Rules}) in the optionally specified base or in base 10 if base is not specified, and place into the specified result the corresponding value. Optionally specify remainder, in which to store the remainder of the inputString immediately following the successfully parsed text, or the position at which a parse failure was detected. If the parsed number is outside of the [0 .. USHRT_MAX] range the result will be the longest number that does not over/underflow and remainder will start at the first digit that would make the number too large/small. Return zero on success, and a non-zero value otherwise. The value of result is unchanged if a parse failure occurs.
- Precondition
- The behavior is undefined unless
2 <= base and base <= 36 (i.e., bases where digits are representable by characters in the range [0-9], [a-z] or [A-Z]).
A parse failure can occur for the following reasons:
- The
inputString is empty.
- The first character of
inputString is not a valid digit in base, or an optional sign followed by a valid digit.