Ignore FASTFLOAT_ALLOWS_LEADING_PLUS for JSON format

This commit is contained in:
Maya Warrier 2023-09-14 19:50:21 -04:00
parent 4de8d715e6
commit 2395482ad5
2 changed files with 5 additions and 2 deletions

View File

@ -280,7 +280,7 @@ parsed_number_string_t<UC> parse_number_string(UC const *p, UC const * pend, par
answer.too_many_digits = false;
answer.negative = (*p == UC('-'));
#ifdef FASTFLOAT_ALLOWS_LEADING_PLUS // disabled by default
if ((*p == UC('-')) || (*p == UC('+'))) {
if ((*p == UC('-')) || (fmt != chars_format::json && *p == UC('+'))) {
#else
if (*p == UC('-')) { // C++17 20.19.3.(7.1) explicitly forbids '+' sign here
#endif

View File

@ -3,13 +3,16 @@
#include <iostream>
#include <vector>
// test that this option is ignored
#define FASTFLOAT_ALLOWS_LEADING_PLUS
#include "fast_float/fast_float.h"
int main()
{
const std::vector<double> expected{ -0.2, 0.02, 0.002, 1., 0. };
const std::vector<std::string> accept{ "-0.2", "0.02", "0.002", "1e+0000", "0e-2" };
const std::vector<std::string> reject{ "-.2", "00.02", "0.e+1", "00.e+1", ".25"};
const std::vector<std::string> reject{ "-.2", "00.02", "0.e+1", "00.e+1", ".25", "+0.25"};
const auto fmt = fast_float::chars_format::json;
for (std::size_t i = 0; i < accept.size(); ++i)