Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
54a41391
Commit
54a41391
authored
9 years ago
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup after #191
parent
ad5d1dab
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
800 additions
and
422 deletions
+800
-422
README.md
README.md
+2
-2
src/json.hpp
src/json.hpp
+765
-375
src/json.hpp.re2c
src/json.hpp.re2c
+31
-44
test/unit.cpp
test/unit.cpp
+2
-1
No files found.
README.md
View file @
54a41391
...
@@ -390,7 +390,7 @@ I deeply appreciate the help of the following people.
...
@@ -390,7 +390,7 @@ I deeply appreciate the help of the following people.
-
[
406345
](
https://github.com/406345
)
fixed two small warnings.
-
[
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.
-
[
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.
-
[
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!
Thanks a lot for helping out!
...
@@ -407,7 +407,7 @@ $ make
...
@@ -407,7 +407,7 @@ $ make
$
./json_unit
"*"
$
./json_unit
"*"
===============================================================================
===============================================================================
All tests passed
(
33433
18
assertions
in
29
test
cases
)
All tests passed
(
33433
29
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
)
.
For more information, have a look at the file
[
.travis.yml
](
https://github.com/nlohmann/json/blob/master/.travis.yml
)
.
This diff is collapsed.
Click to expand it.
src/json.hpp
View file @
54a41391
This diff is collapsed.
Click to expand it.
src/json.hpp.re2c
View file @
54a41391
...
@@ -5604,13 +5604,20 @@ class basic_json
...
@@ -5604,13 +5604,20 @@ class basic_json
case value_t::number_float:
case value_t::number_float:
{
{
// If the number is an integer then output as a fixed with with precision 1
// If the number is an integer then output as a fixed with with
// to output "0.0", "1.0" etc as expected for some round trip tests otherwise
// precision 1 to output "0.0", "1.0" etc as expected for some
// 15 digits of precision allows round-trip IEEE 754 string->double->string;
// round trip tests otherwise 15 digits of precision allows
// to be safe, we read this value from std::numeric_limits<number_float_t>::digits10
// round-trip IEEE 754 string->double->string; to be safe, we
if (std::fmod(m_value.number_float, 1) == 0) o << std::fixed << std::setprecision(1);
// read this value from
else {
// std::numeric_limits<number_float_t>::digits10
o.unsetf(std::ios_base::floatfield); // std::defaultfloat not supported in gcc version < 5
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 << std::setprecision(std::numeric_limits<double>::digits10);
}
}
o << m_value.number_float;
o << m_value.number_float;
...
@@ -7046,55 +7053,35 @@ class basic_json
...
@@ -7046,55 +7053,35 @@ class basic_json
@brief parse floating point number
@brief parse floating point number
This function (and its overloads) serves to select the most approprate
This function (and its overloads) serves to select the most approprate
standard floating point number parsing function
based on the type
standard floating point number parsing function
(i.e., `std::strtof`,
supplied via the first parameter. Set this to
`std::strtod`, or `std::strtold`) based on the type supplied via the
@a static_cast<number_float_t>(nullptr).
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
@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
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);
return std::strtold(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
}
}
/*!
/// @copydoc str_to_float_t
@brief parse floating point number
double str_to_float_t(double*, char** endptr) const
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
{
{
return std::strtod(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
return std::strtod(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
}
}
/*!
/// @copydoc str_to_float_t
@brief parse floating point number
float str_to_float_t(float*, char** endptr) const
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
{
{
return std::strtof(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
return std::strtof(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
}
}
...
@@ -7369,8 +7356,8 @@ class basic_json
...
@@ -7369,8 +7356,8 @@ class basic_json
// check if conversion loses precision (special case -0.0 always loses precision)
// 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);
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)
&&
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)
result.m_value.number_integer != json_value(-0.0f).number_integer)
{
{
// we would not lose precision -> return int
// we would not lose precision -> return int
result.m_type = value_t::number_integer;
result.m_type = value_t::number_integer;
...
...
This diff is collapsed.
Click to expand it.
test/unit.cpp
View file @
54a41391
...
@@ -11602,7 +11602,8 @@ TEST_CASE("regression tests")
...
@@ -11602,7 +11602,8 @@ TEST_CASE("regression tests")
CHECK
(
j_double
.
get
<
double
>
()
==
1.23e45
);
CHECK
(
j_double
.
get
<
double
>
()
==
1.23e45
);
// long double
// 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
);
CHECK
(
j_long_double
.
get
<
long
double
>
()
==
1.23e45L
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment