Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to parse numbers if std::locale() changes the decimal #1565

Open
DosMike opened this issue Sep 11, 2024 · 0 comments
Open

Unable to parse numbers if std::locale() changes the decimal #1565

DosMike opened this issue Sep 11, 2024 · 0 comments

Comments

@DosMike
Copy link

DosMike commented Sep 11, 2024

Describe the bug
Hi, I'm not living in an English speaking country and as such I naturally set std::locale("") to make cpp use familiar number representations instead (This changes the decimal from a dot to a comma). There seems to be a problem where jsoncpp uses a string stream to parse decimals, and the input stream correctly uses the default locale set before, but this now differs from the locale required by Json.

To Reproduce
Steps to reproduce the behavior:

  1. std::locale::global(std::locale("de_DE.UTF-8"));
  2. jsonReader.parse("[123.45]", root, false);

Expected behavior
Should parse the number with dot as decimal without any issue.

Desktop (please complete the following information):

  • OS: Linux
  • Meson N/A
  • Ninja N/A

Additional context
The solution is to imbue the streams with the local required by json like is.imbue(std::local("en_US.UTF-8")) for the reader:

IStringStream is(String(token.start_, token.end_));

IStringStream is(String(token.start_, token.end_));

Don't currently know if the writer is affected with sprintf:

String valueToString(double value, bool useSpecialFloats,

Workaround is to temporarily set the locale to en_US manually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant