-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Stream read/write with generated locales defaults to classic format/parse #174
Comments
@artyom-beilis Would you oppose that change or have any input? @salvoilmiosi You initially filed #64 and noted that |
This is by design. Quoting documentation of standard library implementation
It is actually big issue setting locale can break many libraries like SQL, json and many others. So Boost.Locale requires from user to tell explicitly that the number is localized and basically given to human rather than some kind of text interface. |
I understand the motivation. I guess this is why the standard implicitly imbues the classic locale on startup and provides access to the classic locale at any point.
I differ in that expectation in 2 points:
IMO those are reasonable expectations. Also:
Again: The same expectation holds/pitfall waits: You'd usually change the global locale and then (maybe down in 3rd-party-libs) use However with
in the documentation for ages and hence might be relied on by people so we can't easily change that. So the bug is rather that the Might be a good feature to be able to change that default behavior, similar to |
Small note, there is a reason why many libraries become broken when changing default locale. Because it is rarely used
So bringing back broken stuff because it may be somehow used (actually not) instead of having consistent behavior wouldn't do any good to users. I don't think default number formatting should be anything but "C"/classic locale based. |
I've just seen that the default flag for stream operations with locales generated by Boost.Locale is
posix
, i.e. "classic".This leads to the bug/inconsistency I've encountered at #64 (comment)
Assume this:
And then:
So although a German locale is globally set and one can reasonably expect that all formatting and parsing is done with the German decimal separator
","
this is not the case: It will use the classic locale which outputs"123.25"
and entering"124,25"
will be parsed as"12425"
if it doesn't fail.I traced this to
base_num_format/base_num_parse
which access theios_info.display_flags()
of the stream which defaults toposix
So one would need to do
outstream << as::number
andinstream >> as::number
first for every stream created which external libraries are not aware of leading to those issues.Hence I'd change the default from
posix
tonumber
so results are more intuitive and external libraries unware of Boost.Locale work.Although I'd consider this a bugfix, this is a breaking change, hence I wanted to make sure I didn't miss anything.
But the described behavior really does sound like a bug to me, see also #64 (comment): Imagine an external library unaware of Boost.Locale using the global locale and inspecting the
numpunct
facet and then find that formatting/parsing doesn't behave as expected.The text was updated successfully, but these errors were encountered: