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
0b60d970
Commit
0b60d970
authored
Apr 05, 2016
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make code independent of concrete locale
parent
31bccc83
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
4 deletions
+30
-4
src/json.hpp
src/json.hpp
+15
-2
src/json.hpp.re2c
src/json.hpp.re2c
+15
-2
No files found.
src/json.hpp
View file @
0b60d970
...
...
@@ -88,6 +88,19 @@ struct has_mapped_type
static
constexpr
bool
value
=
sizeof
(
test
<
T
>
(
0
))
==
1
;
};
/*!
@brief helper class to create locales with decimal point
@sa https://github.com/nlohmann/json/issues/51#issuecomment-86869315
*/
class
DecimalSeparator
:
public
std
::
numpunct
<
char
>
{
protected:
char
do_decimal_point
()
const
{
return
'.'
;
}
};
}
/*!
...
...
@@ -6161,7 +6174,7 @@ class basic_json
{
// no exponent - output as a decimal
std
::
stringstream
ss
;
ss
.
imbue
(
std
::
locale
(
"C"
));
ss
.
imbue
(
std
::
locale
(
std
::
locale
(),
new
DecimalSeparator
));
// fix locale problems
ss
<<
std
::
setprecision
(
m_type
.
bits
.
precision
)
<<
std
::
fixed
<<
m_value
.
number_float
;
o
<<
ss
.
str
();
...
...
@@ -6182,7 +6195,7 @@ class basic_json
// to be safe, we read this value from
// std::numeric_limits<number_float_t>::digits10
std
::
stringstream
ss
;
ss
.
imbue
(
std
::
locale
(
"C"
));
ss
.
imbue
(
std
::
locale
(
std
::
locale
(),
new
DecimalSeparator
));
// fix locale problems
ss
<<
std
::
setprecision
(
std
::
numeric_limits
<
double
>::
digits10
)
<<
m_value
.
number_float
;
o
<<
ss
.
str
();
...
...
src/json.hpp.re2c
View file @
0b60d970
...
...
@@ -88,6 +88,19 @@ struct has_mapped_type
static constexpr bool value = sizeof(test<T>(0)) == 1;
};
/*!
@brief helper class to create locales with decimal point
@sa https://github.com/nlohmann/json/issues/51#issuecomment-86869315
*/
class DecimalSeparator : public std::numpunct<char>
{
protected:
char do_decimal_point() const
{
return '.';
}
};
}
/*!
...
...
@@ -6161,7 +6174,7 @@ class basic_json
{
// no exponent - output as a decimal
std::stringstream ss;
ss.imbue(std::locale(
"C"
)); // fix locale problems
ss.imbue(std::locale(
std::locale(), new DecimalSeparator
)); // fix locale problems
ss << std::setprecision(m_type.bits.precision)
<< std::fixed << m_value.number_float;
o << ss.str();
...
...
@@ -6182,7 +6195,7 @@ class basic_json
// to be safe, we read this value from
// std::numeric_limits<number_float_t>::digits10
std::stringstream ss;
ss.imbue(std::locale(
"C"
)); // fix locale problems
ss.imbue(std::locale(
std::locale(), new DecimalSeparator
)); // fix locale problems
ss << std::setprecision(std::numeric_limits<double>::digits10)
<< m_value.number_float;
o << ss.str();
...
...
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