BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdljsn::NumberUtil_ImpUtil Struct Reference

#include <bdljsn_numberutil.h>

Public Types

enum  { k_EXPONENT_OUT_OF_RANGE = -1 }
 

Public Member Functions

template<class t_TYPE >
int asInteger (t_TYPE *result, const bsl::string_view &value)
 

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, bool *isExpNegative, bsl::string_view *integer, bsl::string_view *fraction, bsl::string_view *exponent, bsl::string_view *significantDigits, bsls::Types::Int64 *significantDigitsBias, bsl::string_view::size_type *significantDigitsDotOffset, 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.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
k_EXPONENT_OUT_OF_RANGE 

Member Function Documentation

◆ appendDigits()

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.

◆ asInteger() [1/3]

int bdljsn::NumberUtil_ImpUtil::asInteger ( bsls::Types::Uint64 result,
const bsl::string_view value 
)
inlinestatic

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

◆ asInteger() [2/3]

template<class t_INTEGER_TYPE >
static int bdljsn::NumberUtil_ImpUtil::asInteger ( t_INTEGER_TYPE *  result,
const bsl::string_view value 
)
static

◆ asInteger() [3/3]

template<class t_TYPE >
int bdljsn::NumberUtil_ImpUtil::asInteger ( t_TYPE *  result,
const bsl::string_view value 
)

◆ asIntegerDispatchImp() [1/2]

template<class t_INTEGER_TYPE >
int bdljsn::NumberUtil_ImpUtil::asIntegerDispatchImp ( t_INTEGER_TYPE *  result,
const bsl::string_view value,
bslmf::SelectTraitCase< NumberUtil_IsSigned  
)
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.

◆ asIntegerDispatchImp() [2/2]

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

◆ decompose()

static void bdljsn::NumberUtil_ImpUtil::decompose ( bool *  isNegative,
bool *  isExpNegative,
bsl::string_view integer,
bsl::string_view fraction,
bsl::string_view exponent,
bsl::string_view significantDigits,
bsls::Types::Int64 significantDigitsBias,
bsl::string_view::size_type significantDigitsDotOffset,
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 isExponentNegative with a flag indicating whether the exponent of value is negative, the specified integer with the integer portion of value, the specified fraction with the fraction portion of value, the specified exponent with the exponent portion of value, the specified significantDigits with the significant digits of value, the specified significantDigitsBias with a bias to add to the exponent when considering the value of the significant digits, and the significantDigitsDotOffset with the offset of the . character in significantDigits (if one exists). The returned significantDigits may include a . character (whose offset into significantDigits is given by significantDigitsOffset) which should simply be ignored when considering the significant digits. If significantDigits does not include a . character, significantDigitsOffset will be bsl::string_view::npos. The behavior is undefined unless NumberUtil::isValidNumber(value) is true. Note that if significantDigits[0] is 0 then value must be 0.

For example, here are some examples of decompose results for an input value (isNegative and isExpNegative are omitted for readability):

| value | int | frac | exp | sigDigit | sigDotOff | sigBias |
|----------|-------|-------|-----|----------|-----------|---------|
| "0.00" | "0" | "00" | "" | "0" | npos | 0 |
| "100e+1" | "100" | "" | "1" | "1" | npos | 2 |
| "0.020" | "0" | "020" | "" | "2" | npos | -2 |
| "1.12e5" | "1" | "12" | "5" | "1.12" | 1 | -2 |
| "34.50" | "34" | "50" | "" | "34.5" | 2 | -1 |
| "0.060" | "0" | "060" | "" | "6" | npos | -2 |
| "10e-2" | "0" | "1" | "2" | "1" | npos | 1 |

Notice that the . is ignored when considering significantDigits (so "34.5" is treated as "345", and the bias is -1).

Finally, note that significantDigits, significantDigitBias, and significantDigitsDotOffset are useful when considering a canonical representation for a JSON Number, which consists of a whole number (with leading and trailing zeros removed) and an exponent. This canonical representation can be used when determining whether two JSON numbers are equal. For example, "-12.30e-4" would have a canonical representation -123e-5. This canonical representation can be computed by taking the returned significantDigits, "12.3", ignoring the . character at significantDigitsOffset and incorporating isNegative to get the canonical significant digits -123, then combining exponent ("4") with isExponentNegative to get the exponent of -4 and then adding the returned significantDigitsBias of -1 to that exponent to get the canonical exponent of -5. Combining the canonical significant digits (-123) and the canonical exponent (-5) results in the canonical representation -123e-5.

◆ logUnparseableJsonNumber()

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: