EV-Redis
view release on metacpan or search on metacpan
deps/hiredis/ffc.h view on Meta::CPAN
// frac_end_local) instead of reading back from answer struct fields.
// This allows GCC DSE to eliminate the answer.int_part_* and
// answer.fraction_part_* stores on non-JSON callers (where those fields
// are removed from the return ABI by ISRA).
i = 0;
p = (char*)start_digits;
char const *int_end = (char*)end_of_integer_part;
uint64_t const minimal_nineteen_digit_integer = 1000000000000000000;
while ((i < minimal_nineteen_digit_integer) && (p != int_end)) {
i = i * 10 + (uint64_t)(*p - '0');
++p;
}
if (i >= minimal_nineteen_digit_integer) { // We have a big integer
exponent = end_of_integer_part - p + exp_number;
} else { // We have a value with a fractional component.
p = (char*)before;
char const *frac_end = (char*)frac_end_local;
while ((i < minimal_nineteen_digit_integer) && (p != frac_end)) {
i = i * 10 + (uint64_t)(*p - '0');
++p;
}
exponent = before - p + exp_number;
}
// We have now corrected both exponent and i, to a truncated value
}
}
answer.exponent = exponent;
answer.mantissa = i;
return answer;
}
/**
* Special case +inf, -inf, nan, infinity, -infinity.
* The case comparisons could be made much faster given that we know that the
* strings a null-free and fixed.
**/
ffc_internal ffc_inline
ffc_result ffc_parse_infnan(
char *first, char *last,
ffc_value *value,
ffc_value_kind vk,
ffc_format fmt
) {
ffc_debug("parse_infnan\n");
ffc_result answer;
answer.ptr = first;
answer.outcome = FFC_OUTCOME_OK; // be optimistic
// assume first < last, so dereference without checks;
bool const minus_sign = (*first == '-');
// C++17 20.19.3.(7.1) explicitly forbids '+' sign here
if ((*first == '-') ||
((uint64_t)(fmt & FFC_FORMAT_FLAG_ALLOW_LEADING_PLUS) &&
(*first == '+'))) {
++first;
}
if (last - first >= 3) {
if (ffc_strncasecmp3(first, "nan", 1)) {
answer.ptr = (first += 3);
// The macro casts the literal AFTER applying the negative sign. This is ok:
// -NAN is a double negative NaN, and (float)(-NAN) correctly produces a negative float NaN.
// Same for infinity â (float)(-INFINITY) gives negative float infinity
ffc_set_value(value, vk, minus_sign ? -NAN : NAN);
// Check for possible nan(n-char-seq-opt), C++17 20.19.3.7,
// C11 7.20.1.3.3. At least MSVC produces nan(ind) and nan(snan).
if (first != last && *first == '(') {
for (char *ptr = first + 1; ptr != last; ++ptr) {
if (*ptr == ')') {
answer.ptr = ptr + 1; // valid nan(n-char-seq-opt)
break;
} else if (!(('a' <= *ptr && *ptr <= 'z') ||
('A' <= *ptr && *ptr <= 'Z') ||
('0' <= *ptr && *ptr <= '9') || *ptr == '_'))
break; // forbidden char, not nan(n-char-seq-opt)
}
}
return answer;
}
if (ffc_strncasecmp3(first, "infinity", 1)) {
if ((last - first >= 8) &&
ffc_strncasecmp5(first + 3, (char*)&"infinity"[3], 1)) {
answer.ptr = first + 8;
} else {
answer.ptr = first + 3;
}
ffc_set_value(value, vk, minus_sign ? -INFINITY : INFINITY);
return answer;
}
}
answer.outcome = FFC_OUTCOME_INVALID_INPUT;
return answer;
}
ffc_internal ffc_inline
ffc_result ffc_parse_int_string(
char const *p,
char const *pend,
ffc_int_value *value,
ffc_int_kind ik,
ffc_parse_options options,
int const base
) {
ffc_debug("input '%.*s'... ", (int)(pend - p), p);
ffc_format const fmt = options.format;
if ((uint64_t)(fmt & FFC_FORMAT_FLAG_SKIP_WHITE_SPACE)) {
while ((p != pend) && ffc_is_space(*p)) {
p++;
}
}
if (p == pend || base < 2 || base > 36) {
ffc_result invalid_input_result;
invalid_input_result.ptr = (char*)p;
invalid_input_result.outcome = FFC_OUTCOME_INVALID_INPUT;
return invalid_input_result;
}
ffc_result answer;
char const *const first = p;
( run in 1.836 second using v1.01-cache-2.11-cpan-60884a8df76 )