🐛 fixing #359
This commit is contained in:
parent
0d72767b3e
commit
43dbe02d5b
2 changed files with 4 additions and 46 deletions
25
src/json.hpp
25
src/json.hpp
|
@ -122,26 +122,6 @@ struct has_mapped_type
|
||||||
std::is_integral<decltype(detect(std::declval<T>()))>::value;
|
std::is_integral<decltype(detect(std::declval<T>()))>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
|
||||||
@brief helper class to create locales with decimal point
|
|
||||||
|
|
||||||
This struct is used a default locale during the JSON serialization. JSON
|
|
||||||
requires the decimal point to be `.`, so this function overloads the
|
|
||||||
`do_decimal_point()` function to return `.`. This function is called by
|
|
||||||
float-to-string conversions to retrieve the decimal separator between integer
|
|
||||||
and fractional parts.
|
|
||||||
|
|
||||||
@sa https://github.com/nlohmann/json/issues/51#issuecomment-86869315
|
|
||||||
@since version 2.0.0
|
|
||||||
*/
|
|
||||||
struct DecimalSeparator : std::numpunct<char>
|
|
||||||
{
|
|
||||||
char do_decimal_point() const
|
|
||||||
{
|
|
||||||
return '.';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -2201,8 +2181,7 @@ class basic_json
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
// fix locale problems
|
// fix locale problems
|
||||||
const static std::locale loc(std::locale(), new DecimalSeparator);
|
ss.imbue(std::locale::classic());
|
||||||
ss.imbue(loc);
|
|
||||||
|
|
||||||
// 6, 15 or 16 digits of precision allows round-trip IEEE 754
|
// 6, 15 or 16 digits of precision allows round-trip IEEE 754
|
||||||
// string->float->string, string->double->string or string->long
|
// string->float->string, string->double->string or string->long
|
||||||
|
@ -5829,7 +5808,7 @@ class basic_json
|
||||||
o.width(0);
|
o.width(0);
|
||||||
|
|
||||||
// fix locale problems
|
// fix locale problems
|
||||||
const auto old_locale = o.imbue(std::locale(std::locale(), new DecimalSeparator));
|
const auto old_locale = o.imbue(std::locale::classic());
|
||||||
// set precision
|
// set precision
|
||||||
|
|
||||||
// 6, 15 or 16 digits of precision allows round-trip IEEE 754
|
// 6, 15 or 16 digits of precision allows round-trip IEEE 754
|
||||||
|
|
|
@ -122,26 +122,6 @@ struct has_mapped_type
|
||||||
std::is_integral<decltype(detect(std::declval<T>()))>::value;
|
std::is_integral<decltype(detect(std::declval<T>()))>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
|
||||||
@brief helper class to create locales with decimal point
|
|
||||||
|
|
||||||
This struct is used a default locale during the JSON serialization. JSON
|
|
||||||
requires the decimal point to be `.`, so this function overloads the
|
|
||||||
`do_decimal_point()` function to return `.`. This function is called by
|
|
||||||
float-to-string conversions to retrieve the decimal separator between integer
|
|
||||||
and fractional parts.
|
|
||||||
|
|
||||||
@sa https://github.com/nlohmann/json/issues/51#issuecomment-86869315
|
|
||||||
@since version 2.0.0
|
|
||||||
*/
|
|
||||||
struct DecimalSeparator : std::numpunct<char>
|
|
||||||
{
|
|
||||||
char do_decimal_point() const
|
|
||||||
{
|
|
||||||
return '.';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -2201,8 +2181,7 @@ class basic_json
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
// fix locale problems
|
// fix locale problems
|
||||||
const static std::locale loc(std::locale(), new DecimalSeparator);
|
ss.imbue(std::locale::classic());
|
||||||
ss.imbue(loc);
|
|
||||||
|
|
||||||
// 6, 15 or 16 digits of precision allows round-trip IEEE 754
|
// 6, 15 or 16 digits of precision allows round-trip IEEE 754
|
||||||
// string->float->string, string->double->string or string->long
|
// string->float->string, string->double->string or string->long
|
||||||
|
@ -5829,7 +5808,7 @@ class basic_json
|
||||||
o.width(0);
|
o.width(0);
|
||||||
|
|
||||||
// fix locale problems
|
// fix locale problems
|
||||||
const auto old_locale = o.imbue(std::locale(std::locale(), new DecimalSeparator));
|
const auto old_locale = o.imbue(std::locale::classic());
|
||||||
// set precision
|
// set precision
|
||||||
|
|
||||||
// 6, 15 or 16 digits of precision allows round-trip IEEE 754
|
// 6, 15 or 16 digits of precision allows round-trip IEEE 754
|
||||||
|
|
Loading…
Reference in a new issue