🐛 fixes crash in dump from static object (#359)

Merge branch 'feature/issue359' into develop
This commit is contained in:
Niels 2016-11-22 06:57:58 +01:00
commit c34b41acd6
3 changed files with 8 additions and 48 deletions

View file

@ -499,6 +499,8 @@ I deeply appreciate the help of the following people.
- [ChristophJud](https://github.com/ChristophJud) overworked the CMake files to ease project inclusion. - [ChristophJud](https://github.com/ChristophJud) overworked the CMake files to ease project inclusion.
- [Vladimir Petrigo](https://github.com/vpetrigo) made a SFINAE hack more readable. - [Vladimir Petrigo](https://github.com/vpetrigo) made a SFINAE hack more readable.
- [Denis Andrejew](https://github.com/seeekr) fixed a grammar issue in the README file. - [Denis Andrejew](https://github.com/seeekr) fixed a grammar issue in the README file.
- [Pierre-Antoine Lacaze](https://github.com/palacaze) found a subtle bug in the `dump()` function.
- [TurpentineDistillery](https://github.com/TurpentineDistillery) pointed to [`std::locale::classic()`](http://en.cppreference.com/w/cpp/locale/locale/classic) to avoid too much locale joggling.
Thanks a lot for helping out! Thanks a lot for helping out!

View file

@ -45,7 +45,7 @@ SOFTWARE.
#include <iostream> // istream, ostream #include <iostream> // istream, ostream
#include <iterator> // advance, begin, bidirectional_iterator_tag, distance, end, inserter, iterator, iterator_traits, next, random_access_iterator_tag, reverse_iterator #include <iterator> // advance, begin, bidirectional_iterator_tag, distance, end, inserter, iterator, iterator_traits, next, random_access_iterator_tag, reverse_iterator
#include <limits> // numeric_limits #include <limits> // numeric_limits
#include <locale> // locale, numpunct #include <locale> // locale
#include <map> // map #include <map> // map
#include <memory> // addressof, allocator, allocator_traits, unique_ptr #include <memory> // addressof, allocator, allocator_traits, unique_ptr
#include <numeric> // accumulate #include <numeric> // accumulate
@ -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

View file

@ -45,7 +45,7 @@ SOFTWARE.
#include <iostream> // istream, ostream #include <iostream> // istream, ostream
#include <iterator> // advance, begin, bidirectional_iterator_tag, distance, end, inserter, iterator, iterator_traits, next, random_access_iterator_tag, reverse_iterator #include <iterator> // advance, begin, bidirectional_iterator_tag, distance, end, inserter, iterator, iterator_traits, next, random_access_iterator_tag, reverse_iterator
#include <limits> // numeric_limits #include <limits> // numeric_limits
#include <locale> // locale, numpunct #include <locale> // locale
#include <map> // map #include <map> // map
#include <memory> // addressof, allocator, allocator_traits, unique_ptr #include <memory> // addressof, allocator, allocator_traits, unique_ptr
#include <numeric> // accumulate #include <numeric> // accumulate
@ -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