Add POSIX's apostrophe flag for printf-based funcs (#1285)

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.
This commit is contained in:
Gabriel Ravier 2024-09-15 02:17:40 +02:00 committed by GitHub
parent e3d28de8a6
commit 675abfa029
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View file

@ -250,3 +250,10 @@ TEST(snprintf, testAConversionSpecifier) {
ASSERT_STREQ("0x1.8p+4", buf);
}
*/
TEST(snprintf, apostropheFlag) {
char buf[20];
int i = snprintf(buf, sizeof(buf), "%'d", 1000000);
ASSERT_EQ(7, i);
ASSERT_STREQ("1000000", buf);
}