-
-
Notifications
You must be signed in to change notification settings - Fork 636
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
Add POSIX's apostrophe flag for printf-based funcs #1285
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do support grouping. You can say %,d
for 1,000,000
. Could you please change %'d
so it formats 1'000'000
? Then afterwards we should probably look into importing Musl's localeconv() function so we can access its grouping field. I want the default behavior for Cosmopolitan Libc to be using that apostrophe since it's culture agnostic and I have a disability that makes me allergic to calling setlocale() and unable to read large numbers without grouping. Obviously though if the locale actually specifies a grouping (e.g. English, German) then we should use what it specifies. If you decide to do this (I will if you won't) then please take care to ensure that obtaining the current locale grouping doesn't link any locale code. It should only need to access a global variable through TLS I think.
Well, given that in the C/POSIX locale (the mandatory default before |
I've added a commit to make this change. |
9e0ead5
to
ca31cfe
Compare
I can see that you view this as something important and the standard is on your side. In that case, I'm convinced. Could you please update this PR to go back to the conformant behavior you originally chose? |
881d151
to
7b4e85c
Compare
I have just done so. |
POSIX specifies the <apostrophe> flag character for printf as formatting decimal conversions with the thousands' grouping characters specified by the current locale. Given that cosmopolitan currently has no support for obtaining the locale's grouping character, all that is required (when in the C/POSIX locale) for supporting this flag is ignoring it, and as it's already used to indicate quoting (for non-decimal conversions), all that has to be done is to avoid having it be an alias for the <space> flag so that decimal conversions don't accidentally behave as though the <space> flag has also been specified whenever the <apostrophe> flag is utilized. This patch adds this flag, as described above, along with a test for it.
7b4e85c
to
a482681
Compare
POSIX specifies the flag character for printf as formatting
decimal conversions with the thousands' grouping characters specified by
the current locale. Given that cosmopolitan currently has no support for
obtaining the locale's grouping character, all that is required (when in
the C/POSIX locale) for supporting this flag is ignoring it, and as it's
already used to indicate quoting (for non-decimal conversions), all that
has to be done is to avoid having it be an alias for the flag so
that decimal conversions don't accidentally behave as though the
flag has also been specified whenever the flag is utilized.
This patch adds this flag, as described above, along with a test for it.