-
-
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
Adds custom boost::locale::numpunct #65
base: develop
Are you sure you want to change the base?
Conversation
77d1e5c
to
d43f0d0
Compare
Unfortunately it neither fixes the problem but also introduces new problems. Lets start from what it broke. boost.locale uses Additionally note thousands and decimal separator aren't enough - there is grouping - how to format it isn't always groups of three, sometimes it is two or other for example "10,00,00,00,00,000". So you need to extract both grouping and marks. But in ICU formatting of groups is very different from std::locale/posix locale. In you case if grouping returns "" - than no thousands separators are used. I recommend you to study the subject deeply before you write such a patch - in both terms localization and how it is done and how it is implemented in Boost.Locale. You can always ask questions |
d43f0d0
to
3672482
Compare
I must admit that my patch was a bit rushed. I have also now added grouping info to my icu implementation. |
3672482
to
d1598d3
Compare
It is little bit complicated than that. https://en.wikipedia.org/wiki/Decimal_separator#Examples_of_use I really suggest first define what are you trying to solve. Than look what exists in icu and multiple locales (usually you'll be surprised how euro-centric your thinking will be) and how to solve it properly. It is highly complex topic usually not solved by such a simple manner... And I'm not going to merge half baked solutions. |
b1f5d00
to
770ab80
Compare
I have made my boost::locale::numpunct a subclass of std::numpunct to un-break winapi. Now this solves my problem of being able to access decimal_point, thousands_sep and grouping from icu backend and is compatible with all api's. I have pretty much just used the same technique that have already been in place for posix and winapi. |
But it does not solve the issue: And I don't think it is correct thing to do. |
So you're telling me that the current std::numpunct implementation in winapi and posix is broken but it's necessary because it's called by libstc++ in order for number formatting and parsing to work? Also why should numpunct always return "C" locale separators? Can't you just imbue std::locale::classic() if you want that functionality? |
Exactly. |
Because by default the formatting (without specific flags) by boost.locale is |
I guess I'll live with my fork in my own project then. |
348b7a8
to
8ddfc7e
Compare
8ddfc7e
to
ff22efc
Compare
I think it all boils down to this:
See #64 (comment) for why it is working as defined for ICU and #64 (comment) for what is currently NOT working Patches and fixes are always great, but first the expected behavior needs to be defined and evaluated. Especially when it diverges from what was initially designed and reviewed(!) |
All I need to do is to get decimal point, thousands separator and grouping because I need to define a regex to find and parse numbers from strings, and the library that I use to deal with numbers only supports std::numpunct. There is no way currently to get that information from boost::locale without hacks. |
So you need a std::numpunct for the output of Let's take #64 (comment)
If that is a possible output of -> Don't use bl::as::number, fix the posix numpunct in Boost.Locale and use that. |
It is long. TL;DR -> skip 3 paragraphs I came here because I wanted to have a locale aware formatting functionality, that does not force me to use any heavy commercial product (if there is anything else that can work cross-platform I will be happy to try it). How hard it could be, right? There is a Finally I can use generated locale and inject it to formatting library to have TL;DRTo sum up. I can not even have WorkaroundI can always use |
I still don't understand the issue that is trying to be solved here.
So the issue is that the current Can you show a few simple test codes and expected outputs? |
I have put some code in the repository on GitHub It is worth mentioning what locales I have on my OS:
Question is: Should different backends behave differently in the same conditions? Stream based formating works well, but only for ICU, as std and posix provide only "best-effort" and produce the same output as in case of FMT format, so C for missing locales, and "best-effort" for multi character ones. QtLocale formatting is using ICU under the hood. As you can see numbers are formatted correctly in all cases. To sum up. There should be easily accessible and correct solution for a community. It was not "so easy" to write a code to inherit from
|
Ok, I'll tackle that soonish although I can't provide estimates. First I want to get the tests of this lib back passing to avoid introducing regressions.
Yes. IMO (I didn't invent this library, I only help maintaining) each backend should do formatting as good as possible. ICU is basically the "gold standard" in this regards so other backends may differ from ICU due to lack of the data tables etc. that ICU provides.
So basically the approach done by this PR. So in summary this would be the solution:
Hence power users could do:
and other libs can always do This addresses all 3 points of your options:
|
bb6342c
to
856ebf2
Compare
d033f1e
to
8f3a906
Compare
8f3a906
to
6d6942c
Compare
FYI: I'm working on this and will open a new PR containing your change, rebased to develop with conflicts resolved already. That was non-trivial so I didn't want to burden you with that especially as it took that long till I got to this. I'll also add tests for this which was a lot harder earlier but now should be pretty straight forward. So nothing do to from your side. Anyway: Thanks for your proposal and work and sorry for not getting to this earlier. |
#64 This PR attempts to fix the issue with the suggestion I've been making
It removes the std::numpunct implementation and instead replaces it with a simple, custom class with a similar interface that returns string_type instead of CharType.