BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlb::NumericParseUtil Struct Reference

#include <bdlb_numericparseutil.h>

Public Types

typedef bsl::string_view::size_type size_type
 Shorter name for readability.
 

Static Public Member Functions

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)
 

Detailed Description

This struct provides a namespace for a suite of stateless procedures that perform parsing functionality for numbers.

Member Typedef Documentation

◆ size_type

Member Function Documentation

◆ characterToDigit()

static int bdlb::NumericParseUtil::characterToDigit ( char  character,
int  base 
)
static

Determine whether the specified character represents a digit in the specified base; return the numeric equivalent if so, and -1 otherwise. The behavior is undefined if either character or base is 0 and 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]).

◆ parseDouble() [1/2]

static int bdlb::NumericParseUtil::parseDouble ( double *  result,
bsl::string_view remainder,
const bsl::string_view inputString 
)
static

Parse the specified inputString for a sequence of characters matching the production rule <DOUBLE> (see {Grammar Production Rules}) 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. Return zero on success, and a non-zero value otherwise. The value of result is unchanged if a parse failure occurs unless it is a range error (value ERANGE from <cerrno>). In case of ERANGE return value result will be set to zero on underflow and infinity in case of overflow, with the appropriate sign. The behavior is undefined unless the current numeric locale is the "C" locale, such that strcmp(setlocale(LC_NUMERIC, 0), "C") == 0. For more information see {Floating Point Values}.

◆ parseDouble() [2/2]

int bdlb::NumericParseUtil::parseDouble ( double *  result,
const bsl::string_view inputString 
)
inlinestatic

◆ parseInt() [1/2]

static int bdlb::NumericParseUtil::parseInt ( int *  result,
bsl::string_view remainder,
const bsl::string_view inputString,
int  base = 10 
)
static

A parse failure can occur for the following reasons:

  1. The inputString is empty.
  2. The first character of inputString is not a valid digit in base, or an optional sign followed by a valid digit.

◆ parseInt() [2/2]

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. 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]).

◆ parseInt64() [1/2]

static int bdlb::NumericParseUtil::parseInt64 ( bsls::Types::Int64 result,
bsl::string_view remainder,
const bsl::string_view inputString,
int  base = 10 
)
static

A parse failure can occur for the following reasons:

  1. The inputString is empty.
  2. The first character of inputString is not a valid digit in base, or an optional sign followed by a valid digit.

◆ parseInt64() [2/2]

int bdlb::NumericParseUtil::parseInt64 ( bsls::Types::Int64 result,
const bsl::string_view inputString,
int  base = 10 
)
inlinestatic

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. 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]).

◆ parseShort() [1/2]

static int bdlb::NumericParseUtil::parseShort ( short *  result,
bsl::string_view remainder,
const bsl::string_view inputString,
int  base = 10 
)
static

A parse failure can occur for the following reasons:

  1. The inputString is empty.
  2. The first character of inputString is not a valid digit in base, or an optional sign followed by a valid digit.

◆ parseShort() [2/2]

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. 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]).

◆ parseSignedInteger() [1/2]

static int bdlb::NumericParseUtil::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

A parse failure can occur for the following reasons:

  1. The parsed string is not a <NUMBER>, i.e., does not contain an optional sign followed by at least one digit.
  2. The first digit in inputString is larger than maxValue or smaller than minValue.
  3. The first digit is not a valid number for the base.

◆ parseSignedInteger() [2/2]

int bdlb::NumericParseUtil::parseSignedInteger ( bsls::Types::Int64 result,
const bsl::string_view inputString,
int  base,
const bsls::Types::Int64  minValue,
const bsls::Types::Int64  maxValue 
)
inlinestatic

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. 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 ]).

◆ parseUint() [1/2]

static int bdlb::NumericParseUtil::parseUint ( unsigned int *  result,
bsl::string_view remainder,
const bsl::string_view inputString,
int  base = 10 
)
static

A parse failure can occur for the following reasons:

  1. The inputString is empty.
  2. The first character of inputString is not a valid digit in base, or an optional sign followed by a valid digit.

◆ parseUint() [2/2]

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. 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]).

◆ parseUint64() [1/2]

static int bdlb::NumericParseUtil::parseUint64 ( bsls::Types::Uint64 result,
bsl::string_view remainder,
const bsl::string_view inputString,
int  base = 10 
)
static

A parse failure can occur for the following reasons:

  1. The inputString is empty.
  2. The first character of inputString is not a valid digit in base, or an optional sign followed by a valid digit.

◆ parseUint64() [2/2]

int bdlb::NumericParseUtil::parseUint64 ( bsls::Types::Uint64 result,
const bsl::string_view inputString,
int  base = 10 
)
inlinestatic

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. 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]).

◆ parseUnsignedInteger() [1/4]

static int bdlb::NumericParseUtil::parseUnsignedInteger ( bsls::Types::Uint64 result,
bsl::string_view remainder,
const bsl::string_view inputString,
int  base,
const bsls::Types::Uint64  maxValue 
)
static

◆ parseUnsignedInteger() [2/4]

static int bdlb::NumericParseUtil::parseUnsignedInteger ( bsls::Types::Uint64 result,
bsl::string_view remainder,
const bsl::string_view inputString,
int  base,
const bsls::Types::Uint64  maxValue,
int  maxNumDigits 
)
static

A parse failure can occur for the following reasons:

  1. The inputString is not a <POSITIVE_NUMBER>, i.e., does not begin with a digit.
  2. The first digit in inputString is larger than maxValue.
  3. The first digit is not a valid number for the base.

◆ parseUnsignedInteger() [3/4]

int bdlb::NumericParseUtil::parseUnsignedInteger ( bsls::Types::Uint64 result,
const bsl::string_view inputString,
int  base,
const bsls::Types::Uint64  maxValue 
)
inlinestatic

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. 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 ]).

◆ parseUnsignedInteger() [4/4]

int bdlb::NumericParseUtil::parseUnsignedInteger ( bsls::Types::Uint64 result,
const bsl::string_view inputString,
int  base,
const bsls::Types::Uint64  maxValue,
int  maxNumDigits 
)
inlinestatic

◆ parseUshort() [1/2]

static int bdlb::NumericParseUtil::parseUshort ( unsigned short *  result,
bsl::string_view remainder,
const bsl::string_view inputString,
int  base = 10 
)
static

A parse failure can occur for the following reasons:

  1. The inputString is empty.
  2. The first character of inputString is not a valid digit in base, or an optional sign followed by a valid digit.

◆ parseUshort() [2/2]

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. 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]).


The documentation for this struct was generated from the following file: