lib/univalue_read.cpp
/**
 * Helper for getJsonToken; converts hexadecimal string to unsigned integer.
 *
 * Returns a nullopt if conversion fails due to not enough characters (requires
 * minimum 4 characters), or if any of the characters encountered are not hex.
 *
 * On success, returns an optional containing the converted codepoint.
 *
 * Consumes the first 4 hex characters in `buffer`, insofar they exist.
 */
Helper for getJsonToken; converts hexadecimal string to unsigned integer.
Returns a nullopt if conversion fails due to not enough characters (requires
minimum 4 characters), or if any of the characters encountered are not hex.

On success, returns an optional containing the converted codepoint.

Consumes the first 4 hex characters in `buffer`, insofar they exist.
Helper for getJsonToken ; converts hexadecimal string to unsigned integer . Returns a nullopt if conversion fails due to not enough characters ( requires minimum 4 characters ) or if any of the characters encountered are not hex . On success returns an optional containing the converted codepoint . Consumes the first 4 hex characters in ` buffer ` insofar they exist .
inline constexpr std::optional<unsigned> hatoui(const char*& buffer) noexcept
{
    unsigned val = 0;
    for (const char* end = buffer + 4; buffer != end; ++buffer) {  
        val *= 16;
        if (json_isdigit(*buffer))
            val += *buffer - '0';
        else if (*buffer >= 'a' && *buffer <= 'f')
            val += *buffer - 'a' + 10;
        else if (*buffer >= 'A' && *buffer <= 'F')
            val += *buffer - 'A' + 10;
        else
            return std::nullopt; 
    }
    return val;
}
inline constexpr std :: optional < unsigned > hatoui ( const char * & buffer ) noexcept { unsigned val = 0 ; for ( const char * end = buffer + 4 ; buffer != end ; ++ buffer ) { val *= 16 ; if ( json_isdigit ( * buffer ) ) val += * buffer - ' ' ; else if ( * buffer >= ' ' && * buffer <= ' ' ) val += * buffer - ' ' + 10 ; else if ( * buffer >= ' ' && * buffer <= ' ' ) val += * buffer - ' ' + 10 ; else return std :: nullopt ; } return val ; }
Helper for getJsonToken; converts hexadecimal string to unsigned integer.
Helper for getJsonToken ; converts hexadecimal string to unsigned integer .
// consume 4 chars from buffer // not a hex digit, fail