Quick Links:

bal | bbl | bdl | bsl

Public Types | Static Public Member Functions

bdljsn::NumberUtil_ImpUtil Struct Reference

#include <bdljsn_numberutil.h>

List of all members.

Public Types

enum  { k_EXPONENT_OUT_OF_RANGE = -1 }

Static Public Member Functions

static int appendDigits (bsls::Types::Uint64 *result, bsls::Types::Uint64 startingValue, const bsl::string_view &digits)
static int asInteger (bsls::Types::Uint64 *result, const bsl::string_view &value)
template<class t_INTEGER_TYPE >
static int asInteger (t_INTEGER_TYPE *result, const bsl::string_view &value)
template<class t_INTEGER_TYPE >
static int asIntegerDispatchImp (t_INTEGER_TYPE *result, const bsl::string_view &value, bslmf::SelectTraitCase< NumberUtil_IsSigned >)
template<class t_INTEGER_TYPE >
static int asIntegerDispatchImp (t_INTEGER_TYPE *result, const bsl::string_view &value, bslmf::SelectTraitCase<>)
static void decompose (bool *isNegative, bsl::string_view::const_iterator *integerBegin, bsl::string_view::const_iterator *integerEnd, bsl::string_view::const_iterator *fractionBegin, bsl::string_view::const_iterator *fractionEnd, bool *isExponentNegative, bsl::string_view::const_iterator *exponentBegin, bsl::string_view::const_iterator *significantDigitsBegin, bsl::string_view::const_iterator *significantDigitsEnd, bsls::Types::Int64 *significantDigitsBias, const bsl::string_view &value)
static void logUnparseableJsonNumber (const bsl::string_view &value)

Detailed Description

[!PRIVATE!] This private implementation struct provides a namespace for a suite of functions used to help implement NumberUtil. These functions are private to this component and should not be used by clients.

See Component bdljsn_numberutil


Member Enumeration Documentation

anonymous enum
Enumerator:
k_EXPONENT_OUT_OF_RANGE 

exponent is out of a supported range


Member Function Documentation

static int bdljsn::NumberUtil_ImpUtil::appendDigits ( bsls::Types::Uint64 result,
bsls::Types::Uint64  startingValue,
const bsl::string_view &  digits 
) [static]

Load the specified result by appending the specified digits to the specified startingValue. Return 0 on success, NumberUtil::k_OVERFLOW if the result cannot be represented in a Uint64. For example, appending "345" to 12 will return a result of 12345.

static int bdljsn::NumberUtil_ImpUtil::asInteger ( bsls::Types::Uint64 result,
const bsl::string_view &  value 
) [static]
template<class t_INTEGER_TYPE >
static int bdljsn::NumberUtil_ImpUtil::asInteger ( t_INTEGER_TYPE *  result,
const bsl::string_view &  value 
) [static]

These function overloads implement NumberUtil::asInteger, and are documented there.

template<class t_INTEGER_TYPE >
static int bdljsn::NumberUtil_ImpUtil::asIntegerDispatchImp ( t_INTEGER_TYPE *  result,
const bsl::string_view &  value,
bslmf::SelectTraitCase< NumberUtil_IsSigned  
) [static]
template<class t_INTEGER_TYPE >
static int bdljsn::NumberUtil_ImpUtil::asIntegerDispatchImp ( t_INTEGER_TYPE *  result,
const bsl::string_view &  value,
bslmf::SelectTraitCase<>   
) [static]

These functions are the template dispatched implementations for the NumberUtil_ImpUtil::asInteger template function, and serve distinguish the signed from the (default-case) unsigned implementation. These functions are documented by NumberUtil::asInteger.

static void bdljsn::NumberUtil_ImpUtil::decompose ( bool *  isNegative,
bsl::string_view::const_iterator *  integerBegin,
bsl::string_view::const_iterator *  integerEnd,
bsl::string_view::const_iterator *  fractionBegin,
bsl::string_view::const_iterator *  fractionEnd,
bool *  isExponentNegative,
bsl::string_view::const_iterator *  exponentBegin,
bsl::string_view::const_iterator *  significantDigitsBegin,
bsl::string_view::const_iterator *  significantDigitsEnd,
bsls::Types::Int64 significantDigitsBias,
const bsl::string_view &  value 
) [static]

Decompose the specified value into constituent elements, loading the specified isNegative with a flag indicating if value is negative, the specified integerBegin and integerEnd with the beginning and end of the integer portion of value, the specified fractionBegin and fractionEnd with the beginning and end of the fraction portion of value, the specified isExponentNegative with a flag indicating whether the exponent of value is negative, the specified exponentBegin with the beginning of the exponent part of value, the specified significantDigitsBegin and significantDigitsEnd with the beginning and end of the significant digits of value, and the specified significantDigitsBias with a bias to add to the exponent when considering the value of the significant digits. The range of significant digits returned by this function may include a . character (which should simply be ignored when considering the significant digits). For example, "-12.30e-4" would return isNegative as true, the integer portion would be "12", the fractional portion would be "30", isExponentNegative would be true, exponentBegin would point to 4, the significant digits would be "12.3" and the significantDigitsBias would be -1. If there is no fraction in value, fractionBegin and fractionEnd will both equal exponentBegin. If there is no exponent in value exponentBegin will be value.end(). The behavior is undefined unless NumberUtil::isValidNumber(value) is true.

Note that if *significantDigitsBegin is 0 then value must be 0. Also, note that the end of the exponent is (implicitly) value.end(). Finally, note that the range of significant digits returned and significantDigitBias are useful when considering a canonical representation for a JSON Number, which consists of a whole number (with leading and trailing zeroes removed) and an exponent. For example, "1.45e-1" would have a canonical representation 145e-3. The returned significant digits range returned by this function represents the whole number part of this canonical representation (ignoring a . character if it appears), and significantDigitBias can be added to the exponent of value to get the canonical exponent for the significant digits. For example, the value "1.45e-1", which has a canonical representation 145e-3, would return a significant digits of "1.45" (ignore the . for the canonical significant digits) and a significantDigitsBias of -2 (which is added to the exponent of value, -3, to get the canonical exponent). A bias is returned, rather than a canonical exponent, because the bias is trivially derived from tokenizing value (and does not require more costly computation, in cases where it is not needed).

static void bdljsn::NumberUtil_ImpUtil::logUnparseableJsonNumber ( const bsl::string_view &  value  )  [static]

Log the specified value (for which isValidNumber should be true) could not be correctly parsed into a binary floating point representation. Note that this function should be unreachable (and no test input has been found for which it is needed) but exists to record an issue in case some gap were found between the JSON number specification and the underlying floating point parsing functions (whose quality may be outside of our control and vary by platform).


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