Parse an unsigned integer not exceeding maxValue from a string.

Synopsis

Declared in <bdlb_numericparseutil.h>

static
int
parseUnsignedInteger(
    bsls::Types::Uint64* result,
    std::string_view const& inputString,
    int base,
    bsls::Types::Uint64 const maxValue);

Description

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.

Return Value

0 on success, and a non‐zero value otherwise

Parameters

Name

Description

result

location to store the parsed value

inputString

text to parse

base

numeric base in [2 .. 36]

maxValue

highest acceptable parsed value

Created with MrDocs