Commit 54a41391 authored by Niels's avatar Niels

cleanup after #191

parent ad5d1dab
......@@ -390,7 +390,7 @@ I deeply appreciate the help of the following people.
- [406345](https://github.com/406345) fixed two small warnings.
- [Glen Fernandes](https://github.com/glenfe) noted a potential portability problem in the `has_mapped_type` function.
- [Corbin Hughes](https://github.com/nibroc) fixed some typos in the contribution guidelines.
- [twelsby](https://github.com/twelsby) fixed the array subscript operator and an issue that failed the MSVC build.
- [twelsby](https://github.com/twelsby) fixed the array subscript operator, an issue that failed the MSVC build, and floating-point parsing/dumping.
Thanks a lot for helping out!
......@@ -407,7 +407,7 @@ $ make
$ ./json_unit "*"
===============================================================================
All tests passed (3343318 assertions in 29 test cases)
All tests passed (3343329 assertions in 29 test cases)
```
For more information, have a look at the file [.travis.yml](https://github.com/nlohmann/json/blob/master/.travis.yml).
......@@ -5604,13 +5604,20 @@ class basic_json
case value_t::number_float:
{
// If the number is an integer then output as a fixed with with precision 1
// to output "0.0", "1.0" etc as expected for some round trip tests otherwise
// 15 digits of precision allows round-trip IEEE 754 string->double->string;
// to be safe, we read this value from std::numeric_limits<number_float_t>::digits10
if (std::fmod(m_value.number_float, 1) == 0) o << std::fixed << std::setprecision(1);
else {
o.unsetf(std::ios_base::floatfield); // std::defaultfloat not supported in gcc version < 5
// If the number is an integer then output as a fixed with with
// precision 1 to output "0.0", "1.0" etc as expected for some
// round trip tests otherwise 15 digits of precision allows
// round-trip IEEE 754 string->double->string; to be safe, we
// read this value from
// std::numeric_limits<number_float_t>::digits10
if (std::fmod(m_value.number_float, 1) == 0)
{
o << std::fixed << std::setprecision(1);
}
else
{
// std::defaultfloat not supported in gcc version < 5
o.unsetf(std::ios_base::floatfield);
o << std::setprecision(std::numeric_limits<double>::digits10);
}
o << m_value.number_float;
......@@ -6818,386 +6825,789 @@ class basic_json
m_start = m_cursor;
assert(m_start != nullptr);
{
lexer_char_t yych;
unsigned int yyaccept = 0;
static const unsigned char yybm[] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 32, 32, 0, 0, 32, 0, 0,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
96, 64, 0, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
192, 192, 192, 192, 192, 192, 192, 192,
192, 192, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 0, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
};
if ((m_limit - m_cursor) < 5) yyfill(); // LCOV_EXCL_LINE;
yych = *m_cursor;
if (yych <= ':') {
if (yych <= ' ') {
if (yych <= '\n') {
if (yych <= 0x00) goto basic_json_parser_28;
if (yych <= 0x08) goto basic_json_parser_30;
if (yych >= '\n') goto basic_json_parser_4;
} else {
if (yych == '\r') goto basic_json_parser_2;
if (yych <= 0x1F) goto basic_json_parser_30;
}
} else {
if (yych <= ',') {
if (yych == '"') goto basic_json_parser_27;
if (yych <= '+') goto basic_json_parser_30;
goto basic_json_parser_16;
} else {
if (yych <= '/') {
if (yych <= '-') goto basic_json_parser_23;
goto basic_json_parser_30;
} else {
if (yych <= '0') goto basic_json_parser_24;
if (yych <= '9') goto basic_json_parser_26;
goto basic_json_parser_18;
{
lexer_char_t yych;
unsigned int yyaccept = 0;
static const unsigned char yybm[] =
{
0, 0, 0, 0, 0, 0, 0, 0,
0, 32, 32, 0, 0, 32, 0, 0,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
96, 64, 0, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
192, 192, 192, 192, 192, 192, 192, 192,
192, 192, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 0, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
};
if ((m_limit - m_cursor) < 5)
{
yyfill(); // LCOV_EXCL_LINE;
}
yych = *m_cursor;
if (yych <= ':')
{
if (yych <= ' ')
{
if (yych <= '\n')
{
if (yych <= 0x00)
{
goto basic_json_parser_28;
}
if (yych <= 0x08)
{
goto basic_json_parser_30;
}
if (yych >= '\n')
{
goto basic_json_parser_4;
}
}
else
{
if (yych == '\r')
{
goto basic_json_parser_2;
}
if (yych <= 0x1F)
{
goto basic_json_parser_30;
}
}
}
else
{
if (yych <= ',')
{
if (yych == '"')
{
goto basic_json_parser_27;
}
if (yych <= '+')
{
goto basic_json_parser_30;
}
goto basic_json_parser_16;
}
else
{
if (yych <= '/')
{
if (yych <= '-')
{
goto basic_json_parser_23;
}
goto basic_json_parser_30;
}
else
{
if (yych <= '0')
{
goto basic_json_parser_24;
}
if (yych <= '9')
{
goto basic_json_parser_26;
}
goto basic_json_parser_18;
}
}
}
}
}
} else {
if (yych <= 'n') {
if (yych <= ']') {
if (yych == '[') goto basic_json_parser_8;
if (yych <= '\\') goto basic_json_parser_30;
goto basic_json_parser_10;
} else {
if (yych == 'f') goto basic_json_parser_22;
if (yych <= 'm') goto basic_json_parser_30;
goto basic_json_parser_20;
}
} else {
if (yych <= '{') {
if (yych == 't') goto basic_json_parser_21;
if (yych <= 'z') goto basic_json_parser_30;
goto basic_json_parser_12;
} else {
if (yych <= '}') {
if (yych <= '|') goto basic_json_parser_30;
goto basic_json_parser_14;
} else {
if (yych == 0xEF) goto basic_json_parser_6;
goto basic_json_parser_30;
else
{
if (yych <= 'n')
{
if (yych <= ']')
{
if (yych == '[')
{
goto basic_json_parser_8;
}
if (yych <= '\\')
{
goto basic_json_parser_30;
}
goto basic_json_parser_10;
}
else
{
if (yych == 'f')
{
goto basic_json_parser_22;
}
if (yych <= 'm')
{
goto basic_json_parser_30;
}
goto basic_json_parser_20;
}
}
else
{
if (yych <= '{')
{
if (yych == 't')
{
goto basic_json_parser_21;
}
if (yych <= 'z')
{
goto basic_json_parser_30;
}
goto basic_json_parser_12;
}
else
{
if (yych <= '}')
{
if (yych <= '|')
{
goto basic_json_parser_30;
}
goto basic_json_parser_14;
}
else
{
if (yych == 0xEF)
{
goto basic_json_parser_6;
}
goto basic_json_parser_30;
}
}
}
}
}
}
basic_json_parser_2:
++m_cursor;
yych = *m_cursor;
goto basic_json_parser_5;
++m_cursor;
yych = *m_cursor;
goto basic_json_parser_5;
basic_json_parser_3:
{ return scan(); }
{
return scan();
}
basic_json_parser_4:
++m_cursor;
if (m_limit <= m_cursor) yyfill(); // LCOV_EXCL_LINE;
yych = *m_cursor;
++m_cursor;
if (m_limit <= m_cursor)
{
yyfill(); // LCOV_EXCL_LINE;
}
yych = *m_cursor;
basic_json_parser_5:
if (yybm[0+yych] & 32) {
goto basic_json_parser_4;
}
goto basic_json_parser_3;
if (yybm[0 + yych] & 32)
{
goto basic_json_parser_4;
}
goto basic_json_parser_3;
basic_json_parser_6:
yyaccept = 0;
yych = *(m_marker = ++m_cursor);
if (yych == 0xBB) goto basic_json_parser_64;
yyaccept = 0;
yych = *(m_marker = ++m_cursor);
if (yych == 0xBB)
{
goto basic_json_parser_64;
}
basic_json_parser_7:
{ return token_type::parse_error; }
{
return token_type::parse_error;
}
basic_json_parser_8:
++m_cursor;
{ return token_type::begin_array; }
++m_cursor;
{
return token_type::begin_array;
}
basic_json_parser_10:
++m_cursor;
{ return token_type::end_array; }
++m_cursor;
{
return token_type::end_array;
}
basic_json_parser_12:
++m_cursor;
{ return token_type::begin_object; }
++m_cursor;
{
return token_type::begin_object;
}
basic_json_parser_14:
++m_cursor;
{ return token_type::end_object; }
++m_cursor;
{
return token_type::end_object;
}
basic_json_parser_16:
++m_cursor;
{ return token_type::value_separator; }
++m_cursor;
{
return token_type::value_separator;
}
basic_json_parser_18:
++m_cursor;
{ return token_type::name_separator; }
++m_cursor;
{
return token_type::name_separator;
}
basic_json_parser_20:
yyaccept = 0;
yych = *(m_marker = ++m_cursor);
if (yych == 'u') goto basic_json_parser_60;
goto basic_json_parser_7;
yyaccept = 0;
yych = *(m_marker = ++m_cursor);
if (yych == 'u')
{
goto basic_json_parser_60;
}
goto basic_json_parser_7;
basic_json_parser_21:
yyaccept = 0;
yych = *(m_marker = ++m_cursor);
if (yych == 'r') goto basic_json_parser_56;
goto basic_json_parser_7;
yyaccept = 0;
yych = *(m_marker = ++m_cursor);
if (yych == 'r')
{
goto basic_json_parser_56;
}
goto basic_json_parser_7;
basic_json_parser_22:
yyaccept = 0;
yych = *(m_marker = ++m_cursor);
if (yych == 'a') goto basic_json_parser_51;
goto basic_json_parser_7;
yyaccept = 0;
yych = *(m_marker = ++m_cursor);
if (yych == 'a')
{
goto basic_json_parser_51;
}
goto basic_json_parser_7;
basic_json_parser_23:
yych = *++m_cursor;
if (yych <= '/') goto basic_json_parser_7;
if (yych <= '0') goto basic_json_parser_50;
if (yych <= '9') goto basic_json_parser_41;
goto basic_json_parser_7;
yych = *++m_cursor;
if (yych <= '/')
{
goto basic_json_parser_7;
}
if (yych <= '0')
{
goto basic_json_parser_50;
}
if (yych <= '9')
{
goto basic_json_parser_41;
}
goto basic_json_parser_7;
basic_json_parser_24:
yyaccept = 1;
yych = *(m_marker = ++m_cursor);
if (yych <= 'D') {
if (yych == '.') goto basic_json_parser_43;
} else {
if (yych <= 'E') goto basic_json_parser_44;
if (yych == 'e') goto basic_json_parser_44;
}
yyaccept = 1;
yych = *(m_marker = ++m_cursor);
if (yych <= 'D')
{
if (yych == '.')
{
goto basic_json_parser_43;
}
}
else
{
if (yych <= 'E')
{
goto basic_json_parser_44;
}
if (yych == 'e')
{
goto basic_json_parser_44;
}
}
basic_json_parser_25:
{ return token_type::value_number; }
{
return token_type::value_number;
}
basic_json_parser_26:
yyaccept = 1;
yych = *(m_marker = ++m_cursor);
goto basic_json_parser_42;
yyaccept = 1;
yych = *(m_marker = ++m_cursor);
goto basic_json_parser_42;
basic_json_parser_27:
yyaccept = 0;
yych = *(m_marker = ++m_cursor);
if (yych <= 0x0F) goto basic_json_parser_7;
goto basic_json_parser_32;
yyaccept = 0;
yych = *(m_marker = ++m_cursor);
if (yych <= 0x0F)
{
goto basic_json_parser_7;
}
goto basic_json_parser_32;
basic_json_parser_28:
++m_cursor;
{ return token_type::end_of_input; }
++m_cursor;
{
return token_type::end_of_input;
}
basic_json_parser_30:
yych = *++m_cursor;
goto basic_json_parser_7;
yych = *++m_cursor;
goto basic_json_parser_7;
basic_json_parser_31:
++m_cursor;
if (m_limit <= m_cursor) yyfill(); // LCOV_EXCL_LINE;
yych = *m_cursor;
++m_cursor;
if (m_limit <= m_cursor)
{
yyfill(); // LCOV_EXCL_LINE;
}
yych = *m_cursor;
basic_json_parser_32:
if (yybm[0+yych] & 64) {
goto basic_json_parser_31;
}
if (yych <= 0x0F) goto basic_json_parser_33;
if (yych <= '"') goto basic_json_parser_35;
goto basic_json_parser_34;
basic_json_parser_33:
m_cursor = m_marker;
if (yyaccept == 0) {
goto basic_json_parser_7;
} else {
goto basic_json_parser_25;
}
basic_json_parser_34:
++m_cursor;
if (m_limit <= m_cursor) yyfill(); // LCOV_EXCL_LINE;
yych = *m_cursor;
if (yych <= 'e') {
if (yych <= '/') {
if (yych == '"') goto basic_json_parser_31;
if (yych <= '.') goto basic_json_parser_33;
goto basic_json_parser_31;
} else {
if (yych <= '\\') {
if (yych <= '[') goto basic_json_parser_33;
if (yybm[0 + yych] & 64)
{
goto basic_json_parser_31;
} else {
if (yych == 'b') goto basic_json_parser_31;
goto basic_json_parser_33;
}
}
} else {
if (yych <= 'q') {
if (yych <= 'f') goto basic_json_parser_31;
if (yych == 'n') goto basic_json_parser_31;
goto basic_json_parser_33;
} else {
if (yych <= 's') {
if (yych <= 'r') goto basic_json_parser_31;
goto basic_json_parser_33;
} else {
if (yych <= 't') goto basic_json_parser_31;
if (yych <= 'u') goto basic_json_parser_37;
if (yych <= 0x0F)
{
goto basic_json_parser_33;
}
}
}
if (yych <= '"')
{
goto basic_json_parser_35;
}
goto basic_json_parser_34;
basic_json_parser_33:
m_cursor = m_marker;
if (yyaccept == 0)
{
goto basic_json_parser_7;
}
else
{
goto basic_json_parser_25;
}
basic_json_parser_34:
++m_cursor;
if (m_limit <= m_cursor)
{
yyfill(); // LCOV_EXCL_LINE;
}
yych = *m_cursor;
if (yych <= 'e')
{
if (yych <= '/')
{
if (yych == '"')
{
goto basic_json_parser_31;
}
if (yych <= '.')
{
goto basic_json_parser_33;
}
goto basic_json_parser_31;
}
else
{
if (yych <= '\\')
{
if (yych <= '[')
{
goto basic_json_parser_33;
}
goto basic_json_parser_31;
}
else
{
if (yych == 'b')
{
goto basic_json_parser_31;
}
goto basic_json_parser_33;
}
}
}
else
{
if (yych <= 'q')
{
if (yych <= 'f')
{
goto basic_json_parser_31;
}
if (yych == 'n')
{
goto basic_json_parser_31;
}
goto basic_json_parser_33;
}
else
{
if (yych <= 's')
{
if (yych <= 'r')
{
goto basic_json_parser_31;
}
goto basic_json_parser_33;
}
else
{
if (yych <= 't')
{
goto basic_json_parser_31;
}
if (yych <= 'u')
{
goto basic_json_parser_37;
}
goto basic_json_parser_33;
}
}
}
basic_json_parser_35:
++m_cursor;
{ return token_type::value_string; }
++m_cursor;
{
return token_type::value_string;
}
basic_json_parser_37:
++m_cursor;
if (m_limit <= m_cursor) yyfill(); // LCOV_EXCL_LINE;
yych = *m_cursor;
if (yych <= '@') {
if (yych <= '/') goto basic_json_parser_33;
if (yych >= ':') goto basic_json_parser_33;
} else {
if (yych <= 'F') goto basic_json_parser_38;
if (yych <= '`') goto basic_json_parser_33;
if (yych >= 'g') goto basic_json_parser_33;
}
++m_cursor;
if (m_limit <= m_cursor)
{
yyfill(); // LCOV_EXCL_LINE;
}
yych = *m_cursor;
if (yych <= '@')
{
if (yych <= '/')
{
goto basic_json_parser_33;
}
if (yych >= ':')
{
goto basic_json_parser_33;
}
}
else
{
if (yych <= 'F')
{
goto basic_json_parser_38;
}
if (yych <= '`')
{
goto basic_json_parser_33;
}
if (yych >= 'g')
{
goto basic_json_parser_33;
}
}
basic_json_parser_38:
++m_cursor;
if (m_limit <= m_cursor) yyfill(); // LCOV_EXCL_LINE;
yych = *m_cursor;
if (yych <= '@') {
if (yych <= '/') goto basic_json_parser_33;
if (yych >= ':') goto basic_json_parser_33;
} else {
if (yych <= 'F') goto basic_json_parser_39;
if (yych <= '`') goto basic_json_parser_33;
if (yych >= 'g') goto basic_json_parser_33;
}
++m_cursor;
if (m_limit <= m_cursor)
{
yyfill(); // LCOV_EXCL_LINE;
}
yych = *m_cursor;
if (yych <= '@')
{
if (yych <= '/')
{
goto basic_json_parser_33;
}
if (yych >= ':')
{
goto basic_json_parser_33;
}
}
else
{
if (yych <= 'F')
{
goto basic_json_parser_39;
}
if (yych <= '`')
{
goto basic_json_parser_33;
}
if (yych >= 'g')
{
goto basic_json_parser_33;
}
}
basic_json_parser_39:
++m_cursor;
if (m_limit <= m_cursor) yyfill(); // LCOV_EXCL_LINE;
yych = *m_cursor;
if (yych <= '@') {
if (yych <= '/') goto basic_json_parser_33;
if (yych >= ':') goto basic_json_parser_33;
} else {
if (yych <= 'F') goto basic_json_parser_40;
if (yych <= '`') goto basic_json_parser_33;
if (yych >= 'g') goto basic_json_parser_33;
}
++m_cursor;
if (m_limit <= m_cursor)
{
yyfill(); // LCOV_EXCL_LINE;
}
yych = *m_cursor;
if (yych <= '@')
{
if (yych <= '/')
{
goto basic_json_parser_33;
}
if (yych >= ':')
{
goto basic_json_parser_33;
}
}
else
{
if (yych <= 'F')
{
goto basic_json_parser_40;
}
if (yych <= '`')
{
goto basic_json_parser_33;
}
if (yych >= 'g')
{
goto basic_json_parser_33;
}
}
basic_json_parser_40:
++m_cursor;
if (m_limit <= m_cursor) yyfill(); // LCOV_EXCL_LINE;
yych = *m_cursor;
if (yych <= '@') {
if (yych <= '/') goto basic_json_parser_33;
if (yych <= '9') goto basic_json_parser_31;
goto basic_json_parser_33;
} else {
if (yych <= 'F') goto basic_json_parser_31;
if (yych <= '`') goto basic_json_parser_33;
if (yych <= 'f') goto basic_json_parser_31;
goto basic_json_parser_33;
}
++m_cursor;
if (m_limit <= m_cursor)
{
yyfill(); // LCOV_EXCL_LINE;
}
yych = *m_cursor;
if (yych <= '@')
{
if (yych <= '/')
{
goto basic_json_parser_33;
}
if (yych <= '9')
{
goto basic_json_parser_31;
}
goto basic_json_parser_33;
}
else
{
if (yych <= 'F')
{
goto basic_json_parser_31;
}
if (yych <= '`')
{
goto basic_json_parser_33;
}
if (yych <= 'f')
{
goto basic_json_parser_31;
}
goto basic_json_parser_33;
}
basic_json_parser_41:
yyaccept = 1;
m_marker = ++m_cursor;
if ((m_limit - m_cursor) < 3) yyfill(); // LCOV_EXCL_LINE;
yych = *m_cursor;
yyaccept = 1;
m_marker = ++m_cursor;
if ((m_limit - m_cursor) < 3)
{
yyfill(); // LCOV_EXCL_LINE;
}
yych = *m_cursor;
basic_json_parser_42:
if (yybm[0+yych] & 128) {
goto basic_json_parser_41;
}
if (yych <= 'D') {
if (yych != '.') goto basic_json_parser_25;
} else {
if (yych <= 'E') goto basic_json_parser_44;
if (yych == 'e') goto basic_json_parser_44;
goto basic_json_parser_25;
}
if (yybm[0 + yych] & 128)
{
goto basic_json_parser_41;
}
if (yych <= 'D')
{
if (yych != '.')
{
goto basic_json_parser_25;
}
}
else
{
if (yych <= 'E')
{
goto basic_json_parser_44;
}
if (yych == 'e')
{
goto basic_json_parser_44;
}
goto basic_json_parser_25;
}
basic_json_parser_43:
yych = *++m_cursor;
if (yych <= '/') goto basic_json_parser_33;
if (yych <= '9') goto basic_json_parser_48;
goto basic_json_parser_33;
yych = *++m_cursor;
if (yych <= '/')
{
goto basic_json_parser_33;
}
if (yych <= '9')
{
goto basic_json_parser_48;
}
goto basic_json_parser_33;
basic_json_parser_44:
yych = *++m_cursor;
if (yych <= ',') {
if (yych != '+') goto basic_json_parser_33;
} else {
if (yych <= '-') goto basic_json_parser_45;
if (yych <= '/') goto basic_json_parser_33;
if (yych <= '9') goto basic_json_parser_46;
goto basic_json_parser_33;
}
yych = *++m_cursor;
if (yych <= ',')
{
if (yych != '+')
{
goto basic_json_parser_33;
}
}
else
{
if (yych <= '-')
{
goto basic_json_parser_45;
}
if (yych <= '/')
{
goto basic_json_parser_33;
}
if (yych <= '9')
{
goto basic_json_parser_46;
}
goto basic_json_parser_33;
}
basic_json_parser_45:
yych = *++m_cursor;
if (yych <= '/') goto basic_json_parser_33;
if (yych >= ':') goto basic_json_parser_33;
yych = *++m_cursor;
if (yych <= '/')
{
goto basic_json_parser_33;
}
if (yych >= ':')
{
goto basic_json_parser_33;
}
basic_json_parser_46:
++m_cursor;
if (m_limit <= m_cursor) yyfill(); // LCOV_EXCL_LINE;
yych = *m_cursor;
if (yych <= '/') goto basic_json_parser_25;
if (yych <= '9') goto basic_json_parser_46;
goto basic_json_parser_25;
++m_cursor;
if (m_limit <= m_cursor)
{
yyfill(); // LCOV_EXCL_LINE;
}
yych = *m_cursor;
if (yych <= '/')
{
goto basic_json_parser_25;
}
if (yych <= '9')
{
goto basic_json_parser_46;
}
goto basic_json_parser_25;
basic_json_parser_48:
yyaccept = 1;
m_marker = ++m_cursor;
if ((m_limit - m_cursor) < 3) yyfill(); // LCOV_EXCL_LINE;
yych = *m_cursor;
if (yych <= 'D') {
if (yych <= '/') goto basic_json_parser_25;
if (yych <= '9') goto basic_json_parser_48;
goto basic_json_parser_25;
} else {
if (yych <= 'E') goto basic_json_parser_44;
if (yych == 'e') goto basic_json_parser_44;
goto basic_json_parser_25;
}
yyaccept = 1;
m_marker = ++m_cursor;
if ((m_limit - m_cursor) < 3)
{
yyfill(); // LCOV_EXCL_LINE;
}
yych = *m_cursor;
if (yych <= 'D')
{
if (yych <= '/')
{
goto basic_json_parser_25;
}
if (yych <= '9')
{
goto basic_json_parser_48;
}
goto basic_json_parser_25;
}
else
{
if (yych <= 'E')
{
goto basic_json_parser_44;
}
if (yych == 'e')
{
goto basic_json_parser_44;
}
goto basic_json_parser_25;
}
basic_json_parser_50:
yyaccept = 1;
yych = *(m_marker = ++m_cursor);
if (yych <= 'D') {
if (yych == '.') goto basic_json_parser_43;
goto basic_json_parser_25;
} else {
if (yych <= 'E') goto basic_json_parser_44;
if (yych == 'e') goto basic_json_parser_44;
goto basic_json_parser_25;
}
yyaccept = 1;
yych = *(m_marker = ++m_cursor);
if (yych <= 'D')
{
if (yych == '.')
{
goto basic_json_parser_43;
}
goto basic_json_parser_25;
}
else
{
if (yych <= 'E')
{
goto basic_json_parser_44;
}
if (yych == 'e')
{
goto basic_json_parser_44;
}
goto basic_json_parser_25;
}
basic_json_parser_51:
yych = *++m_cursor;
if (yych != 'l') goto basic_json_parser_33;
yych = *++m_cursor;
if (yych != 's') goto basic_json_parser_33;
yych = *++m_cursor;
if (yych != 'e') goto basic_json_parser_33;
++m_cursor;
{ return token_type::literal_false; }
yych = *++m_cursor;
if (yych != 'l')
{
goto basic_json_parser_33;
}
yych = *++m_cursor;
if (yych != 's')
{
goto basic_json_parser_33;
}
yych = *++m_cursor;
if (yych != 'e')
{
goto basic_json_parser_33;
}
++m_cursor;
{
return token_type::literal_false;
}
basic_json_parser_56:
yych = *++m_cursor;
if (yych != 'u') goto basic_json_parser_33;
yych = *++m_cursor;
if (yych != 'e') goto basic_json_parser_33;
++m_cursor;
{ return token_type::literal_true; }
yych = *++m_cursor;
if (yych != 'u')
{
goto basic_json_parser_33;
}
yych = *++m_cursor;
if (yych != 'e')
{
goto basic_json_parser_33;
}
++m_cursor;
{
return token_type::literal_true;
}
basic_json_parser_60:
yych = *++m_cursor;
if (yych != 'l') goto basic_json_parser_33;
yych = *++m_cursor;
if (yych != 'l') goto basic_json_parser_33;
++m_cursor;
{ return token_type::literal_null; }
yych = *++m_cursor;
if (yych != 'l')
{
goto basic_json_parser_33;
}
yych = *++m_cursor;
if (yych != 'l')
{
goto basic_json_parser_33;
}
++m_cursor;
{
return token_type::literal_null;
}
basic_json_parser_64:
yych = *++m_cursor;
if (yych != 0xBF) goto basic_json_parser_33;
++m_cursor;
{ return scan(); }
}
yych = *++m_cursor;
if (yych != 0xBF)
{
goto basic_json_parser_33;
}
++m_cursor;
{
return scan();
}
}
}
......@@ -7364,55 +7774,35 @@ basic_json_parser_64:
@brief parse floating point number
This function (and its overloads) serves to select the most approprate
standard floating point number parsing function based on the type
supplied via the first parameter. Set this to
@a static_cast<number_float_t>(nullptr).
standard floating point number parsing function (i.e., `std::strtof`,
`std::strtod`, or `std::strtold`) based on the type supplied via the
first parameter. Set this to @a static_cast<number_float_t>(nullptr).
@param type the @ref number_float_t in use
@param[in] type the @ref number_float_t in use
@param endptr recieves a pointer to the first character after the number
@param[in,out] endptr recieves a pointer to the first character after
the number
@return the floating point number
@warning This function uses `std::strtof`, `std::strtod`, or
`std::strtold` which use the current C locale to determine which
character is used as decimal point character. This may yield to parse
errors if the locale does not used `.`.
*/
long double str_to_float_t(long double* /* type */, char** endptr) const
{
return std::strtold(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
}
/*!
@brief parse floating point number
This function (and its overloads) serves to select the most approprate
standard floating point number parsing function based on the type
supplied via the first parameter. Set this to
@a static_cast<number_float_t>(nullptr).
@param type the @ref number_float_t in use
@param endptr recieves a pointer to the first character after the number
@return the floating point number
*/
double str_to_float_t(double* /* type */, char** endptr) const
/// @copydoc str_to_float_t
double str_to_float_t(double*, char** endptr) const
{
return std::strtod(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
}
/*!
@brief parse floating point number
This function (and its overloads) serves to select the most approprate
standard floating point number parsing function based on the type
supplied via the first parameter. Set this to
@a static_cast<number_float_t>(nullptr).
@param type the @ref number_float_t in use
@param endptr recieves a pointer to the first character after the number
@return the floating point number
*/
float str_to_float_t(float* /* type */, char** endptr) const
/// @copydoc str_to_float_t
float str_to_float_t(float*, char** endptr) const
{
return std::strtof(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
}
......@@ -7687,8 +8077,8 @@ basic_json_parser_64:
// check if conversion loses precision (special case -0.0 always loses precision)
const auto int_val = static_cast<number_integer_t>(result.m_value.number_float);
if (result.m_value.number_float == static_cast<number_float_t>(int_val) &&
result.m_value.number_integer != json_value(-0.0f).number_integer)
if (result.m_value.number_float == static_cast<number_float_t>(int_val) and
result.m_value.number_integer != json_value(-0.0f).number_integer)
{
// we would not lose precision -> return int
result.m_type = value_t::number_integer;
......
......@@ -5604,13 +5604,20 @@ class basic_json
case value_t::number_float:
{
// If the number is an integer then output as a fixed with with precision 1
// to output "0.0", "1.0" etc as expected for some round trip tests otherwise
// 15 digits of precision allows round-trip IEEE 754 string->double->string;
// to be safe, we read this value from std::numeric_limits<number_float_t>::digits10
if (std::fmod(m_value.number_float, 1) == 0) o << std::fixed << std::setprecision(1);
else {
o.unsetf(std::ios_base::floatfield); // std::defaultfloat not supported in gcc version < 5
// If the number is an integer then output as a fixed with with
// precision 1 to output "0.0", "1.0" etc as expected for some
// round trip tests otherwise 15 digits of precision allows
// round-trip IEEE 754 string->double->string; to be safe, we
// read this value from
// std::numeric_limits<number_float_t>::digits10
if (std::fmod(m_value.number_float, 1) == 0)
{
o << std::fixed << std::setprecision(1);
}
else
{
// std::defaultfloat not supported in gcc version < 5
o.unsetf(std::ios_base::floatfield);
o << std::setprecision(std::numeric_limits<double>::digits10);
}
o << m_value.number_float;
......@@ -7046,55 +7053,35 @@ class basic_json
@brief parse floating point number
This function (and its overloads) serves to select the most approprate
standard floating point number parsing function based on the type
supplied via the first parameter. Set this to
@a static_cast<number_float_t>(nullptr).
standard floating point number parsing function (i.e., `std::strtof`,
`std::strtod`, or `std::strtold`) based on the type supplied via the
first parameter. Set this to @a static_cast<number_float_t>(nullptr).
@param type the @ref number_float_t in use
@param[in] type the @ref number_float_t in use
@param endptr recieves a pointer to the first character after the number
@param[in,out] endptr recieves a pointer to the first character after
the number
@return the floating point number
@warning This function uses `std::strtof`, `std::strtod`, or
`std::strtold` which use the current C locale to determine which
character is used as decimal point character. This may yield to parse
errors if the locale does not used `.`.
*/
long double str_to_float_t(long double* /* type */, char** endptr) const
{
return std::strtold(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
}
/*!
@brief parse floating point number
This function (and its overloads) serves to select the most approprate
standard floating point number parsing function based on the type
supplied via the first parameter. Set this to
@a static_cast<number_float_t>(nullptr).
@param type the @ref number_float_t in use
@param endptr recieves a pointer to the first character after the number
@return the floating point number
*/
double str_to_float_t(double* /* type */, char** endptr) const
/// @copydoc str_to_float_t
double str_to_float_t(double*, char** endptr) const
{
return std::strtod(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
}
/*!
@brief parse floating point number
This function (and its overloads) serves to select the most approprate
standard floating point number parsing function based on the type
supplied via the first parameter. Set this to
@a static_cast<number_float_t>(nullptr).
@param type the @ref number_float_t in use
@param endptr recieves a pointer to the first character after the number
@return the floating point number
*/
float str_to_float_t(float* /* type */, char** endptr) const
/// @copydoc str_to_float_t
float str_to_float_t(float*, char** endptr) const
{
return std::strtof(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
}
......@@ -7369,8 +7356,8 @@ class basic_json
// check if conversion loses precision (special case -0.0 always loses precision)
const auto int_val = static_cast<number_integer_t>(result.m_value.number_float);
if (result.m_value.number_float == static_cast<number_float_t>(int_val) &&
result.m_value.number_integer != json_value(-0.0f).number_integer)
if (result.m_value.number_float == static_cast<number_float_t>(int_val) and
result.m_value.number_integer != json_value(-0.0f).number_integer)
{
// we would not lose precision -> return int
result.m_type = value_t::number_integer;
......
......@@ -11602,7 +11602,8 @@ TEST_CASE("regression tests")
CHECK(j_double.get<double>() == 1.23e45);
// long double
nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, long double> j_long_double = 1.23e45L;
nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, long double> j_long_double =
1.23e45L;
CHECK(j_long_double.get<long double>() == 1.23e45L);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment