Quick Links:

bal | bbl | bdl | bsl

Public Types | Static Public Member Functions

bdlb::NumericParseUtil Struct Reference

#include <bdlb_numericparseutil.h>

List of all members.

Public Types

typedef bsl::string_view::size_type size_type

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.

See Component bdlb_numericparseutil


Member Typedef Documentation

typedef bsl::string_view::size_type bdlb::NumericParseUtil::size_type

Member Function Documentation

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

static int bdlb::NumericParseUtil::parseDouble ( double *  result,
const bsl::string_view &  inputString 
) [static]
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. 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.

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

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

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.
static int bdlb::NumericParseUtil::parseInt64 ( bsls::Types::Int64 result,
const bsl::string_view &  inputString,
int  base = 10 
) [static]
static int bdlb::NumericParseUtil::parseInt64 ( bsls::Types::Int64 result,
bsl::string_view *  remainder,
const bsl::string_view &  inputString,
int  base = 10 
) [static]

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

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.
static int bdlb::NumericParseUtil::parseShort ( short *  result,
const bsl::string_view &  inputString,
int  base = 10 
) [static]
static int bdlb::NumericParseUtil::parseShort ( short *  result,
bsl::string_view *  remainder,
const bsl::string_view &  inputString,
int  base = 10 
) [static]

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

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.
static int bdlb::NumericParseUtil::parseUint ( unsigned int *  result,
const bsl::string_view &  inputString,
int  base = 10 
) [static]
static int bdlb::NumericParseUtil::parseUint ( unsigned int *  result,
bsl::string_view *  remainder,
const bsl::string_view &  inputString,
int  base = 10 
) [static]

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

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.
static int bdlb::NumericParseUtil::parseUint64 ( bsls::Types::Uint64 result,
const bsl::string_view &  inputString,
int  base = 10 
) [static]
static int bdlb::NumericParseUtil::parseUint64 ( bsls::Types::Uint64 result,
bsl::string_view *  remainder,
const bsl::string_view &  inputString,
int  base = 10 
) [static]

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

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.
static int bdlb::NumericParseUtil::parseUshort ( unsigned short *  result,
const bsl::string_view &  inputString,
int  base = 10 
) [static]
static int bdlb::NumericParseUtil::parseUshort ( unsigned short *  result,
bsl::string_view *  remainder,
const bsl::string_view &  inputString,
int  base = 10 
) [static]

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

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

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

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'.
static int bdlb::NumericParseUtil::parseUnsignedInteger ( bsls::Types::Uint64 result,
const bsl::string_view &  inputString,
int  base,
const bsls::Types::Uint64  maxValue 
) [static]
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]
static int bdlb::NumericParseUtil::parseUnsignedInteger ( bsls::Types::Uint64 result,
const bsl::string_view &  inputString,
int  base,
const bsls::Types::Uint64  maxValue,
int  maxNumDigits 
) [static]
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]

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

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'.

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