mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Add PARSE_NUMBER_XXX__ALLOW_UNDERSCORES
This commit is contained in:
1 parent
e82bc8ec7b
commit
c5c9885db4
5 files changed
+190
-83
No files matched your search
@@ -147,11 +147,13 @@ wuffs_base__private_implementation__high_prec_dec__parse(
|
||||
uint8_t* p = s.ptr;
|
||||
uint8_t* q = s.ptr + s.len;
|
||||
|
||||
for (;; p++) {
|
||||
if (p >= q) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
} else if (*p != '_') {
|
||||
break;
|
||||
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
|
||||
for (;; p++) {
|
||||
if (p >= q) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
} else if (*p != '_') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,11 +167,13 @@ wuffs_base__private_implementation__high_prec_dec__parse(
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
for (;; p++) {
|
||||
if (p >= q) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
} else if (*p != '_') {
|
||||
break;
|
||||
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
|
||||
for (;; p++) {
|
||||
if (p >= q) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
} else if (*p != '_') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
@@ -200,7 +204,8 @@ wuffs_base__private_implementation__high_prec_dec__parse(
|
||||
} else if ((*p == 'E') || (*p == 'e')) {
|
||||
p++;
|
||||
goto after_exp;
|
||||
} else if (*p != '_') {
|
||||
} else if ((*p != '_') ||
|
||||
!(options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
}
|
||||
@@ -236,7 +241,8 @@ wuffs_base__private_implementation__high_prec_dec__parse(
|
||||
} else if ((*p == 'E') || (*p == 'e')) {
|
||||
p++;
|
||||
goto after_exp;
|
||||
} else if (*p != '_') {
|
||||
} else if ((*p != '_') ||
|
||||
!(options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
}
|
||||
@@ -274,18 +280,21 @@ after_sep:
|
||||
} else if ((*p == 'E') || (*p == 'e')) {
|
||||
p++;
|
||||
goto after_exp;
|
||||
} else if (*p != '_') {
|
||||
} else if ((*p != '_') ||
|
||||
!(options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
}
|
||||
|
||||
after_exp:
|
||||
do {
|
||||
for (;; p++) {
|
||||
if (p >= q) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
} else if (*p != '_') {
|
||||
break;
|
||||
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
|
||||
for (;; p++) {
|
||||
if (p >= q) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
} else if (*p != '_') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,7 +312,8 @@ after_exp:
|
||||
WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION;
|
||||
bool saw_exp_digits = false;
|
||||
for (; p < q; p++) {
|
||||
if (*p == '_') {
|
||||
if ((*p == '_') &&
|
||||
(options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {
|
||||
// No-op.
|
||||
} else if (('0' <= *p) && (*p <= '9')) {
|
||||
saw_exp_digits = true;
|
||||
|
||||
@@ -110,7 +110,9 @@ 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;
|
||||
|
||||
for (; (p < q) && (*p == '_'); p++) {
|
||||
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
|
||||
for (; (p < q) && (*p == '_'); p++) {
|
||||
}
|
||||
}
|
||||
|
||||
bool negative = false;
|
||||
@@ -171,7 +173,9 @@ 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;
|
||||
|
||||
for (; (p < q) && (*p == '_'); p++) {
|
||||
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
|
||||
for (; (p < q) && (*p == '_'); p++) {
|
||||
}
|
||||
}
|
||||
|
||||
if (p >= q) {
|
||||
@@ -182,23 +186,27 @@ wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
if (p >= q) {
|
||||
goto ok_zero;
|
||||
}
|
||||
if (*p == '_') {
|
||||
p++;
|
||||
for (; p < q; p++) {
|
||||
if (*p != '_') {
|
||||
if (options &
|
||||
WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES) {
|
||||
goto decimal;
|
||||
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
|
||||
if (*p == '_') {
|
||||
p++;
|
||||
for (; p < q; p++) {
|
||||
if (*p != '_') {
|
||||
if (options &
|
||||
WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES) {
|
||||
goto decimal;
|
||||
}
|
||||
goto fail_bad_argument;
|
||||
}
|
||||
goto fail_bad_argument;
|
||||
}
|
||||
goto ok_zero;
|
||||
}
|
||||
goto ok_zero;
|
||||
}
|
||||
|
||||
if ((*p == 'x') || (*p == 'X')) {
|
||||
p++;
|
||||
for (; (p < q) && (*p == '_'); p++) {
|
||||
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
|
||||
for (; (p < q) && (*p == '_'); p++) {
|
||||
}
|
||||
}
|
||||
if (p < q) {
|
||||
goto hexadecimal;
|
||||
@@ -206,7 +214,9 @@ wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
|
||||
} else if ((*p == 'd') || (*p == 'D')) {
|
||||
p++;
|
||||
for (; (p < q) && (*p == '_'); p++) {
|
||||
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
|
||||
for (; (p < q) && (*p == '_'); p++) {
|
||||
}
|
||||
}
|
||||
if (p < q) {
|
||||
goto decimal;
|
||||
@@ -232,7 +242,8 @@ decimal:
|
||||
const uint8_t max1 = 5;
|
||||
|
||||
for (; p < q; p++) {
|
||||
if (*p == '_') {
|
||||
if ((*p == '_') &&
|
||||
(options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {
|
||||
continue;
|
||||
}
|
||||
uint8_t digit = wuffs_base__parse_number__decimal_digits[*p];
|
||||
@@ -261,7 +272,8 @@ hexadecimal:
|
||||
v &= 0x0F;
|
||||
|
||||
for (; p < q; p++) {
|
||||
if (*p == '_') {
|
||||
if ((*p == '_') &&
|
||||
(options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {
|
||||
continue;
|
||||
}
|
||||
uint8_t digit = wuffs_base__parse_number__hexadecimal_digits[*p];
|
||||
|
||||
+12
-12
@@ -33,13 +33,13 @@ const BaseFloatConvSubmoduleCodeC = "" +
|
||||
"e ±2047\n// bounds are further away from zero than ±(324 + 800), where 800 and 2047 is\n// WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION and\n// WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE.\n//\n// digits[.. num_digits] are the number's digits in big-endian order. The\n// uint8_t values are in the range [0 ..= 9], not ['0' ..= '9'], where e.g. '7'\n// is the ASCII value 0x37.\n//\n// decimal_point is the index (within digits) of the decimal point. It may be\n// negative or be larger than num_digits, in which case the explicit digits are\n// padded with implicit zeroes.\n//\n// For example, if num_digits is 3 and digits is \"\\x07\\x08\\x09\":\n// - A decimal_point of -2 means \".00789\"\n// - A decimal_point of -1 means \".0789\"\n// - A decimal_point of +0 means \".789\"\n// - A decimal_point of +1 means \"7.89\"\n// - A decimal_point of +2 means \"78.9\"\n// - A decimal_point of +3 means \"789.\"\n// - A decimal_point of +4 means \"7890.\"\n// - A decimal_point of +5 means \"78900.\"\n//\n// As above, a" +
|
||||
" decimal_point higher than +2047 means that the overall value is\n// infinity, lower than -2047 means zero.\n//\n// negative is a sign bit. An HPD can distinguish positive and negative zero.\n//\n// truncated is whether there are more than\n// WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION digits, and at\n// least one of those extra digits are non-zero. The existence of long-tail\n// digits can affect rounding.\n//\n// The \"all fields are zero\" value is valid, and represents the number +0.\ntypedef struct {\n uint32_t num_digits;\n int32_t decimal_point;\n bool negative;\n bool truncated;\n uint8_t digits[WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION];\n} wuffs_base__private_implementation__high_prec_dec;\n\n// wuffs_base__private_implementation__high_prec_dec__trim trims trailing\n// zeroes from the h->digits[.. h->num_digits] slice. They have no benefit,\n// since we explicitly track h->decimal_point.\n//\n// Preconditions:\n// - h is non-NULL.\nstatic inline void //\nwuffs_base__private_implementation_" +
|
||||
"_high_prec_dec__trim(\n wuffs_base__private_implementation__high_prec_dec* h) {\n while ((h->num_digits > 0) && (h->digits[h->num_digits - 1] == 0)) {\n h->num_digits--;\n }\n}\n\n// wuffs_base__private_implementation__high_prec_dec__assign sets h to\n// represent the number x.\n//\n// Preconditions:\n// - h is non-NULL.\nstatic void //\nwuffs_base__private_implementation__high_prec_dec__assign(\n wuffs_base__private_implementation__high_prec_dec* h,\n uint64_t x,\n bool negative) {\n uint32_t n = 0;\n\n // Set h->digits.\n if (x > 0) {\n // Calculate the digits, working right-to-left. After we determine n (how\n // many digits there are), copy from buf to h->digits.\n //\n // UINT64_MAX, 18446744073709551615, is 20 digits long. It can be faster to\n // copy a constant number of bytes than a variable number (20 instead of\n // n). Make buf large enough (and start writing to it from the middle) so\n // that can we always copy 20 bytes: the slice buf[(20-n) .. (40-n)].\n uint8_t buf[40] = {0};" +
|
||||
"\n uint8_t* ptr = &buf[20];\n do {\n uint64_t remaining = x / 10;\n x -= remaining * 10;\n ptr--;\n *ptr = (uint8_t)x;\n n++;\n x = remaining;\n } while (x > 0);\n memcpy(h->digits, ptr, 20);\n }\n\n // Set h's other fields.\n h->num_digits = n;\n h->decimal_point = (int32_t)n;\n h->negative = negative;\n h->truncated = false;\n wuffs_base__private_implementation__high_prec_dec__trim(h);\n}\n\nstatic wuffs_base__status //\nwuffs_base__private_implementation__high_prec_dec__parse(\n wuffs_base__private_implementation__high_prec_dec* h,\n wuffs_base__slice_u8 s,\n uint32_t options) {\n if (!h) {\n return wuffs_base__make_status(wuffs_base__error__bad_receiver);\n }\n h->num_digits = 0;\n h->decimal_point = 0;\n h->negative = false;\n h->truncated = false;\n\n uint8_t* p = s.ptr;\n uint8_t* q = s.ptr + s.len;\n\n for (;; p++) {\n if (p >= q) {\n return wuffs_base__make_status(wuffs_base__error__bad_argument);\n } else if (*p != '_') {\n break;\n }\n }\n\n // Parse s" +
|
||||
"ign.\n do {\n if (*p == '+') {\n p++;\n } else if (*p == '-') {\n h->negative = true;\n p++;\n } else {\n break;\n }\n for (;; p++) {\n if (p >= q) {\n return wuffs_base__make_status(wuffs_base__error__bad_argument);\n } else if (*p != '_') {\n break;\n }\n }\n } while (0);\n\n // Parse digits, up to (and including) a '.', 'E' or 'e'. Examples for each\n // limb in this if-else chain:\n // - \"0.789\"\n // - \"1002.789\"\n // - \".789\"\n // - Other (invalid input).\n uint32_t nd = 0;\n int32_t dp = 0;\n bool no_digits_before_separator = false;\n if (('0' == *p) &&\n !(options &\n WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES)) {\n p++;\n for (;; p++) {\n if (p >= q) {\n goto after_all;\n } else if (*p ==\n ((options &\n WUFFS_BASE__PARSE_NUMBER_FXX__DECIMAL_SEPARATOR_IS_A_COMMA)\n ? ','\n : '.')) {\n p++;\n goto after_sep;\n } else " +
|
||||
"if ((*p == 'E') || (*p == 'e')) {\n p++;\n goto after_exp;\n } else if (*p != '_') {\n return wuffs_base__make_status(wuffs_base__error__bad_argument);\n }\n }\n\n } else if (('0' <= *p) && (*p <= '9')) {\n if (*p == '0') {\n for (; (p < q) && (*p == '0'); p++) {\n }\n } else {\n h->digits[nd++] = (uint8_t)(*p - '0');\n dp = (int32_t)nd;\n p++;\n }\n\n for (;; p++) {\n if (p >= q) {\n goto after_all;\n } else if (('0' <= *p) && (*p <= '9')) {\n if (nd < WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {\n h->digits[nd++] = (uint8_t)(*p - '0');\n dp = (int32_t)nd;\n } else if ('0' != *p) {\n // Long-tail non-zeroes set the truncated bit.\n h->truncated = true;\n }\n } else if (*p ==\n ((options &\n WUFFS_BASE__PARSE_NUMBER_FXX__DECIMAL_SEPARATOR_IS_A_COMMA)\n ? ','\n : '.')) {\n p++;\n goto after_s" +
|
||||
"ep;\n } else if ((*p == 'E') || (*p == 'e')) {\n p++;\n goto after_exp;\n } else if (*p != '_') {\n return wuffs_base__make_status(wuffs_base__error__bad_argument);\n }\n }\n\n } else if (*p == ((options &\n WUFFS_BASE__PARSE_NUMBER_FXX__DECIMAL_SEPARATOR_IS_A_COMMA)\n ? ','\n : '.')) {\n p++;\n no_digits_before_separator = true;\n\n } else {\n return wuffs_base__make_status(wuffs_base__error__bad_argument);\n }\n\nafter_sep:\n for (;; p++) {\n if (p >= q) {\n goto after_all;\n } else if ('0' == *p) {\n if (nd == 0) {\n // Track leading zeroes implicitly.\n dp--;\n } else if (nd <\n WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {\n h->digits[nd++] = (uint8_t)(*p - '0');\n }\n } else if (('0' < *p) && (*p <= '9')) {\n if (nd < WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {\n h->digits[nd++] = (uint8_t)(*p - '0');\n } els" +
|
||||
"e {\n // Long-tail non-zeroes set the truncated bit.\n h->truncated = true;\n }\n } else if ((*p == 'E') || (*p == 'e')) {\n p++;\n goto after_exp;\n } else if (*p != '_') {\n return wuffs_base__make_status(wuffs_base__error__bad_argument);\n }\n }\n\nafter_exp:\n do {\n for (;; p++) {\n if (p >= q) {\n return wuffs_base__make_status(wuffs_base__error__bad_argument);\n } else if (*p != '_') {\n break;\n }\n }\n\n int32_t exp_sign = +1;\n if (*p == '+') {\n p++;\n } else if (*p == '-') {\n exp_sign = -1;\n p++;\n }\n\n int32_t exp = 0;\n const int32_t exp_large =\n WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE +\n WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION;\n bool saw_exp_digits = false;\n for (; p < q; p++) {\n if (*p == '_') {\n // No-op.\n } else if (('0' <= *p) && (*p <= '9')) {\n saw_exp_digits = true;\n if (exp < exp_large) {\n exp = (10 * exp)" +
|
||||
" + ((int32_t)(*p - '0'));\n }\n } else {\n break;\n }\n }\n if (!saw_exp_digits) {\n return wuffs_base__make_status(wuffs_base__error__bad_argument);\n }\n dp += exp_sign * exp;\n } while (0);\n\nafter_all:\n if (p != q) {\n return wuffs_base__make_status(wuffs_base__error__bad_argument);\n }\n h->num_digits = nd;\n if (nd == 0) {\n if (no_digits_before_separator) {\n return wuffs_base__make_status(wuffs_base__error__bad_argument);\n }\n h->decimal_point = 0;\n } else if (dp <\n -WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE) {\n h->decimal_point =\n -WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE - 1;\n } else if (dp >\n +WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE) {\n h->decimal_point =\n +WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE + 1;\n } else {\n h->decimal_point = dp;\n }\n wuffs_base__private_implementation__high_prec_dec__trim(h);\n return wuffs_base__m" +
|
||||
"ake_status(NULL);\n}\n\n" +
|
||||
"\n uint8_t* ptr = &buf[20];\n do {\n uint64_t remaining = x / 10;\n x -= remaining * 10;\n ptr--;\n *ptr = (uint8_t)x;\n n++;\n x = remaining;\n } while (x > 0);\n memcpy(h->digits, ptr, 20);\n }\n\n // Set h's other fields.\n h->num_digits = n;\n h->decimal_point = (int32_t)n;\n h->negative = negative;\n h->truncated = false;\n wuffs_base__private_implementation__high_prec_dec__trim(h);\n}\n\nstatic wuffs_base__status //\nwuffs_base__private_implementation__high_prec_dec__parse(\n wuffs_base__private_implementation__high_prec_dec* h,\n wuffs_base__slice_u8 s,\n uint32_t options) {\n if (!h) {\n return wuffs_base__make_status(wuffs_base__error__bad_receiver);\n }\n h->num_digits = 0;\n h->decimal_point = 0;\n h->negative = false;\n h->truncated = false;\n\n uint8_t* p = s.ptr;\n uint8_t* q = s.ptr + s.len;\n\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n for (;; p++) {\n if (p >= q) {\n return wuffs_base__make_status(wuffs_base__error__bad_ar" +
|
||||
"gument);\n } else if (*p != '_') {\n break;\n }\n }\n }\n\n // Parse sign.\n do {\n if (*p == '+') {\n p++;\n } else if (*p == '-') {\n h->negative = true;\n p++;\n } else {\n break;\n }\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n for (;; p++) {\n if (p >= q) {\n return wuffs_base__make_status(wuffs_base__error__bad_argument);\n } else if (*p != '_') {\n break;\n }\n }\n }\n } while (0);\n\n // Parse digits, up to (and including) a '.', 'E' or 'e'. Examples for each\n // limb in this if-else chain:\n // - \"0.789\"\n // - \"1002.789\"\n // - \".789\"\n // - Other (invalid input).\n uint32_t nd = 0;\n int32_t dp = 0;\n bool no_digits_before_separator = false;\n if (('0' == *p) &&\n !(options &\n WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES)) {\n p++;\n for (;; p++) {\n if (p >= q) {\n goto after_all;\n } else if (*p ==\n ((options &\n " +
|
||||
" WUFFS_BASE__PARSE_NUMBER_FXX__DECIMAL_SEPARATOR_IS_A_COMMA)\n ? ','\n : '.')) {\n p++;\n goto after_sep;\n } else if ((*p == 'E') || (*p == 'e')) {\n p++;\n goto after_exp;\n } else if ((*p != '_') ||\n !(options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {\n return wuffs_base__make_status(wuffs_base__error__bad_argument);\n }\n }\n\n } else if (('0' <= *p) && (*p <= '9')) {\n if (*p == '0') {\n for (; (p < q) && (*p == '0'); p++) {\n }\n } else {\n h->digits[nd++] = (uint8_t)(*p - '0');\n dp = (int32_t)nd;\n p++;\n }\n\n for (;; p++) {\n if (p >= q) {\n goto after_all;\n } else if (('0' <= *p) && (*p <= '9')) {\n if (nd < WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {\n h->digits[nd++] = (uint8_t)(*p - '0');\n dp = (int32_t)nd;\n } else if ('0' != *p) {\n // Long-tail non-zeroes set the truncated bit.\n " +
|
||||
" h->truncated = true;\n }\n } else if (*p ==\n ((options &\n WUFFS_BASE__PARSE_NUMBER_FXX__DECIMAL_SEPARATOR_IS_A_COMMA)\n ? ','\n : '.')) {\n p++;\n goto after_sep;\n } else if ((*p == 'E') || (*p == 'e')) {\n p++;\n goto after_exp;\n } else if ((*p != '_') ||\n !(options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {\n return wuffs_base__make_status(wuffs_base__error__bad_argument);\n }\n }\n\n } else if (*p == ((options &\n WUFFS_BASE__PARSE_NUMBER_FXX__DECIMAL_SEPARATOR_IS_A_COMMA)\n ? ','\n : '.')) {\n p++;\n no_digits_before_separator = true;\n\n } else {\n return wuffs_base__make_status(wuffs_base__error__bad_argument);\n }\n\nafter_sep:\n for (;; p++) {\n if (p >= q) {\n goto after_all;\n } else if ('0' == *p) {\n if (nd == 0) {\n // Track leading zeroes implicitly.\n " +
|
||||
" dp--;\n } else if (nd <\n WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {\n h->digits[nd++] = (uint8_t)(*p - '0');\n }\n } else if (('0' < *p) && (*p <= '9')) {\n if (nd < WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {\n h->digits[nd++] = (uint8_t)(*p - '0');\n } else {\n // Long-tail non-zeroes set the truncated bit.\n h->truncated = true;\n }\n } else if ((*p == 'E') || (*p == 'e')) {\n p++;\n goto after_exp;\n } else if ((*p != '_') ||\n !(options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {\n return wuffs_base__make_status(wuffs_base__error__bad_argument);\n }\n }\n\nafter_exp:\n do {\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n for (;; p++) {\n if (p >= q) {\n return wuffs_base__make_status(wuffs_base__error__bad_argument);\n } else if (*p != '_') {\n break;\n }\n }\n }\n\n int32_t exp_sign = +1;\n if (*p ==" +
|
||||
" '+') {\n p++;\n } else if (*p == '-') {\n exp_sign = -1;\n p++;\n }\n\n int32_t exp = 0;\n const int32_t exp_large =\n WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE +\n WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION;\n bool saw_exp_digits = false;\n for (; p < q; p++) {\n if ((*p == '_') &&\n (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {\n // No-op.\n } else if (('0' <= *p) && (*p <= '9')) {\n saw_exp_digits = true;\n if (exp < exp_large) {\n exp = (10 * exp) + ((int32_t)(*p - '0'));\n }\n } else {\n break;\n }\n }\n if (!saw_exp_digits) {\n return wuffs_base__make_status(wuffs_base__error__bad_argument);\n }\n dp += exp_sign * exp;\n } while (0);\n\nafter_all:\n if (p != q) {\n return wuffs_base__make_status(wuffs_base__error__bad_argument);\n }\n h->num_digits = nd;\n if (nd == 0) {\n if (no_digits_before_separator) {\n return wuffs_base__make_status" +
|
||||
"(wuffs_base__error__bad_argument);\n }\n h->decimal_point = 0;\n } else if (dp <\n -WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE) {\n h->decimal_point =\n -WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE - 1;\n } else if (dp >\n +WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE) {\n h->decimal_point =\n +WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DECIMAL_POINT__RANGE + 1;\n } else {\n h->decimal_point = dp;\n }\n wuffs_base__private_implementation__high_prec_dec__trim(h);\n return wuffs_base__make_status(NULL);\n}\n\n" +
|
||||
"" +
|
||||
"// --------\n\n// wuffs_base__private_implementation__high_prec_dec__lshift_num_new_digits\n// returns the number of additional decimal digits when left-shifting by shift.\n//\n// See below for preconditions.\nstatic uint32_t //\nwuffs_base__private_implementation__high_prec_dec__lshift_num_new_digits(\n wuffs_base__private_implementation__high_prec_dec* h,\n uint32_t shift) {\n // Masking with 0x3F should be unnecessary (assuming the preconditions) but\n // it's cheap and ensures that we don't overflow the\n // wuffs_base__private_implementation__hpd_left_shift array.\n shift &= 63;\n\n uint32_t x_a = wuffs_base__private_implementation__hpd_left_shift[shift];\n uint32_t x_b = wuffs_base__private_implementation__hpd_left_shift[shift + 1];\n uint32_t num_new_digits = x_a >> 11;\n uint32_t pow5_a = 0x7FF & x_a;\n uint32_t pow5_b = 0x7FF & x_b;\n\n const uint8_t* pow5 =\n &wuffs_base__private_implementation__powers_of_5[pow5_a];\n uint32_t i = 0;\n uint32_t n = pow5_b - pow5_a;\n for (; i < n; i++) {\n if (i >" +
|
||||
"= h->num_digits) {\n return num_new_digits - 1;\n } else if (h->digits[i] == pow5[i]) {\n continue;\n } else if (h->digits[i] < pow5[i]) {\n return num_new_digits - 1;\n } else {\n return num_new_digits;\n }\n }\n return num_new_digits;\n}\n\n" +
|
||||
@@ -166,11 +166,11 @@ const BaseIntConvSubmoduleC = "" +
|
||||
" 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, 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 if (options &\n WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES) {\n goto decimal;\n }\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 if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES) {\n goto decimal;\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 r" +
|
||||
"eturn 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 if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n for (; (p < q) && (*p == '_'); p++) {\n }\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 > 0x7FFFFFFFFFFF" +
|
||||
"FFFF) {\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, uint32_t options) {\n uint8_t* p = s.ptr;\n uint8_t* q = s.ptr + s.len;\n\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n for (; (p < q) && (*p == '_'); p++) {\n }\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 (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n " +
|
||||
"if (*p == '_') {\n p++;\n for (; p < q; p++) {\n if (*p != '_') {\n if (options &\n WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES) {\n goto decimal;\n }\n goto fail_bad_argument;\n }\n }\n goto ok_zero;\n }\n }\n\n if ((*p == 'x') || (*p == 'X')) {\n p++;\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n for (; (p < q) && (*p == '_'); p++) {\n }\n }\n if (p < q) {\n goto hexadecimal;\n }\n\n } else if ((*p == 'd') || (*p == 'D')) {\n p++;\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n for (; (p < q) && (*p == '_'); p++) {\n }\n }\n if (p < q) {\n goto decimal;\n }\n }\n\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES) {\n goto decimal;\n }\n goto fail_bad_argument;\n }\n\ndecimal:\n do {\n uint64_t v = wuffs_base__parse_number__decimal_digi" +
|
||||
"ts[*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 (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {\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 (options" +
|
||||
" & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {\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\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 " +
|
||||
|
||||
@@ -10028,11 +10028,13 @@ wuffs_base__private_implementation__high_prec_dec__parse(
|
||||
uint8_t* p = s.ptr;
|
||||
uint8_t* q = s.ptr + s.len;
|
||||
|
||||
for (;; p++) {
|
||||
if (p >= q) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
} else if (*p != '_') {
|
||||
break;
|
||||
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
|
||||
for (;; p++) {
|
||||
if (p >= q) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
} else if (*p != '_') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10046,11 +10048,13 @@ wuffs_base__private_implementation__high_prec_dec__parse(
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
for (;; p++) {
|
||||
if (p >= q) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
} else if (*p != '_') {
|
||||
break;
|
||||
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
|
||||
for (;; p++) {
|
||||
if (p >= q) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
} else if (*p != '_') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
@@ -10081,7 +10085,8 @@ wuffs_base__private_implementation__high_prec_dec__parse(
|
||||
} else if ((*p == 'E') || (*p == 'e')) {
|
||||
p++;
|
||||
goto after_exp;
|
||||
} else if (*p != '_') {
|
||||
} else if ((*p != '_') ||
|
||||
!(options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
}
|
||||
@@ -10117,7 +10122,8 @@ wuffs_base__private_implementation__high_prec_dec__parse(
|
||||
} else if ((*p == 'E') || (*p == 'e')) {
|
||||
p++;
|
||||
goto after_exp;
|
||||
} else if (*p != '_') {
|
||||
} else if ((*p != '_') ||
|
||||
!(options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
}
|
||||
@@ -10155,18 +10161,21 @@ after_sep:
|
||||
} else if ((*p == 'E') || (*p == 'e')) {
|
||||
p++;
|
||||
goto after_exp;
|
||||
} else if (*p != '_') {
|
||||
} else if ((*p != '_') ||
|
||||
!(options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
}
|
||||
|
||||
after_exp:
|
||||
do {
|
||||
for (;; p++) {
|
||||
if (p >= q) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
} else if (*p != '_') {
|
||||
break;
|
||||
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
|
||||
for (;; p++) {
|
||||
if (p >= q) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
} else if (*p != '_') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10184,7 +10193,8 @@ after_exp:
|
||||
WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION;
|
||||
bool saw_exp_digits = false;
|
||||
for (; p < q; p++) {
|
||||
if (*p == '_') {
|
||||
if ((*p == '_') &&
|
||||
(options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {
|
||||
// No-op.
|
||||
} else if (('0' <= *p) && (*p <= '9')) {
|
||||
saw_exp_digits = true;
|
||||
@@ -11767,7 +11777,9 @@ 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;
|
||||
|
||||
for (; (p < q) && (*p == '_'); p++) {
|
||||
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
|
||||
for (; (p < q) && (*p == '_'); p++) {
|
||||
}
|
||||
}
|
||||
|
||||
bool negative = false;
|
||||
@@ -11828,7 +11840,9 @@ 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;
|
||||
|
||||
for (; (p < q) && (*p == '_'); p++) {
|
||||
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
|
||||
for (; (p < q) && (*p == '_'); p++) {
|
||||
}
|
||||
}
|
||||
|
||||
if (p >= q) {
|
||||
@@ -11839,23 +11853,27 @@ wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
if (p >= q) {
|
||||
goto ok_zero;
|
||||
}
|
||||
if (*p == '_') {
|
||||
p++;
|
||||
for (; p < q; p++) {
|
||||
if (*p != '_') {
|
||||
if (options &
|
||||
WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES) {
|
||||
goto decimal;
|
||||
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
|
||||
if (*p == '_') {
|
||||
p++;
|
||||
for (; p < q; p++) {
|
||||
if (*p != '_') {
|
||||
if (options &
|
||||
WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES) {
|
||||
goto decimal;
|
||||
}
|
||||
goto fail_bad_argument;
|
||||
}
|
||||
goto fail_bad_argument;
|
||||
}
|
||||
goto ok_zero;
|
||||
}
|
||||
goto ok_zero;
|
||||
}
|
||||
|
||||
if ((*p == 'x') || (*p == 'X')) {
|
||||
p++;
|
||||
for (; (p < q) && (*p == '_'); p++) {
|
||||
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
|
||||
for (; (p < q) && (*p == '_'); p++) {
|
||||
}
|
||||
}
|
||||
if (p < q) {
|
||||
goto hexadecimal;
|
||||
@@ -11863,7 +11881,9 @@ wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
|
||||
} else if ((*p == 'd') || (*p == 'D')) {
|
||||
p++;
|
||||
for (; (p < q) && (*p == '_'); p++) {
|
||||
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
|
||||
for (; (p < q) && (*p == '_'); p++) {
|
||||
}
|
||||
}
|
||||
if (p < q) {
|
||||
goto decimal;
|
||||
@@ -11889,7 +11909,8 @@ decimal:
|
||||
const uint8_t max1 = 5;
|
||||
|
||||
for (; p < q; p++) {
|
||||
if (*p == '_') {
|
||||
if ((*p == '_') &&
|
||||
(options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {
|
||||
continue;
|
||||
}
|
||||
uint8_t digit = wuffs_base__parse_number__decimal_digits[*p];
|
||||
@@ -11918,7 +11939,8 @@ hexadecimal:
|
||||
v &= 0x0F;
|
||||
|
||||
for (; p < q; p++) {
|
||||
if (*p == '_') {
|
||||
if ((*p == '_') &&
|
||||
(options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {
|
||||
continue;
|
||||
}
|
||||
uint8_t digit = wuffs_base__parse_number__hexadecimal_digits[*p];
|
||||
|
||||
+66
-3
@@ -396,6 +396,40 @@ test_wuffs_strconv_hpd_rounded_integer() {
|
||||
}
|
||||
}
|
||||
|
||||
// Test WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES.
|
||||
{
|
||||
int o;
|
||||
for (o = 0; o < 2; o++) {
|
||||
wuffs_base__private_implementation__high_prec_dec hpd;
|
||||
const char* str = "_1.2__5";
|
||||
wuffs_base__status status =
|
||||
wuffs_base__private_implementation__high_prec_dec__parse(
|
||||
&hpd, wuffs_base__make_slice_u8((void*)str, strlen(str)),
|
||||
(o ? WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES
|
||||
: WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS));
|
||||
|
||||
if (o == 0) {
|
||||
if (status.repr != wuffs_base__error__bad_argument) {
|
||||
RETURN_FAIL("ALLOW_UNDERSCORES off: have \"%s\", want \"%s\"",
|
||||
status.repr, wuffs_base__error__bad_argument);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
CHECK_STATUS("ALLOW_UNDERSCORES on", status);
|
||||
wuffs_base__result_f64 r =
|
||||
wuffs_base__private_implementation__high_prec_dec__to_f64(&hpd, 0);
|
||||
uint64_t have =
|
||||
wuffs_base__ieee_754_bit_representation__from_f64(r.value);
|
||||
uint64_t want = 0x3FF4000000000000;
|
||||
if (have != want) {
|
||||
RETURN_FAIL("ALLOW_UNDERSCORES on: have 0x%016" PRIX64
|
||||
", want 0x%016" PRIX64,
|
||||
have, want);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test WUFFS_BASE__PARSE_NUMBER_FXX__DECIMAL_SEPARATOR_IS_A_COMMA.
|
||||
{
|
||||
int o;
|
||||
@@ -800,7 +834,7 @@ test_wuffs_strconv_parse_number_f64() {
|
||||
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);
|
||||
WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES);
|
||||
uint64_t have =
|
||||
(r.status.repr == NULL)
|
||||
? wuffs_base__ieee_754_bit_representation__from_f64(r.value)
|
||||
@@ -853,7 +887,7 @@ test_wuffs_strconv_parse_number_i64() {
|
||||
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);
|
||||
WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES);
|
||||
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,
|
||||
@@ -940,7 +974,7 @@ test_wuffs_strconv_parse_number_u64() {
|
||||
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);
|
||||
WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES);
|
||||
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,
|
||||
@@ -977,6 +1011,35 @@ test_wuffs_strconv_parse_number_u64() {
|
||||
}
|
||||
}
|
||||
|
||||
// Test WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES.
|
||||
{
|
||||
int o;
|
||||
for (o = 0; o < 2; o++) {
|
||||
const char* str = "56_7__8";
|
||||
wuffs_base__result_u64 r = wuffs_base__parse_number_u64(
|
||||
wuffs_base__make_slice_u8((void*)str, strlen(str)),
|
||||
(o ? WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES
|
||||
: WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS));
|
||||
|
||||
if (o == 0) {
|
||||
if (r.status.repr != wuffs_base__error__bad_argument) {
|
||||
RETURN_FAIL(
|
||||
"ALLOW_MULTIPLE_LEADING_ZEROES off: have \"%s\", want \"%s\"",
|
||||
r.status.repr, wuffs_base__error__bad_argument);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
CHECK_STATUS("ALLOW_MULTIPLE_LEADING_ZEROES on", r.status);
|
||||
uint64_t want = 5678;
|
||||
if (r.value != want) {
|
||||
RETURN_FAIL("ALLOW_MULTIPLE_LEADING_ZEROES on: have %" PRIu64
|
||||
", want %" PRIu64,
|
||||
r.value, want);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user