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
53e3da80
Commit
53e3da80
authored
Mar 23, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor adjustments to pull request #38
parent
a382a93a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
7 deletions
+17
-7
src/json.hpp
src/json.hpp
+7
-5
src/json.hpp.re2c
src/json.hpp.re2c
+10
-2
No files found.
src/json.hpp
View file @
53e3da80
...
@@ -32,6 +32,7 @@ iterators allow a ReversibleContainer to be iterated over in reverse.
...
@@ -32,6 +32,7 @@ iterators allow a ReversibleContainer to be iterated over in reverse.
#include <algorithm>
#include <algorithm>
#include <cmath>
#include <cmath>
#include <cstdio>
#include <functional>
#include <functional>
#include <initializer_list>
#include <initializer_list>
#include <iomanip>
#include <iomanip>
...
@@ -1882,7 +1883,8 @@ class basic_json
...
@@ -1882,7 +1883,8 @@ class basic_json
recursively. Note that
recursively. Note that
- strings and object keys are escaped using escape_string()
- strings and object keys are escaped using escape_string()
- integer numbers are converted to a string before output using std::to_string()
- integer numbers are converted to a string before output using
std::to_string()
- floating-point numbers are converted to a string using "%g" format
- floating-point numbers are converted to a string using "%g" format
@param prettyPrint whether the output shall be pretty-printed
@param prettyPrint whether the output shall be pretty-printed
...
@@ -1991,12 +1993,12 @@ class basic_json
...
@@ -1991,12 +1993,12 @@ class basic_json
case
(
value_t
:
:
number_float
)
:
case
(
value_t
:
:
number_float
)
:
{
{
// 15 digits of precision allows round-trip IEEE 754 string->double->string
// 15 digits of precision allows round-trip IEEE 754
unsigned
int
sz
=
(
unsigned
int
)
std
::
snprintf
(
nullptr
,
0
,
"%.15g"
,
m_value
.
number_float
);
// string->double->string
const
auto
sz
=
static_cast
<
unsigned
int
>
(
std
::
snprintf
(
nullptr
,
0
,
"%.15g"
,
m_value
.
number_float
));
std
::
vector
<
char
>
buf
(
sz
+
1
);
std
::
vector
<
char
>
buf
(
sz
+
1
);
std
::
snprintf
(
&
buf
[
0
],
buf
.
size
(),
"%.15g"
,
m_value
.
number_float
);
std
::
snprintf
(
&
buf
[
0
],
buf
.
size
(),
"%.15g"
,
m_value
.
number_float
);
string_t
formatted
=
buf
.
data
();
return
string_t
(
buf
.
data
());
return
formatted
;
}
}
default:
default:
...
...
src/json.hpp.re2c
View file @
53e3da80
...
@@ -32,6 +32,7 @@ iterators allow a ReversibleContainer to be iterated over in reverse.
...
@@ -32,6 +32,7 @@ iterators allow a ReversibleContainer to be iterated over in reverse.
#include <algorithm>
#include <algorithm>
#include <cmath>
#include <cmath>
#include <cstdio>
#include <functional>
#include <functional>
#include <initializer_list>
#include <initializer_list>
#include <iomanip>
#include <iomanip>
...
@@ -1882,7 +1883,9 @@ class basic_json
...
@@ -1882,7 +1883,9 @@ class basic_json
recursively. Note that
recursively. Note that
- strings and object keys are escaped using escape_string()
- strings and object keys are escaped using escape_string()
- numbers are converted to a string before output using std::to_string()
- integer numbers are converted to a string before output using
std::to_string()
- floating-point numbers are converted to a string using "%g" format
@param prettyPrint whether the output shall be pretty-printed
@param prettyPrint whether the output shall be pretty-printed
@param indentStep the indent level
@param indentStep the indent level
...
@@ -1990,7 +1993,12 @@ class basic_json
...
@@ -1990,7 +1993,12 @@ class basic_json
case (value_t::number_float):
case (value_t::number_float):
{
{
return std::to_string(m_value.number_float);
// 15 digits of precision allows round-trip IEEE 754
// string->double->string
const auto sz = static_cast<unsigned int>(std::snprintf(nullptr, 0, "%.15g", m_value.number_float));
std::vector<char> buf(sz + 1);
std::snprintf(&buf[0], buf.size(), "%.15g", m_value.number_float);
return string_t(buf.data());
}
}
default:
default:
...
...
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