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
7d14f167
Unverified
Commit
7d14f167
authored
Feb 20, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🚑
fix for #465
parent
b04543ec
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
22 deletions
+27
-22
src/json.hpp
src/json.hpp
+1
-10
src/json.hpp.re2c
src/json.hpp.re2c
+1
-10
test/src/unit-inspection.cpp
test/src/unit-inspection.cpp
+16
-2
test/src/unit-regression.cpp
test/src/unit-regression.cpp
+9
-0
No files found.
src/json.hpp
View file @
7d14f167
...
...
@@ -8310,16 +8310,7 @@ class basic_json
static_assert
(
d
==
6
or
d
==
15
or
d
==
16
or
d
==
17
,
"unexpected NumberType"
);
static
constexpr
auto
fmt
=
d
==
6
?
"%.7g"
:
d
==
15
?
"%.16g"
:
d
==
16
?
"%.17g"
:
d
==
17
?
"%.18g"
:
"%.19g"
;
// I'm not sure why we need to +1 the precision,
// but without it there's a unit-test that fails
// that asserts precision of the output
snprintf
(
m_buf
.
data
(),
m_buf
.
size
(),
fmt
,
x
);
snprintf
(
m_buf
.
data
(),
m_buf
.
size
(),
"%.*g"
,
d
,
x
);
// read information from locale
const
auto
loc
=
localeconv
();
...
...
src/json.hpp.re2c
View file @
7d14f167
...
...
@@ -8310,16 +8310,7 @@ class basic_json
static_assert(d == 6 or d == 15 or d == 16 or d == 17,
"unexpected NumberType");
static constexpr auto fmt = d == 6 ? "%.7g"
: d == 15 ? "%.16g"
: d == 16 ? "%.17g"
: d == 17 ? "%.18g"
: "%.19g";
// I'm not sure why we need to +1 the precision,
// but without it there's a unit-test that fails
// that asserts precision of the output
snprintf(m_buf.data(), m_buf.size(), fmt, x);
snprintf(m_buf.data(), m_buf.size(), "%.*g", d, x);
// read information from locale
const auto loc = localeconv();
...
...
test/src/unit-inspection.cpp
View file @
7d14f167
...
...
@@ -250,17 +250,31 @@ TEST_CASE("object inspection")
ss
.
str
(
std
::
string
());
// use stringstream for JSON serialization
json
j_number
=
3.14159265358979
3
;
json
j_number
=
3.14159265358979
;
ss
<<
j_number
;
// check that precision has been overridden during serialization
CHECK
(
ss
.
str
()
==
"3.14159265358979
3
"
);
CHECK
(
ss
.
str
()
==
"3.14159265358979"
);
// check that precision has been restored
CHECK
(
ss
.
precision
()
==
3
);
}
}
SECTION
(
"round trips"
)
{
for
(
const
auto
&
s
:
{
"3.141592653589793"
,
"1000000000000000010E5"
})
{
json
j1
=
json
::
parse
(
s
);
std
::
string
s1
=
j1
.
dump
();
json
j2
=
json
::
parse
(
s1
);
std
::
string
s2
=
j2
.
dump
();
CHECK
(
s1
==
s2
);
}
}
SECTION
(
"return the type of the object (explicit)"
)
{
SECTION
(
"null"
)
...
...
test/src/unit-regression.cpp
View file @
7d14f167
...
...
@@ -783,4 +783,13 @@ TEST_CASE("regression tests")
json
j
=
R"({"bool_value":true,"double_value":2.0,"int_value":10,"level1":{"list_value":[3,"hi",false],"tmp":5.0},"string_value":"hello"})"
_json
;
CHECK
(
j
[
"double_value"
].
is_number_float
());
}
SECTION
(
"issue #465 - roundtrip error while parsing 1000000000000000010E5"
)
{
json
j1
=
json
::
parse
(
"1000000000000000010E5"
);
std
::
string
s1
=
j1
.
dump
();
json
j2
=
json
::
parse
(
s1
);
std
::
string
s2
=
j2
.
dump
();
CHECK
(
s1
==
s2
);
}
}
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