Skip to content

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

Open
@DosMike

Description

@DosMike

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions