mirror of
https://github.com/nlohmann/json
synced 2024-11-30 23:50:08 +00:00
Trying to coerce setlocale to make snprintf use commas as delimiter; the behavior appears to be compiler/platform-specific
This commit is contained in:
parent
6e8da7d8c4
commit
d2e9ce270a
@ -407,21 +407,21 @@ TEST_CASE("regression tests")
|
|||||||
{
|
{
|
||||||
const std::string orig_locale_name(setlocale(LC_ALL, NULL));
|
const std::string orig_locale_name(setlocale(LC_ALL, NULL));
|
||||||
|
|
||||||
setlocale(LC_NUMERIC, "de_DE");
|
setlocale(LC_NUMERIC, "fr_Fr.UTF-8");
|
||||||
std::array<char, 64> buf;
|
std::array<char, 64> buf;
|
||||||
|
|
||||||
{
|
{
|
||||||
// verify that snprintf now uses commas as decimal-separator
|
// verify that snprintf now uses commas as decimal-separator
|
||||||
std::snprintf(buf.data(), buf.size(), "%.2f", 3.14);
|
std::snprintf(buf.data(), buf.size(), "%.2f", 3.14);
|
||||||
assert(std::strcmp(buf.data(), "3,14") == 0);
|
CHECK(std::strcmp(buf.data(), "3,14") == 0);
|
||||||
|
|
||||||
// verify that strtod now uses commas as decimal-separator
|
// verify that strtod now uses commas as decimal-separator
|
||||||
const double d1 = std::strtod(buf.data(), nullptr);
|
const double d1 = std::strtod(buf.data(), nullptr);
|
||||||
assert(d1 == 3.14);
|
CHECK(d1 == 3.14);
|
||||||
|
|
||||||
// verify that strtod does not understand dots as decimal separator
|
// verify that strtod does not understand dots as decimal separator
|
||||||
const double d2 = std::strtod("3.14", nullptr);
|
const double d2 = std::strtod("3.14", nullptr);
|
||||||
assert(d2 == 3);
|
CHECK(d2 == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
const json j1 = json::parse("3.14");
|
const json j1 = json::parse("3.14");
|
||||||
|
Loading…
Reference in New Issue
Block a user