mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Add wuffs_base__parse_number_xxx options arg
This commit is contained in:
1 parent
832edf7227
commit
6b7ce30e32
9 files changed
+83
-53
No files matched your search
@@ -64,6 +64,7 @@ for a C++ compiler $CXX, such as clang++ or g++.
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
@@ -215,7 +216,8 @@ parse_flags(int argc, char** argv) {
|
||||
while (*arg++ != '=') {
|
||||
}
|
||||
wuffs_base__result_u64 u = wuffs_base__parse_number_u64(
|
||||
wuffs_base__make_slice_u8((uint8_t*)arg, strlen(arg)));
|
||||
wuffs_base__make_slice_u8((uint8_t*)arg, strlen(arg)),
|
||||
WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);
|
||||
if (wuffs_base__status__is_ok(&u.status) && (u.value <= 0xFFFFFFFF)) {
|
||||
g_flags.max_output_depth = (uint32_t)(u.value);
|
||||
continue;
|
||||
@@ -235,7 +237,7 @@ parse_flags(int argc, char** argv) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// ----
|
||||
// ----
|
||||
|
||||
#define WORK_BUFFER_ARRAY_SIZE \
|
||||
WUFFS_JSON__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE
|
||||
@@ -522,7 +524,8 @@ JsonThing::parse_number(TokenStream::Result tsr) {
|
||||
if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_TEXT) {
|
||||
if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_INTEGER_SIGNED) {
|
||||
static constexpr int64_t m = 0x001FFFFFFFFFFFFF; // ((1<<53) - 1).
|
||||
wuffs_base__result_i64 r = wuffs_base__parse_number_i64(tsr.src_data);
|
||||
wuffs_base__result_i64 r = wuffs_base__parse_number_i64(
|
||||
tsr.src_data, WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);
|
||||
if (!r.status.is_ok()) {
|
||||
return Result(r.status.message());
|
||||
} else if ((r.value < -m) || (+m < r.value)) {
|
||||
@@ -533,7 +536,8 @@ JsonThing::parse_number(TokenStream::Result tsr) {
|
||||
jt.value.i = r.value;
|
||||
return Result("", jt);
|
||||
} else if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_FLOATING_POINT) {
|
||||
wuffs_base__result_f64 r = wuffs_base__parse_number_f64(tsr.src_data);
|
||||
wuffs_base__result_f64 r = wuffs_base__parse_number_f64(
|
||||
tsr.src_data, WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);
|
||||
if (!r.status.is_ok()) {
|
||||
return Result(r.status.message());
|
||||
}
|
||||
|
||||
@@ -431,8 +431,9 @@ class Query {
|
||||
m_depth = d + 1;
|
||||
if (all_digits) {
|
||||
// wuffs_base__parse_number_u64 rejects leading zeroes, e.g. "00", "07".
|
||||
m_array_index =
|
||||
wuffs_base__parse_number_u64(wuffs_base__make_slice_u8(i, k - i));
|
||||
m_array_index = wuffs_base__parse_number_u64(
|
||||
wuffs_base__make_slice_u8(i, k - i),
|
||||
WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -601,7 +602,8 @@ parse_flags(int argc, char** argv) {
|
||||
while (*arg++ != '=') {
|
||||
}
|
||||
wuffs_base__result_u64 u = wuffs_base__parse_number_u64(
|
||||
wuffs_base__make_slice_u8((uint8_t*)arg, strlen(arg)));
|
||||
wuffs_base__make_slice_u8((uint8_t*)arg, strlen(arg)),
|
||||
WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);
|
||||
if (wuffs_base__status__is_ok(&u.status) && (u.value <= 0xFFFFFFFF)) {
|
||||
g_flags.max_output_depth = (uint32_t)(u.value);
|
||||
continue;
|
||||
|
||||
@@ -1987,7 +1987,7 @@ wuffs_base__private_implementation__is_decimal_digit(uint8_t c) {
|
||||
}
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__result_f64 //
|
||||
wuffs_base__parse_number_f64(wuffs_base__slice_u8 s) {
|
||||
wuffs_base__parse_number_f64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
// In practice, almost all "dd.ddddE±xxx" numbers can be represented
|
||||
// losslessly by a uint64_t mantissa "dddddd" and an int32_t base-10
|
||||
// exponent, adjusting "xxx" for the position (if present) of the decimal
|
||||
|
||||
@@ -106,7 +106,7 @@ static const uint8_t wuffs_base__parse_number__hexadecimal_digits[256] = {
|
||||
// --------
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__result_i64 //
|
||||
wuffs_base__parse_number_i64(wuffs_base__slice_u8 s) {
|
||||
wuffs_base__parse_number_i64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
uint8_t* p = s.ptr;
|
||||
uint8_t* q = s.ptr + s.len;
|
||||
|
||||
@@ -125,7 +125,7 @@ wuffs_base__parse_number_i64(wuffs_base__slice_u8 s) {
|
||||
|
||||
do {
|
||||
wuffs_base__result_u64 r = wuffs_base__parse_number_u64(
|
||||
wuffs_base__make_slice_u8(p, (size_t)(q - p)));
|
||||
wuffs_base__make_slice_u8(p, (size_t)(q - p)), options);
|
||||
if (r.status.repr != NULL) {
|
||||
wuffs_base__result_i64 ret;
|
||||
ret.status.repr = r.status.repr;
|
||||
@@ -167,7 +167,7 @@ fail_out_of_bounds:
|
||||
}
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__result_u64 //
|
||||
wuffs_base__parse_number_u64(wuffs_base__slice_u8 s) {
|
||||
wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
uint8_t* p = s.ptr;
|
||||
uint8_t* q = s.ptr + s.len;
|
||||
|
||||
|
||||
@@ -16,6 +16,14 @@
|
||||
|
||||
// ---------------- String Conversions
|
||||
|
||||
// Options (bitwise or'ed together) for wuffs_base__parse_number_xxx
|
||||
// functions. The XXX options apply to both integer and floating point. The FXX
|
||||
// options apply only to floating point.
|
||||
|
||||
#define WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS ((uint32_t)0x00000000)
|
||||
|
||||
// --------
|
||||
|
||||
// Options (bitwise or'ed together) for wuffs_base__render_number_xxx
|
||||
// functions. The XXX options apply to both integer and floating point. The FXX
|
||||
// options apply only to floating point.
|
||||
@@ -99,7 +107,7 @@
|
||||
// function requires the WUFFS_CONFIG__MODULE__BASE__F64CONV sub-module, not
|
||||
// just WUFFS_CONFIG__MODULE__BASE__CORE.
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__result_f64 //
|
||||
wuffs_base__parse_number_f64(wuffs_base__slice_u8 s);
|
||||
wuffs_base__parse_number_f64(wuffs_base__slice_u8 s, uint32_t options);
|
||||
|
||||
// --------
|
||||
|
||||
@@ -143,7 +151,7 @@ wuffs_base__ieee_754_bit_representation__to_f64(uint64_t u) {
|
||||
// It is similar to wuffs_base__parse_number_u64 but it returns a signed
|
||||
// integer, not an unsigned integer. It also allows a leading '+' or '-'.
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__result_i64 //
|
||||
wuffs_base__parse_number_i64(wuffs_base__slice_u8 s);
|
||||
wuffs_base__parse_number_i64(wuffs_base__slice_u8 s, uint32_t options);
|
||||
|
||||
// wuffs_base__parse_number_u64 parses the ASCII integer in s. For example, if
|
||||
// s contains the bytes "123" then it will return the uint64_t 123.
|
||||
@@ -170,7 +178,7 @@ wuffs_base__parse_number_i64(wuffs_base__slice_u8 s);
|
||||
// opening "0d" or "0X" that denotes base-10 or base-16. For example,
|
||||
// "__0D_1_002" would successfully parse as "one thousand and two".
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__result_u64 //
|
||||
wuffs_base__parse_number_u64(wuffs_base__slice_u8 s);
|
||||
wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options);
|
||||
|
||||
// --------
|
||||
|
||||
|
||||
+23
-21
@@ -131,15 +131,15 @@ const BaseF64ConvSubmoduleC = "" +
|
||||
"shift left, putting us in [½ .. 1].\n while (h->decimal_point <= 0) {\n uint32_t shift;\n if (h->decimal_point == 0) {\n if (h->digits[0] >= 5) {\n break;\n }\n shift = (h->digits[0] <= 2) ? 2 : 1;\n } else {\n uint32_t n = (uint32_t)(-h->decimal_point);\n shift = (n < num_powers)\n ? powers[n]\n : WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL;\n }\n\n wuffs_base__private_implementation__high_prec_dec__small_lshift(h, shift);\n if (h->decimal_point >\n +WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE) {\n goto infinity;\n }\n exp2 -= (int32_t)shift;\n }\n\n // We're in the range [½ .. 1] but f64 uses [1 .. 2].\n exp2--;\n\n // The minimum normal exponent is (f64_bias + 1).\n while ((f64_bias + 1) > exp2) {\n uint32_t n = (uint32_t)((f64_bias + 1) - exp2);\n if (n > WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL) {\n n = WUFFS_BASE__" +
|
||||
"PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL;\n }\n wuffs_base__private_implementation__high_prec_dec__small_rshift(h, n);\n exp2 += (int32_t)n;\n }\n\n // Check for overflow.\n if ((exp2 - f64_bias) >= 0x07FF) { // (1 << 11) - 1.\n goto infinity;\n }\n\n // Extract 53 bits for the mantissa (in base-2).\n wuffs_base__private_implementation__high_prec_dec__small_lshift(h, 53);\n uint64_t man2 =\n wuffs_base__private_implementation__high_prec_dec__rounded_integer(h);\n\n // Rounding might have added one bit. If so, shift and re-check overflow.\n if ((man2 >> 53) != 0) {\n man2 >>= 1;\n exp2++;\n if ((exp2 - f64_bias) >= 0x07FF) { // (1 << 11) - 1.\n goto infinity;\n }\n }\n\n // Handle subnormal numbers.\n if ((man2 >> 52) == 0) {\n exp2 = f64_bias;\n }\n\n // Pack the bits and return.\n uint64_t exp2_bits =\n (uint64_t)((exp2 - f64_bias) & 0x07FF); // (1 << 11) - 1.\n uint64_t bits = (man2 & 0x000FFFFFFFFFFFFF) | " +
|
||||
" // (1 << 52) - 1.\n (exp2_bits << 52) | //\n (h->negative ? 0x8000000000000000 : 0); // (1 << 63).\n\n wuffs_base__result_f64 ret;\n ret.status.repr = NULL;\n ret.value = wuffs_base__ieee_754_bit_representation__to_f64(bits);\n return ret;\n } while (0);\n\nzero:\n do {\n uint64_t bits = h->negative ? 0x8000000000000000 : 0;\n\n wuffs_base__result_f64 ret;\n ret.status.repr = NULL;\n ret.value = wuffs_base__ieee_754_bit_representation__to_f64(bits);\n return ret;\n } while (0);\n\ninfinity:\n do {\n uint64_t bits = h->negative ? 0xFFF0000000000000 : 0x7FF0000000000000;\n\n wuffs_base__result_f64 ret;\n ret.status.repr = NULL;\n ret.value = wuffs_base__ieee_754_bit_representation__to_f64(bits);\n return ret;\n } while (0);\n}\n\nstatic inline bool //\nwuffs_base__private_implementation__is_decimal_digit(uint8_t c) {\n return ('0' <= c) && (c <= '9');\n}\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__result_f64 //\nwuffs_base__parse_numb" +
|
||||
"er_f64(wuffs_base__slice_u8 s) {\n // In practice, almost all \"dd.ddddE±xxx\" numbers can be represented\n // losslessly by a uint64_t mantissa \"dddddd\" and an int32_t base-10\n // exponent, adjusting \"xxx\" for the position (if present) of the decimal\n // separator '.' or ','.\n //\n // This (u64 man, i32 exp10) data structure is superficially similar to the\n // \"Do It Yourself Floating Point\" type from Loitsch (†), but the exponent\n // here is base-10, not base-2.\n //\n // If s's number fits in a (man, exp10), parse that pair with the Eisel\n // algorithm. If not, or if Eisel fails, parsing s with the fallback\n // algorithm is slower but comprehensive.\n //\n // † \"Printing Floating-Point Numbers Quickly and Accurately with Integers\"\n // (https://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf).\n // Florian Loitsch is also the primary contributor to\n // https://github.com/google/double-conversion\n do {\n // Calculating that (man, exp10) pair needs to stay within s's bounds.\n /" +
|
||||
"/ Provided that s isn't extremely long, work on a NUL-terminated copy of\n // s's contents. The NUL byte isn't a valid part of \"±dd.ddddE±xxx\".\n //\n // As the pointer p walks the contents, it's faster to repeatedly check \"is\n // *p a valid digit\" than \"is p within bounds and *p a valid digit\".\n if (s.len >= 256) {\n goto fallback;\n }\n uint8_t z[256];\n memcpy(&z[0], s.ptr, s.len);\n z[s.len] = 0;\n const uint8_t* p = &z[0];\n\n // Look for a leading minus sign. Technically, we could also look for an\n // optional plus sign, but the \"script/process-json-numbers.c with -p\"\n // benchmark is noticably slower if we do. It's optional and, in practice,\n // usually absent. Let the fallback catch it.\n bool negative = (*p == '-');\n if (negative) {\n p++;\n }\n\n // After walking \"dd.dddd\", comparing p later with p now will produce the\n // number of \"d\"s and \".\"s.\n const uint8_t* const start_of_digits_ptr = p;\n\n // Walk the \"d\"s before a '.', 'E', NUL byte, " +
|
||||
"etc. If it starts with '0',\n // it must be a single '0'. If it starts with a non-zero decimal digit, it\n // can be a sequence of decimal digits.\n //\n // Update the man variable during the walk. It's OK if man overflows now.\n // We'll detect that later.\n uint64_t man;\n if (*p == '0') {\n man = 0;\n p++;\n if (wuffs_base__private_implementation__is_decimal_digit(*p)) {\n goto fallback;\n }\n } else if (wuffs_base__private_implementation__is_decimal_digit(*p)) {\n man = ((uint8_t)(*p - '0'));\n p++;\n for (; wuffs_base__private_implementation__is_decimal_digit(*p); p++) {\n man = (10 * man) + ((uint8_t)(*p - '0'));\n }\n } else {\n goto fallback;\n }\n\n // Walk the \"d\"s after the optional decimal separator ('.' or ','),\n // updating the man and exp10 variables.\n int32_t exp10 = 0;\n if ((*p == '.') || (*p == ',')) {\n p++;\n const uint8_t* first_after_separator_ptr = p;\n if (!wuffs_base__private_implementation__is_d" +
|
||||
"ecimal_digit(*p)) {\n goto fallback;\n }\n man = (10 * man) + ((uint8_t)(*p - '0'));\n p++;\n for (; wuffs_base__private_implementation__is_decimal_digit(*p); p++) {\n man = (10 * man) + ((uint8_t)(*p - '0'));\n }\n exp10 = ((int32_t)(first_after_separator_ptr - p));\n }\n\n // Count the number of digits:\n // - for an input of \"314159\", digit_count is 6.\n // - for an input of \"3.14159\", digit_count is 7.\n //\n // This is off-by-one if there is a decimal separator. That's OK for now.\n // We'll correct for that later. The \"script/process-json-numbers.c with\n // -p\" benchmark is noticably slower if we try to correct for that now.\n uint32_t digit_count = (uint32_t)(p - start_of_digits_ptr);\n\n // Update exp10 for the optional exponent, starting with 'E' or 'e'.\n if ((*p | 0x20) == 'e') {\n p++;\n int32_t exp_sign = +1;\n if (*p == '-') {\n p++;\n exp_sign = -1;\n } else if (*p == '+') {\n p++;\n }\n if (!w" +
|
||||
"uffs_base__private_implementation__is_decimal_digit(*p)) {\n goto fallback;\n }\n int32_t exp_num = ((uint8_t)(*p - '0'));\n p++;\n // The rest of the exp_num walking has a peculiar control flow but, once\n // again, the \"script/process-json-numbers.c with -p\" benchmark is\n // sensitive to alternative formulations.\n if (wuffs_base__private_implementation__is_decimal_digit(*p)) {\n exp_num = (10 * exp_num) + ((uint8_t)(*p - '0'));\n p++;\n }\n if (wuffs_base__private_implementation__is_decimal_digit(*p)) {\n exp_num = (10 * exp_num) + ((uint8_t)(*p - '0'));\n p++;\n }\n while (wuffs_base__private_implementation__is_decimal_digit(*p)) {\n if (exp_num > 0x1000000) {\n goto fallback;\n }\n exp_num = (10 * exp_num) + ((uint8_t)(*p - '0'));\n p++;\n }\n exp10 += exp_sign * exp_num;\n }\n\n // The Wuffs API is that the original slice has no trailing data. It also\n // allows underscores, which we " +
|
||||
"don't catch here but the fallback should.\n if (p != &z[s.len]) {\n goto fallback;\n }\n\n // Check that the uint64_t typed man variable has not overflowed, based on\n // digit_count.\n //\n // For reference:\n // - (1 << 63) is 9223372036854775808, which has 19 decimal digits.\n // - (1 << 64) is 18446744073709551616, which has 20 decimal digits.\n // - 19 nines, 9999999999999999999, is 0x8AC7230489E7FFFF, which has 64\n // bits and 16 hexadecimal digits.\n // - 20 nines, 99999999999999999999, is 0x56BC75E2D630FFFFF, which has 67\n // bits and 17 hexadecimal digits.\n if (digit_count > 19) {\n // Even if we have more than 19 pseudo-digits, it's not yet definitely an\n // overflow. Recall that digit_count might be off-by-one (too large) if\n // there's a decimal separator. It will also over-report the number of\n // meaningful digits if the input looks something like \"0.000dddExxx\".\n //\n // We adjust by the number of leading '0's and '." +
|
||||
"'s and re-compare to 19.\n // Once again, technically, we could skip ','s too, but that perturbs the\n // \"script/process-json-numbers.c with -p\" benchmark.\n const uint8_t* q = start_of_digits_ptr;\n for (; (*q == '0') || (*q == '.'); q++) {\n }\n digit_count -= (uint32_t)(q - start_of_digits_ptr);\n if (digit_count > 19) {\n goto fallback;\n }\n }\n\n // The wuffs_base__private_implementation__parse_number_f64_eisel\n // preconditions include that exp10 is in the range -326 ..= 310.\n if ((exp10 < -326) || (310 < exp10)) {\n goto fallback;\n }\n\n // If man and exp10 are small enough, all three of (man), (10 ** exp10) and\n // (man ** (10 ** exp10)) are exactly representable by a double. We don't\n // need to run the Eisel algorithm.\n if ((-22 <= exp10) && (exp10 <= 22) && ((man >> 53) == 0)) {\n double d = (double)man;\n if (exp10 >= 0) {\n d *= wuffs_base__private_implementation__f64_powers_of_10[+exp10];\n } else {\n d /= " +
|
||||
"wuffs_base__private_implementation__f64_powers_of_10[-exp10];\n }\n wuffs_base__result_f64 ret;\n ret.status.repr = NULL;\n ret.value = negative ? -d : +d;\n return ret;\n }\n\n // The wuffs_base__private_implementation__parse_number_f64_eisel\n // preconditions include that man is non-zero. Parsing \"0\" should be caught\n // by the \"If man and exp10 are small enough\" above, but \"0e99\" might not.\n if (man == 0) {\n goto fallback;\n }\n\n // Our man and exp10 are in range. Run the Eisel algorithm.\n int64_t r =\n wuffs_base__private_implementation__parse_number_f64_eisel(man, exp10);\n if (r < 0) {\n goto fallback;\n }\n wuffs_base__result_f64 ret;\n ret.status.repr = NULL;\n ret.value = wuffs_base__ieee_754_bit_representation__to_f64(\n ((uint64_t)r) | (((uint64_t)negative) << 63));\n return ret;\n } while (0);\n\nfallback:\n do {\n wuffs_base__private_implementation__high_prec_dec h;\n wuffs_base__status status =\n wuffs_base__private_" +
|
||||
"implementation__high_prec_dec__parse(&h, s);\n if (status.repr) {\n return wuffs_base__parse_number_f64_special(s, status.repr);\n }\n return wuffs_base__private_implementation__parse_number_f64__fallback(&h);\n } while (0);\n}\n\n" +
|
||||
"er_f64(wuffs_base__slice_u8 s, uint32_t options) {\n // In practice, almost all \"dd.ddddE±xxx\" numbers can be represented\n // losslessly by a uint64_t mantissa \"dddddd\" and an int32_t base-10\n // exponent, adjusting \"xxx\" for the position (if present) of the decimal\n // separator '.' or ','.\n //\n // This (u64 man, i32 exp10) data structure is superficially similar to the\n // \"Do It Yourself Floating Point\" type from Loitsch (†), but the exponent\n // here is base-10, not base-2.\n //\n // If s's number fits in a (man, exp10), parse that pair with the Eisel\n // algorithm. If not, or if Eisel fails, parsing s with the fallback\n // algorithm is slower but comprehensive.\n //\n // † \"Printing Floating-Point Numbers Quickly and Accurately with Integers\"\n // (https://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf).\n // Florian Loitsch is also the primary contributor to\n // https://github.com/google/double-conversion\n do {\n // Calculating that (man, exp10) pair needs to stay within" +
|
||||
" s's bounds.\n // Provided that s isn't extremely long, work on a NUL-terminated copy of\n // s's contents. The NUL byte isn't a valid part of \"±dd.ddddE±xxx\".\n //\n // As the pointer p walks the contents, it's faster to repeatedly check \"is\n // *p a valid digit\" than \"is p within bounds and *p a valid digit\".\n if (s.len >= 256) {\n goto fallback;\n }\n uint8_t z[256];\n memcpy(&z[0], s.ptr, s.len);\n z[s.len] = 0;\n const uint8_t* p = &z[0];\n\n // Look for a leading minus sign. Technically, we could also look for an\n // optional plus sign, but the \"script/process-json-numbers.c with -p\"\n // benchmark is noticably slower if we do. It's optional and, in practice,\n // usually absent. Let the fallback catch it.\n bool negative = (*p == '-');\n if (negative) {\n p++;\n }\n\n // After walking \"dd.dddd\", comparing p later with p now will produce the\n // number of \"d\"s and \".\"s.\n const uint8_t* const start_of_digits_ptr = p;\n\n // Walk the \"d\"s before a '." +
|
||||
"', 'E', NUL byte, etc. If it starts with '0',\n // it must be a single '0'. If it starts with a non-zero decimal digit, it\n // can be a sequence of decimal digits.\n //\n // Update the man variable during the walk. It's OK if man overflows now.\n // We'll detect that later.\n uint64_t man;\n if (*p == '0') {\n man = 0;\n p++;\n if (wuffs_base__private_implementation__is_decimal_digit(*p)) {\n goto fallback;\n }\n } else if (wuffs_base__private_implementation__is_decimal_digit(*p)) {\n man = ((uint8_t)(*p - '0'));\n p++;\n for (; wuffs_base__private_implementation__is_decimal_digit(*p); p++) {\n man = (10 * man) + ((uint8_t)(*p - '0'));\n }\n } else {\n goto fallback;\n }\n\n // Walk the \"d\"s after the optional decimal separator ('.' or ','),\n // updating the man and exp10 variables.\n int32_t exp10 = 0;\n if ((*p == '.') || (*p == ',')) {\n p++;\n const uint8_t* first_after_separator_ptr = p;\n if (!wuffs_base__private_im" +
|
||||
"plementation__is_decimal_digit(*p)) {\n goto fallback;\n }\n man = (10 * man) + ((uint8_t)(*p - '0'));\n p++;\n for (; wuffs_base__private_implementation__is_decimal_digit(*p); p++) {\n man = (10 * man) + ((uint8_t)(*p - '0'));\n }\n exp10 = ((int32_t)(first_after_separator_ptr - p));\n }\n\n // Count the number of digits:\n // - for an input of \"314159\", digit_count is 6.\n // - for an input of \"3.14159\", digit_count is 7.\n //\n // This is off-by-one if there is a decimal separator. That's OK for now.\n // We'll correct for that later. The \"script/process-json-numbers.c with\n // -p\" benchmark is noticably slower if we try to correct for that now.\n uint32_t digit_count = (uint32_t)(p - start_of_digits_ptr);\n\n // Update exp10 for the optional exponent, starting with 'E' or 'e'.\n if ((*p | 0x20) == 'e') {\n p++;\n int32_t exp_sign = +1;\n if (*p == '-') {\n p++;\n exp_sign = -1;\n } else if (*p == '+') {\n p++;\n " +
|
||||
" }\n if (!wuffs_base__private_implementation__is_decimal_digit(*p)) {\n goto fallback;\n }\n int32_t exp_num = ((uint8_t)(*p - '0'));\n p++;\n // The rest of the exp_num walking has a peculiar control flow but, once\n // again, the \"script/process-json-numbers.c with -p\" benchmark is\n // sensitive to alternative formulations.\n if (wuffs_base__private_implementation__is_decimal_digit(*p)) {\n exp_num = (10 * exp_num) + ((uint8_t)(*p - '0'));\n p++;\n }\n if (wuffs_base__private_implementation__is_decimal_digit(*p)) {\n exp_num = (10 * exp_num) + ((uint8_t)(*p - '0'));\n p++;\n }\n while (wuffs_base__private_implementation__is_decimal_digit(*p)) {\n if (exp_num > 0x1000000) {\n goto fallback;\n }\n exp_num = (10 * exp_num) + ((uint8_t)(*p - '0'));\n p++;\n }\n exp10 += exp_sign * exp_num;\n }\n\n // The Wuffs API is that the original slice has no trailing data. It also\n // allows unde" +
|
||||
"rscores, which we don't catch here but the fallback should.\n if (p != &z[s.len]) {\n goto fallback;\n }\n\n // Check that the uint64_t typed man variable has not overflowed, based on\n // digit_count.\n //\n // For reference:\n // - (1 << 63) is 9223372036854775808, which has 19 decimal digits.\n // - (1 << 64) is 18446744073709551616, which has 20 decimal digits.\n // - 19 nines, 9999999999999999999, is 0x8AC7230489E7FFFF, which has 64\n // bits and 16 hexadecimal digits.\n // - 20 nines, 99999999999999999999, is 0x56BC75E2D630FFFFF, which has 67\n // bits and 17 hexadecimal digits.\n if (digit_count > 19) {\n // Even if we have more than 19 pseudo-digits, it's not yet definitely an\n // overflow. Recall that digit_count might be off-by-one (too large) if\n // there's a decimal separator. It will also over-report the number of\n // meaningful digits if the input looks something like \"0.000dddExxx\".\n //\n // We adjust by the number of l" +
|
||||
"eading '0's and '.'s and re-compare to 19.\n // Once again, technically, we could skip ','s too, but that perturbs the\n // \"script/process-json-numbers.c with -p\" benchmark.\n const uint8_t* q = start_of_digits_ptr;\n for (; (*q == '0') || (*q == '.'); q++) {\n }\n digit_count -= (uint32_t)(q - start_of_digits_ptr);\n if (digit_count > 19) {\n goto fallback;\n }\n }\n\n // The wuffs_base__private_implementation__parse_number_f64_eisel\n // preconditions include that exp10 is in the range -326 ..= 310.\n if ((exp10 < -326) || (310 < exp10)) {\n goto fallback;\n }\n\n // If man and exp10 are small enough, all three of (man), (10 ** exp10) and\n // (man ** (10 ** exp10)) are exactly representable by a double. We don't\n // need to run the Eisel algorithm.\n if ((-22 <= exp10) && (exp10 <= 22) && ((man >> 53) == 0)) {\n double d = (double)man;\n if (exp10 >= 0) {\n d *= wuffs_base__private_implementation__f64_powers_of_10[+exp10];\n } el" +
|
||||
"se {\n d /= wuffs_base__private_implementation__f64_powers_of_10[-exp10];\n }\n wuffs_base__result_f64 ret;\n ret.status.repr = NULL;\n ret.value = negative ? -d : +d;\n return ret;\n }\n\n // The wuffs_base__private_implementation__parse_number_f64_eisel\n // preconditions include that man is non-zero. Parsing \"0\" should be caught\n // by the \"If man and exp10 are small enough\" above, but \"0e99\" might not.\n if (man == 0) {\n goto fallback;\n }\n\n // Our man and exp10 are in range. Run the Eisel algorithm.\n int64_t r =\n wuffs_base__private_implementation__parse_number_f64_eisel(man, exp10);\n if (r < 0) {\n goto fallback;\n }\n wuffs_base__result_f64 ret;\n ret.status.repr = NULL;\n ret.value = wuffs_base__ieee_754_bit_representation__to_f64(\n ((uint64_t)r) | (((uint64_t)negative) << 63));\n return ret;\n } while (0);\n\nfallback:\n do {\n wuffs_base__private_implementation__high_prec_dec h;\n wuffs_base__status status =\n wu" +
|
||||
"ffs_base__private_implementation__high_prec_dec__parse(&h, s);\n if (status.repr) {\n return wuffs_base__parse_number_f64_special(s, status.repr);\n }\n return wuffs_base__private_implementation__parse_number_f64__fallback(&h);\n } while (0);\n}\n\n" +
|
||||
"" +
|
||||
"// --------\n\nstatic inline size_t //\nwuffs_base__private_implementation__render_inf(wuffs_base__slice_u8 dst,\n bool neg,\n uint32_t options) {\n if (neg) {\n if (dst.len < 4) {\n return 0;\n }\n wuffs_base__store_u32le__no_bounds_check(dst.ptr, 0x666E492D); // '-Inf'le.\n return 4;\n }\n\n if (options & WUFFS_BASE__RENDER_NUMBER_XXX__LEADING_PLUS_SIGN) {\n if (dst.len < 4) {\n return 0;\n }\n wuffs_base__store_u32le__no_bounds_check(dst.ptr, 0x666E492B); // '+Inf'le.\n return 4;\n }\n\n if (dst.len < 3) {\n return 0;\n }\n wuffs_base__store_u24le__no_bounds_check(dst.ptr, 0x666E49); // 'Inf'le.\n return 3;\n}\n\nstatic inline size_t //\nwuffs_base__private_implementation__render_nan(wuffs_base__slice_u8 dst) {\n if (dst.len < 3) {\n return 0;\n }\n wuffs_base__store_u24le__no_bounds_check(dst.ptr, 0x4E614E); // 'NaN'le.\n return 3;\n}\n\nstatic size_t //\nwuffs_base__private_implementation__high" +
|
||||
"_prec_dec__render_exponent_absent(\n wuffs_base__slice_u8 dst,\n wuffs_base__private_implementation__high_prec_dec* h,\n uint32_t precision,\n uint32_t options) {\n size_t n = (h->negative ||\n (options & WUFFS_BASE__RENDER_NUMBER_XXX__LEADING_PLUS_SIGN))\n ? 1\n : 0;\n if (h->decimal_point <= 0) {\n n += 1;\n } else {\n n += (size_t)(h->decimal_point);\n }\n if (precision > 0) {\n n += precision + 1; // +1 for the '.'.\n }\n\n // Don't modify dst if the formatted number won't fit.\n if (n > dst.len) {\n return 0;\n }\n\n // Align-left or align-right.\n uint8_t* ptr = (options & WUFFS_BASE__RENDER_NUMBER_XXX__ALIGN_RIGHT)\n ? &dst.ptr[dst.len - n]\n : &dst.ptr[0];\n\n // Leading \"±\".\n if (h->negative) {\n *ptr++ = '-';\n } else if (options & WUFFS_BASE__RENDER_NUMBER_XXX__LEADING_PLUS_SIGN) {\n *ptr++ = '+';\n }\n\n // Integral digits.\n if (h->decimal_point <= 0) {\n *ptr++ = '0';\n } else {\n uint32_t m =\n" +
|
||||
@@ -160,11 +160,11 @@ const BaseI64ConvSubmoduleC = "" +
|
||||
" 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x80 ..= 0x87.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x88 ..= 0x8F.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x90 ..= 0x97.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x98 ..= 0x9F.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xA0 ..= 0xA7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xA8 ..= 0xAF.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xB0 ..= 0xB7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xB8 ..= 0xBF.\n\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xC0 ..= 0xC7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xC8 ..= 0xCF.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xD0 ..= 0xD7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xD8 ..= 0xDF.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xE0 ..= 0xE7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xE8 ..= 0xEF.\n 0x00, 0x00, 0x00, 0x00, 0x0" +
|
||||
"0, 0x00, 0x00, 0x00, // 0xF0 ..= 0xF7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xF8 ..= 0xFF.\n // 0 1 2 3 4 5 6 7\n // 8 9 A B C D E F\n};\n\n" +
|
||||
"" +
|
||||
"// --------\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__result_i64 //\nwuffs_base__parse_number_i64(wuffs_base__slice_u8 s) {\n uint8_t* p = s.ptr;\n uint8_t* q = s.ptr + s.len;\n\n for (; (p < q) && (*p == '_'); p++) {\n }\n\n bool negative = false;\n if (p >= q) {\n goto fail_bad_argument;\n } else if (*p == '-') {\n p++;\n negative = true;\n } else if (*p == '+') {\n p++;\n }\n\n do {\n wuffs_base__result_u64 r = wuffs_base__parse_number_u64(\n wuffs_base__make_slice_u8(p, (size_t)(q - p)));\n if (r.status.repr != NULL) {\n wuffs_base__result_i64 ret;\n ret.status.repr = r.status.repr;\n ret.value = 0;\n return ret;\n } else if (negative) {\n if (r.value > 0x8000000000000000) {\n goto fail_out_of_bounds;\n }\n wuffs_base__result_i64 ret;\n ret.status.repr = NULL;\n ret.value = -(int64_t)(r.value);\n return ret;\n } else if (r.value > 0x7FFFFFFFFFFFFFFF) {\n goto fail_out_of_bounds;\n } else {\n wuffs_base__result_i64 ret;\n ret.status" +
|
||||
".repr = NULL;\n ret.value = +(int64_t)(r.value);\n return ret;\n }\n } while (0);\n\nfail_bad_argument:\n do {\n wuffs_base__result_i64 ret;\n ret.status.repr = wuffs_base__error__bad_argument;\n ret.value = 0;\n return ret;\n } while (0);\n\nfail_out_of_bounds:\n do {\n wuffs_base__result_i64 ret;\n ret.status.repr = wuffs_base__error__out_of_bounds;\n ret.value = 0;\n return ret;\n } while (0);\n}\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__result_u64 //\nwuffs_base__parse_number_u64(wuffs_base__slice_u8 s) {\n uint8_t* p = s.ptr;\n uint8_t* q = s.ptr + s.len;\n\n for (; (p < q) && (*p == '_'); p++) {\n }\n\n if (p >= q) {\n goto fail_bad_argument;\n\n } else if (*p == '0') {\n p++;\n if (p >= q) {\n goto ok_zero;\n }\n if (*p == '_') {\n p++;\n for (; p < q; p++) {\n if (*p != '_') {\n goto fail_bad_argument;\n }\n }\n goto ok_zero;\n }\n\n if ((*p == 'x') || (*p == 'X')) {\n p++;\n for (; (p < q) && (*p == '_'); p++) {\n }\n " +
|
||||
"if (p < q) {\n goto hexadecimal;\n }\n\n } else if ((*p == 'd') || (*p == 'D')) {\n p++;\n for (; (p < q) && (*p == '_'); p++) {\n }\n if (p < q) {\n goto decimal;\n }\n }\n\n goto fail_bad_argument;\n }\n\ndecimal:\n do {\n uint64_t v = wuffs_base__parse_number__decimal_digits[*p++];\n if (v == 0) {\n goto fail_bad_argument;\n }\n v &= 0x0F;\n\n // UINT64_MAX is 18446744073709551615, which is ((10 * max10) + max1).\n const uint64_t max10 = 1844674407370955161u;\n const uint8_t max1 = 5;\n\n for (; p < q; p++) {\n if (*p == '_') {\n continue;\n }\n uint8_t digit = wuffs_base__parse_number__decimal_digits[*p];\n if (digit == 0) {\n goto fail_bad_argument;\n }\n digit &= 0x0F;\n if ((v > max10) || ((v == max10) && (digit > max1))) {\n goto fail_out_of_bounds;\n }\n v = (10 * v) + ((uint64_t)(digit));\n }\n\n wuffs_base__result_u64 ret;\n ret.status.repr = NULL;\n ret.value = v;\n return ret;\n " +
|
||||
"} while (0);\n\nhexadecimal:\n do {\n uint64_t v = wuffs_base__parse_number__hexadecimal_digits[*p++];\n if (v == 0) {\n goto fail_bad_argument;\n }\n v &= 0x0F;\n\n for (; p < q; p++) {\n if (*p == '_') {\n continue;\n }\n uint8_t digit = wuffs_base__parse_number__hexadecimal_digits[*p];\n if (digit == 0) {\n goto fail_bad_argument;\n }\n digit &= 0x0F;\n if ((v >> 60) != 0) {\n goto fail_out_of_bounds;\n }\n v = (v << 4) | ((uint64_t)(digit));\n }\n\n wuffs_base__result_u64 ret;\n ret.status.repr = NULL;\n ret.value = v;\n return ret;\n } while (0);\n\nok_zero:\n do {\n wuffs_base__result_u64 ret;\n ret.status.repr = NULL;\n ret.value = 0;\n return ret;\n } while (0);\n\nfail_bad_argument:\n do {\n wuffs_base__result_u64 ret;\n ret.status.repr = wuffs_base__error__bad_argument;\n ret.value = 0;\n return ret;\n } while (0);\n\nfail_out_of_bounds:\n do {\n wuffs_base__result_u64 ret;\n ret.status.repr = wuffs_base__error__" +
|
||||
"out_of_bounds;\n ret.value = 0;\n return ret;\n } while (0);\n}\n\n" +
|
||||
"// --------\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__result_i64 //\nwuffs_base__parse_number_i64(wuffs_base__slice_u8 s, uint32_t options) {\n uint8_t* p = s.ptr;\n uint8_t* q = s.ptr + s.len;\n\n for (; (p < q) && (*p == '_'); p++) {\n }\n\n bool negative = false;\n if (p >= q) {\n goto fail_bad_argument;\n } else if (*p == '-') {\n p++;\n negative = true;\n } else if (*p == '+') {\n p++;\n }\n\n do {\n wuffs_base__result_u64 r = wuffs_base__parse_number_u64(\n wuffs_base__make_slice_u8(p, (size_t)(q - p)), options);\n if (r.status.repr != NULL) {\n wuffs_base__result_i64 ret;\n ret.status.repr = r.status.repr;\n ret.value = 0;\n return ret;\n } else if (negative) {\n if (r.value > 0x8000000000000000) {\n goto fail_out_of_bounds;\n }\n wuffs_base__result_i64 ret;\n ret.status.repr = NULL;\n ret.value = -(int64_t)(r.value);\n return ret;\n } else if (r.value > 0x7FFFFFFFFFFFFFFF) {\n goto fail_out_of_bounds;\n } else {\n wuffs_base__resul" +
|
||||
"t_i64 ret;\n ret.status.repr = NULL;\n ret.value = +(int64_t)(r.value);\n return ret;\n }\n } while (0);\n\nfail_bad_argument:\n do {\n wuffs_base__result_i64 ret;\n ret.status.repr = wuffs_base__error__bad_argument;\n ret.value = 0;\n return ret;\n } while (0);\n\nfail_out_of_bounds:\n do {\n wuffs_base__result_i64 ret;\n ret.status.repr = wuffs_base__error__out_of_bounds;\n ret.value = 0;\n return ret;\n } while (0);\n}\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__result_u64 //\nwuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {\n uint8_t* p = s.ptr;\n uint8_t* q = s.ptr + s.len;\n\n for (; (p < q) && (*p == '_'); p++) {\n }\n\n if (p >= q) {\n goto fail_bad_argument;\n\n } else if (*p == '0') {\n p++;\n if (p >= q) {\n goto ok_zero;\n }\n if (*p == '_') {\n p++;\n for (; p < q; p++) {\n if (*p != '_') {\n goto fail_bad_argument;\n }\n }\n goto ok_zero;\n }\n\n if ((*p == 'x') || (*p == 'X')) {\n p++;\n for (; " +
|
||||
"(p < q) && (*p == '_'); p++) {\n }\n if (p < q) {\n goto hexadecimal;\n }\n\n } else if ((*p == 'd') || (*p == 'D')) {\n p++;\n for (; (p < q) && (*p == '_'); p++) {\n }\n if (p < q) {\n goto decimal;\n }\n }\n\n goto fail_bad_argument;\n }\n\ndecimal:\n do {\n uint64_t v = wuffs_base__parse_number__decimal_digits[*p++];\n if (v == 0) {\n goto fail_bad_argument;\n }\n v &= 0x0F;\n\n // UINT64_MAX is 18446744073709551615, which is ((10 * max10) + max1).\n const uint64_t max10 = 1844674407370955161u;\n const uint8_t max1 = 5;\n\n for (; p < q; p++) {\n if (*p == '_') {\n continue;\n }\n uint8_t digit = wuffs_base__parse_number__decimal_digits[*p];\n if (digit == 0) {\n goto fail_bad_argument;\n }\n digit &= 0x0F;\n if ((v > max10) || ((v == max10) && (digit > max1))) {\n goto fail_out_of_bounds;\n }\n v = (10 * v) + ((uint64_t)(digit));\n }\n\n wuffs_base__result_u64 ret;\n ret.status.repr " +
|
||||
"= NULL;\n ret.value = v;\n return ret;\n } while (0);\n\nhexadecimal:\n do {\n uint64_t v = wuffs_base__parse_number__hexadecimal_digits[*p++];\n if (v == 0) {\n goto fail_bad_argument;\n }\n v &= 0x0F;\n\n for (; p < q; p++) {\n if (*p == '_') {\n continue;\n }\n uint8_t digit = wuffs_base__parse_number__hexadecimal_digits[*p];\n if (digit == 0) {\n goto fail_bad_argument;\n }\n digit &= 0x0F;\n if ((v >> 60) != 0) {\n goto fail_out_of_bounds;\n }\n v = (v << 4) | ((uint64_t)(digit));\n }\n\n wuffs_base__result_u64 ret;\n ret.status.repr = NULL;\n ret.value = v;\n return ret;\n } while (0);\n\nok_zero:\n do {\n wuffs_base__result_u64 ret;\n ret.status.repr = NULL;\n ret.value = 0;\n return ret;\n } while (0);\n\nfail_bad_argument:\n do {\n wuffs_base__result_u64 ret;\n ret.status.repr = wuffs_base__error__bad_argument;\n ret.value = 0;\n return ret;\n } while (0);\n\nfail_out_of_bounds:\n do {\n wuffs_base__result_u64 r" +
|
||||
"et;\n ret.status.repr = wuffs_base__error__out_of_bounds;\n ret.value = 0;\n return ret;\n } while (0);\n}\n\n" +
|
||||
"" +
|
||||
"// --------\n\n// wuffs_base__render_number__first_hundred contains the decimal encodings of\n// the first one hundred numbers [0 ..= 99].\nstatic const uint8_t wuffs_base__render_number__first_hundred[200] = {\n '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', //\n '0', '5', '0', '6', '0', '7', '0', '8', '0', '9', //\n '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', //\n '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', //\n '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', //\n '2', '5', '2', '6', '2', '7', '2', '8', '2', '9', //\n '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', //\n '3', '5', '3', '6', '3', '7', '3', '8', '3', '9', //\n '4', '0', '4', '1', '4', '2', '4', '3', '4', '4', //\n '4', '5', '4', '6', '4', '7', '4', '8', '4', '9', //\n '5', '0', '5', '1', '5', '2', '5', '3', '5', '4', //\n '5', '5', '5', '6', '5', '7', '5', '8', '5', '9', //\n '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', //\n '6', '5', '6', '6', '6', '7', '6', '8', '6', '9', //\n '" +
|
||||
"7', '0', '7', '1', '7', '2', '7', '3', '7', '4', //\n '7', '5', '7', '6', '7', '7', '7', '8', '7', '9', //\n '8', '0', '8', '1', '8', '2', '8', '3', '8', '4', //\n '8', '5', '8', '6', '8', '7', '8', '8', '8', '9', //\n '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', //\n '9', '5', '9', '6', '9', '7', '9', '8', '9', '9', //\n};\n\nstatic size_t //\nwuffs_base__private_implementation__render_number_u64(wuffs_base__slice_u8 dst,\n uint64_t x,\n uint32_t options,\n bool neg) {\n uint8_t buf[WUFFS_BASE__U64__BYTE_LENGTH__MAX_INCL];\n uint8_t* ptr = &buf[0] + sizeof(buf);\n\n while (x >= 100) {\n size_t index = (x % 100) * 2;\n x /= 100;\n uint8_t s0 = wuffs_base__render_number__first_hundred[index + 0];\n uint8_t s1 = wuffs_base__render_number__first_hundred[index + 1];\n ptr -= 2;\n ptr[0] = s0;\n ptr[1] = s1;\n }\n\n if (x < 10) {\n " +
|
||||
@@ -484,19 +484,21 @@ const BaseStrConvPrivateH = "" +
|
||||
""
|
||||
|
||||
const BaseStrConvPublicH = "" +
|
||||
"// ---------------- String Conversions\n\n// Options (bitwise or'ed together) for wuffs_base__render_number_xxx\n// functions. The XXX options apply to both integer and floating point. The FXX\n// options apply only to floating point.\n\n#define WUFFS_BASE__RENDER_NUMBER_XXX__DEFAULT_OPTIONS ((uint32_t)0x00000000)\n\n// WUFFS_BASE__RENDER_NUMBER_XXX__ALIGN_RIGHT means to render to the right side\n// (higher indexes) of the destination slice, leaving any untouched bytes on\n// the left side (lower indexes). The default is vice versa: rendering on the\n// left with slack on the right.\n#define WUFFS_BASE__RENDER_NUMBER_XXX__ALIGN_RIGHT ((uint32_t)0x00000001)\n\n// WUFFS_BASE__RENDER_NUMBER_XXX__LEADING_PLUS_SIGN means to render the leading\n// \"+\" for non-negative numbers: \"+0\" and \"+12.3\" instead of \"0\" and \"12.3\".\n#define WUFFS_BASE__RENDER_NUMBER_XXX__LEADING_PLUS_SIGN ((uint32_t)0x00000002)\n\n// WUFFS_BASE__RENDER_NUMBER_FXX__DECIMAL_SEPARATOR_IS_A_COMMA means to render\n// one-and-a-half as \"1,5\" instead of \"1.5\".\n#define " +
|
||||
"WUFFS_BASE__RENDER_NUMBER_FXX__DECIMAL_SEPARATOR_IS_A_COMMA \\\n ((uint32_t)0x00000100)\n\n// WUFFS_BASE__RENDER_NUMBER_FXX__EXPONENT_ETC means whether to never\n// (EXPONENT_ABSENT, equivalent to printf's \"%f\") or to always\n// (EXPONENT_PRESENT, equivalent to printf's \"%e\") render a floating point\n// number as \"1.23e+05\" instead of \"123000\".\n//\n// Having both bits set is the same has having neither bit set, where the\n// notation used depends on whether the exponent is sufficiently large: \"0.5\"\n// is preferred over \"5e-01\" but \"5e-09\" is preferred over \"0.000000005\".\n#define WUFFS_BASE__RENDER_NUMBER_FXX__EXPONENT_ABSENT ((uint32_t)0x00000200)\n#define WUFFS_BASE__RENDER_NUMBER_FXX__EXPONENT_PRESENT ((uint32_t)0x00000400)\n\n// WUFFS_BASE__RENDER_NUMBER_FXX__JUST_ENOUGH_PRECISION means to render the\n// smallest number of digits so that parsing the resultant string will recover\n// the same double-precision floating point number.\n//\n// For example, double-precision cannot distinguish between 0.3 and\n// 0.2999999999999" +
|
||||
"99988897769753748434595763683319091796875, so when this bit\n// is set, rendering the latter will produce \"0.3\" but rendering\n// 0.3000000000000000444089209850062616169452667236328125 will produce\n// \"0.30000000000000004\".\n#define WUFFS_BASE__RENDER_NUMBER_FXX__JUST_ENOUGH_PRECISION \\\n ((uint32_t)0x00000800)\n\n" +
|
||||
"// ---------------- String Conversions\n\n// Options (bitwise or'ed together) for wuffs_base__parse_number_xxx\n// functions. The XXX options apply to both integer and floating point. The FXX\n// options apply only to floating point.\n\n#define WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS ((uint32_t)0x00000000)\n\n" +
|
||||
"" +
|
||||
"// --------\n\n// Options (bitwise or'ed together) for wuffs_base__render_number_xxx\n// functions. The XXX options apply to both integer and floating point. The FXX\n// options apply only to floating point.\n\n#define WUFFS_BASE__RENDER_NUMBER_XXX__DEFAULT_OPTIONS ((uint32_t)0x00000000)\n\n// WUFFS_BASE__RENDER_NUMBER_XXX__ALIGN_RIGHT means to render to the right side\n// (higher indexes) of the destination slice, leaving any untouched bytes on\n// the left side (lower indexes). The default is vice versa: rendering on the\n// left with slack on the right.\n#define WUFFS_BASE__RENDER_NUMBER_XXX__ALIGN_RIGHT ((uint32_t)0x00000001)\n\n// WUFFS_BASE__RENDER_NUMBER_XXX__LEADING_PLUS_SIGN means to render the leading\n// \"+\" for non-negative numbers: \"+0\" and \"+12.3\" instead of \"0\" and \"12.3\".\n#define WUFFS_BASE__RENDER_NUMBER_XXX__LEADING_PLUS_SIGN ((uint32_t)0x00000002)\n\n// WUFFS_BASE__RENDER_NUMBER_FXX__DECIMAL_SEPARATOR_IS_A_COMMA means to render\n// one-and-a-half as \"1,5\" instead of \"1.5\".\n#define WUFFS_BASE__RENDER_NUMBER_F" +
|
||||
"XX__DECIMAL_SEPARATOR_IS_A_COMMA \\\n ((uint32_t)0x00000100)\n\n// WUFFS_BASE__RENDER_NUMBER_FXX__EXPONENT_ETC means whether to never\n// (EXPONENT_ABSENT, equivalent to printf's \"%f\") or to always\n// (EXPONENT_PRESENT, equivalent to printf's \"%e\") render a floating point\n// number as \"1.23e+05\" instead of \"123000\".\n//\n// Having both bits set is the same has having neither bit set, where the\n// notation used depends on whether the exponent is sufficiently large: \"0.5\"\n// is preferred over \"5e-01\" but \"5e-09\" is preferred over \"0.000000005\".\n#define WUFFS_BASE__RENDER_NUMBER_FXX__EXPONENT_ABSENT ((uint32_t)0x00000200)\n#define WUFFS_BASE__RENDER_NUMBER_FXX__EXPONENT_PRESENT ((uint32_t)0x00000400)\n\n// WUFFS_BASE__RENDER_NUMBER_FXX__JUST_ENOUGH_PRECISION means to render the\n// smallest number of digits so that parsing the resultant string will recover\n// the same double-precision floating point number.\n//\n// For example, double-precision cannot distinguish between 0.3 and\n// 0.2999999999999999888977697537484345957636" +
|
||||
"83319091796875, so when this bit\n// is set, rendering the latter will produce \"0.3\" but rendering\n// 0.3000000000000000444089209850062616169452667236328125 will produce\n// \"0.30000000000000004\".\n#define WUFFS_BASE__RENDER_NUMBER_FXX__JUST_ENOUGH_PRECISION \\\n ((uint32_t)0x00000800)\n\n" +
|
||||
"" +
|
||||
"// ---------------- IEEE 754 Floating Point\n\n// wuffs_base__parse_number_f64 parses the floating point number in s. For\n// example, if s contains the bytes \"1.5\" then it will return the double 1.5.\n//\n// It returns an error if s does not contain a floating point number.\n//\n// It does not necessarily return an error if the conversion is lossy, e.g. if\n// s is \"0.3\", which double-precision floating point cannot represent exactly.\n//\n// Similarly, the returned value may be infinite (and no error returned) even\n// if s was not \"inf\", when the input is nominally finite but sufficiently\n// larger than DBL_MAX, about 1.8e+308.\n//\n// It is similar to the C standard library's strtod function, but:\n// - Errors are returned in-band (in a result type), not out-of-band (errno).\n// - It takes a slice (a pointer and length), not a NUL-terminated C string.\n// - It does not take an optional endptr argument. It does not allow a partial\n// parse: it returns an error unless all of s is consumed.\n// - It does not allow whi" +
|
||||
"tespace, leading or otherwise.\n// - It does not allow unnecessary leading zeroes (\"0\" is valid and its sole\n// zero is necessary). All of \"00\", \"0644\" and \"00.7\" are invalid.\n// - It is not affected by i18n / l10n settings such as environment variables.\n// - Conversely, it always accepts either ',' or '.' as a decimal separator.\n// In particular, \"3,141,592\" is always invalid but \"3,141\" is always valid\n// (and approximately π). The caller is responsible for e.g. previously\n// rejecting or filtering s if it contains a comma, if that is unacceptable\n// to the caller. For example, JSON numbers always use a dot '.' and never a\n// comma ',', regardless of the LOCALE environment variable.\n// - It does allow arbitrary underscores. For example, \"_3.141_592\" would\n// successfully parse, again approximately π.\n// - It does allow \"inf\", \"+Infinity\" and \"-NAN\", case insensitive, but it\n// does not permit \"nan\" to be followed by an integer mantissa.\n// - It does not allow hexadecimal float" +
|
||||
"ing point numbers.\n//\n// For modular builds that divide the base module into sub-modules, using this\n// function requires the WUFFS_CONFIG__MODULE__BASE__F64CONV sub-module, not\n// just WUFFS_CONFIG__MODULE__BASE__CORE.\nWUFFS_BASE__MAYBE_STATIC wuffs_base__result_f64 //\nwuffs_base__parse_number_f64(wuffs_base__slice_u8 s);\n\n" +
|
||||
"ing point numbers.\n//\n// For modular builds that divide the base module into sub-modules, using this\n// function requires the WUFFS_CONFIG__MODULE__BASE__F64CONV sub-module, not\n// just WUFFS_CONFIG__MODULE__BASE__CORE.\nWUFFS_BASE__MAYBE_STATIC wuffs_base__result_f64 //\nwuffs_base__parse_number_f64(wuffs_base__slice_u8 s, uint32_t options);\n\n" +
|
||||
"" +
|
||||
"// --------\n\n// wuffs_base__ieee_754_bit_representation__etc converts between a double\n// precision numerical value and its IEEE 754 64-bit representation (1 sign\n// bit, 11 exponent bits, 52 explicit significand bits).\n//\n// For example, it converts between:\n// - +1.0 and 0x3FF0_0000_0000_0000.\n// - +5.5 and 0x4016_0000_0000_0000.\n// - -inf and 0xFFF0_0000_0000_0000.\n//\n// See https://en.wikipedia.org/wiki/Double-precision_floating-point_format\n\nstatic inline uint64_t //\nwuffs_base__ieee_754_bit_representation__from_f64(double f) {\n uint64_t u = 0;\n if (sizeof(uint64_t) == sizeof(double)) {\n memcpy(&u, &f, sizeof(uint64_t));\n }\n return u;\n}\n\nstatic inline double //\nwuffs_base__ieee_754_bit_representation__to_f64(uint64_t u) {\n double f = 0;\n if (sizeof(uint64_t) == sizeof(double)) {\n memcpy(&f, &u, sizeof(uint64_t));\n }\n return f;\n}\n\n" +
|
||||
"" +
|
||||
"// ---------------- Integer\n\n// wuffs_base__parse_number_i64 parses the ASCII integer in s. For example, if\n// s contains the bytes \"-123\" then it will return the int64_t -123.\n//\n// It returns an error if s does not contain an integer or if the integer\n// within would overflow an int64_t.\n//\n// It is similar to wuffs_base__parse_number_u64 but it returns a signed\n// integer, not an unsigned integer. It also allows a leading '+' or '-'.\nWUFFS_BASE__MAYBE_STATIC wuffs_base__result_i64 //\nwuffs_base__parse_number_i64(wuffs_base__slice_u8 s);\n\n// wuffs_base__parse_number_u64 parses the ASCII integer in s. For example, if\n// s contains the bytes \"123\" then it will return the uint64_t 123.\n//\n// It returns an error if s does not contain an integer or if the integer\n// within would overflow a uint64_t.\n//\n// It is similar to the C standard library's strtoull function, but:\n// - Errors are returned in-band (in a result type), not out-of-band (errno).\n// - It takes a slice (a pointer and length), not a NUL-termina" +
|
||||
"ted C string.\n// - It does not take an optional endptr argument. It does not allow a partial\n// parse: it returns an error unless all of s is consumed.\n// - It does not allow whitespace, leading or otherwise.\n// - It does not allow a leading '+' or '-'.\n// - It does not allow unnecessary leading zeroes (\"0\" is valid and its sole\n// zero is necessary). All of \"00\", \"0644\" and \"007\" are invalid.\n// - It does not take a base argument (e.g. base 10 vs base 16). Instead, it\n// always accepts both decimal (e.g \"1234\", \"0d5678\") and hexadecimal (e.g.\n// \"0x9aBC\"). The caller is responsible for prior filtering of e.g. hex\n// numbers if they are unwanted. For example, Wuffs' JSON decoder will only\n// produce a wuffs_base__token for decimal numbers, not hexadecimal.\n// - It is not affected by i18n / l10n settings such as environment variables.\n// - It does allow arbitrary underscores, except inside the optional 2-byte\n// opening \"0d\" or \"0X\" that denotes base-10 or base-16. For example,\n// " +
|
||||
" \"__0D_1_002\" would successfully parse as \"one thousand and two\".\nWUFFS_BASE__MAYBE_STATIC wuffs_base__result_u64 //\nwuffs_base__parse_number_u64(wuffs_base__slice_u8 s);\n\n" +
|
||||
"// ---------------- Integer\n\n// wuffs_base__parse_number_i64 parses the ASCII integer in s. For example, if\n// s contains the bytes \"-123\" then it will return the int64_t -123.\n//\n// It returns an error if s does not contain an integer or if the integer\n// within would overflow an int64_t.\n//\n// It is similar to wuffs_base__parse_number_u64 but it returns a signed\n// integer, not an unsigned integer. It also allows a leading '+' or '-'.\nWUFFS_BASE__MAYBE_STATIC wuffs_base__result_i64 //\nwuffs_base__parse_number_i64(wuffs_base__slice_u8 s, uint32_t options);\n\n// wuffs_base__parse_number_u64 parses the ASCII integer in s. For example, if\n// s contains the bytes \"123\" then it will return the uint64_t 123.\n//\n// It returns an error if s does not contain an integer or if the integer\n// within would overflow a uint64_t.\n//\n// It is similar to the C standard library's strtoull function, but:\n// - Errors are returned in-band (in a result type), not out-of-band (errno).\n// - It takes a slice (a pointer and length)," +
|
||||
" not a NUL-terminated C string.\n// - It does not take an optional endptr argument. It does not allow a partial\n// parse: it returns an error unless all of s is consumed.\n// - It does not allow whitespace, leading or otherwise.\n// - It does not allow a leading '+' or '-'.\n// - It does not allow unnecessary leading zeroes (\"0\" is valid and its sole\n// zero is necessary). All of \"00\", \"0644\" and \"007\" are invalid.\n// - It does not take a base argument (e.g. base 10 vs base 16). Instead, it\n// always accepts both decimal (e.g \"1234\", \"0d5678\") and hexadecimal (e.g.\n// \"0x9aBC\"). The caller is responsible for prior filtering of e.g. hex\n// numbers if they are unwanted. For example, Wuffs' JSON decoder will only\n// produce a wuffs_base__token for decimal numbers, not hexadecimal.\n// - It is not affected by i18n / l10n settings such as environment variables.\n// - It does allow arbitrary underscores, except inside the optional 2-byte\n// opening \"0d\" or \"0X\" that denotes base-10 or base-16." +
|
||||
" For example,\n// \"__0D_1_002\" would successfully parse as \"one thousand and two\".\nWUFFS_BASE__MAYBE_STATIC wuffs_base__result_u64 //\nwuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options);\n\n" +
|
||||
"" +
|
||||
"// --------\n\n#define WUFFS_BASE__I64__BYTE_LENGTH__MAX_INCL 20\n#define WUFFS_BASE__U64__BYTE_LENGTH__MAX_INCL 21\n\n// wuffs_base__render_number_f64 writes the decimal encoding of x to dst and\n// returns the number of bytes written. If dst is shorter than the entire\n// encoding, it returns 0 (and no bytes are written).\n//\n// For those familiar with C's printf or Go's fmt.Printf functions:\n// - \"%e\" means the WUFFS_BASE__RENDER_NUMBER_FXX__EXPONENT_PRESENT option.\n// - \"%f\" means the WUFFS_BASE__RENDER_NUMBER_FXX__EXPONENT_ABSENT option.\n// - \"%g\" means neither or both bits are set.\n//\n// The precision argument controls the number of digits rendered, excluding the\n// exponent (the \"e+05\" in \"1.23e+05\"):\n// - for \"%e\" and \"%f\" it is the number of digits after the decimal separator,\n// - for \"%g\" it is the number of significant digits (and trailing zeroes are\n// removed).\n//\n// A precision of 6 gives similar output to printf's defaults.\n//\n// A precision greater than 4095 is equivalent to 4095.\n//\n// The " +
|
||||
"precision argument is ignored when the\n// WUFFS_BASE__RENDER_NUMBER_FXX__JUST_ENOUGH_PRECISION option is set. This is\n// similar to Go's strconv.FormatFloat with a negative (i.e. non-sensical)\n// precision, but there is no corresponding feature in C's printf.\n//\n// Extreme values of x will be rendered as \"NaN\", \"Inf\" (or \"+Inf\" if the\n// WUFFS_BASE__RENDER_NUMBER_XXX__LEADING_PLUS_SIGN option is set) or \"-Inf\".\nWUFFS_BASE__MAYBE_STATIC size_t //\nwuffs_base__render_number_f64(wuffs_base__slice_u8 dst,\n double x,\n uint32_t precision,\n uint32_t options);\n\n// wuffs_base__render_number_i64 writes the decimal encoding of x to dst and\n// returns the number of bytes written. If dst is shorter than the entire\n// encoding, it returns 0 (and no bytes are written).\n//\n// dst will never be too short if its length is at least 20, also known as\n// WUFFS_BASE__I64__BYTE_LENGTH__MAX_INCL.\nWUFFS_BASE__MAYBE_STATIC size_t //\nwuffs_base__ren" +
|
||||
|
||||
@@ -3922,6 +3922,14 @@ wuffs_base__pixel_swizzler::swizzle_interleaved_from_slice(
|
||||
|
||||
// ---------------- String Conversions
|
||||
|
||||
// Options (bitwise or'ed together) for wuffs_base__parse_number_xxx
|
||||
// functions. The XXX options apply to both integer and floating point. The FXX
|
||||
// options apply only to floating point.
|
||||
|
||||
#define WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS ((uint32_t)0x00000000)
|
||||
|
||||
// --------
|
||||
|
||||
// Options (bitwise or'ed together) for wuffs_base__render_number_xxx
|
||||
// functions. The XXX options apply to both integer and floating point. The FXX
|
||||
// options apply only to floating point.
|
||||
@@ -4005,7 +4013,7 @@ wuffs_base__pixel_swizzler::swizzle_interleaved_from_slice(
|
||||
// function requires the WUFFS_CONFIG__MODULE__BASE__F64CONV sub-module, not
|
||||
// just WUFFS_CONFIG__MODULE__BASE__CORE.
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__result_f64 //
|
||||
wuffs_base__parse_number_f64(wuffs_base__slice_u8 s);
|
||||
wuffs_base__parse_number_f64(wuffs_base__slice_u8 s, uint32_t options);
|
||||
|
||||
// --------
|
||||
|
||||
@@ -4049,7 +4057,7 @@ wuffs_base__ieee_754_bit_representation__to_f64(uint64_t u) {
|
||||
// It is similar to wuffs_base__parse_number_u64 but it returns a signed
|
||||
// integer, not an unsigned integer. It also allows a leading '+' or '-'.
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__result_i64 //
|
||||
wuffs_base__parse_number_i64(wuffs_base__slice_u8 s);
|
||||
wuffs_base__parse_number_i64(wuffs_base__slice_u8 s, uint32_t options);
|
||||
|
||||
// wuffs_base__parse_number_u64 parses the ASCII integer in s. For example, if
|
||||
// s contains the bytes "123" then it will return the uint64_t 123.
|
||||
@@ -4076,7 +4084,7 @@ wuffs_base__parse_number_i64(wuffs_base__slice_u8 s);
|
||||
// opening "0d" or "0X" that denotes base-10 or base-16. For example,
|
||||
// "__0D_1_002" would successfully parse as "one thousand and two".
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__result_u64 //
|
||||
wuffs_base__parse_number_u64(wuffs_base__slice_u8 s);
|
||||
wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options);
|
||||
|
||||
// --------
|
||||
|
||||
@@ -10933,7 +10941,7 @@ wuffs_base__private_implementation__is_decimal_digit(uint8_t c) {
|
||||
}
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__result_f64 //
|
||||
wuffs_base__parse_number_f64(wuffs_base__slice_u8 s) {
|
||||
wuffs_base__parse_number_f64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
// In practice, almost all "dd.ddddE±xxx" numbers can be represented
|
||||
// losslessly by a uint64_t mantissa "dddddd" and an int32_t base-10
|
||||
// exponent, adjusting "xxx" for the position (if present) of the decimal
|
||||
@@ -11548,7 +11556,7 @@ static const uint8_t wuffs_base__parse_number__hexadecimal_digits[256] = {
|
||||
// --------
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__result_i64 //
|
||||
wuffs_base__parse_number_i64(wuffs_base__slice_u8 s) {
|
||||
wuffs_base__parse_number_i64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
uint8_t* p = s.ptr;
|
||||
uint8_t* q = s.ptr + s.len;
|
||||
|
||||
@@ -11567,7 +11575,7 @@ wuffs_base__parse_number_i64(wuffs_base__slice_u8 s) {
|
||||
|
||||
do {
|
||||
wuffs_base__result_u64 r = wuffs_base__parse_number_u64(
|
||||
wuffs_base__make_slice_u8(p, (size_t)(q - p)));
|
||||
wuffs_base__make_slice_u8(p, (size_t)(q - p)), options);
|
||||
if (r.status.repr != NULL) {
|
||||
wuffs_base__result_i64 ret;
|
||||
ret.status.repr = r.status.repr;
|
||||
@@ -11609,7 +11617,7 @@ fail_out_of_bounds:
|
||||
}
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__result_u64 //
|
||||
wuffs_base__parse_number_u64(wuffs_base__slice_u8 s) {
|
||||
wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
uint8_t* p = s.ptr;
|
||||
uint8_t* q = s.ptr + s.len;
|
||||
|
||||
|
||||
@@ -229,7 +229,8 @@ main1(int argc, char** argv) {
|
||||
|
||||
if (g_flags.parse_number_f64) {
|
||||
wuffs_base__result_f64 r = wuffs_base__parse_number_f64(
|
||||
wuffs_base__make_slice_u8(&g_src.data.ptr[buf_pos], len));
|
||||
wuffs_base__make_slice_u8(&g_src.data.ptr[buf_pos], len),
|
||||
WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);
|
||||
if (!wuffs_base__status__is_ok(&r.status)) {
|
||||
return wuffs_base__status__message(&r.status);
|
||||
}
|
||||
|
||||
+15
-10
@@ -597,9 +597,10 @@ test_wuffs_strconv_parse_number_f64() {
|
||||
|
||||
int tc;
|
||||
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
|
||||
wuffs_base__result_f64 r =
|
||||
wuffs_base__parse_number_f64(wuffs_base__make_slice_u8(
|
||||
(void*)test_cases[tc].str, strlen(test_cases[tc].str)));
|
||||
wuffs_base__result_f64 r = wuffs_base__parse_number_f64(
|
||||
wuffs_base__make_slice_u8((void*)test_cases[tc].str,
|
||||
strlen(test_cases[tc].str)),
|
||||
WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);
|
||||
uint64_t have =
|
||||
(r.status.repr == NULL)
|
||||
? wuffs_base__ieee_754_bit_representation__from_f64(r.value)
|
||||
@@ -649,9 +650,10 @@ test_wuffs_strconv_parse_number_i64() {
|
||||
|
||||
int tc;
|
||||
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
|
||||
wuffs_base__result_i64 r =
|
||||
wuffs_base__parse_number_i64(wuffs_base__make_slice_u8(
|
||||
(void*)test_cases[tc].str, strlen(test_cases[tc].str)));
|
||||
wuffs_base__result_i64 r = wuffs_base__parse_number_i64(
|
||||
wuffs_base__make_slice_u8((void*)test_cases[tc].str,
|
||||
strlen(test_cases[tc].str)),
|
||||
WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);
|
||||
int64_t have = (r.status.repr == NULL) ? r.value : fail;
|
||||
if (have != test_cases[tc].want) {
|
||||
RETURN_FAIL("\"%s\": have 0x%" PRIX64 ", want 0x%" PRIX64,
|
||||
@@ -735,9 +737,10 @@ test_wuffs_strconv_parse_number_u64() {
|
||||
|
||||
int tc;
|
||||
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
|
||||
wuffs_base__result_u64 r =
|
||||
wuffs_base__parse_number_u64(wuffs_base__make_slice_u8(
|
||||
(void*)test_cases[tc].str, strlen(test_cases[tc].str)));
|
||||
wuffs_base__result_u64 r = wuffs_base__parse_number_u64(
|
||||
wuffs_base__make_slice_u8((void*)test_cases[tc].str,
|
||||
strlen(test_cases[tc].str)),
|
||||
WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);
|
||||
uint64_t have = (r.status.repr == NULL) ? r.value : fail;
|
||||
if (have != test_cases[tc].want) {
|
||||
RETURN_FAIL("\"%s\": have 0x%" PRIX64 ", want 0x%" PRIX64,
|
||||
@@ -3190,7 +3193,9 @@ do_bench_wuffs_strconv_parse_number_f64(const char* str,
|
||||
uint64_t i;
|
||||
uint64_t iters = iters_unscaled * g_flags.iterscale;
|
||||
for (i = 0; i < iters; i++) {
|
||||
CHECK_STATUS("", wuffs_base__parse_number_f64(s).status);
|
||||
CHECK_STATUS("", wuffs_base__parse_number_f64(
|
||||
s, WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS)
|
||||
.status);
|
||||
}
|
||||
bench_finish(iters, 0);
|
||||
|
||||
|
||||
Reference in new issue
Block a user