Merge pull request #4360 from milescoviello/fix/wide-printf-grouping-flag

fix(libc): accept the ' flag in the wide printf family
This commit is contained in:
Dean 2026-10-13 07:20:09 +13:00 committed by GitHub
commit dfe9ccf6a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View File

@ -115,9 +115,10 @@ std::u16string FormatWide(const char16_t* format, VaList* source, bool secure =
bool left = false;
int width = 0;
int precision = -1;
while (In(*format, "-+ #0")) {
while (In(*format, "-+ #0'")) {
if (*format == u'-') left = true;
spec += static_cast<char>(*format++);
if (*format != u'\'') spec += static_cast<char>(*format);
++format;
}
if (*format == u'*') {
++format;

View File

@ -135,6 +135,14 @@ static void CheckCount() {
Require(Format(buffer, 16, u"a%n", nullCount) < 0, "vswprintf null %n argument");
}
static void CheckGroupingFlag() {
char16_t buffer[48];
Require(swprintf_nid_postfix(buffer, 48, u"%'d|%'-6u|%'.2f|%'+05d|%'g", 1234567, 42u, 1234.5, 12, 1e6) == 34 &&
buffer == std::u16string(u"1234567|42 |1234.50|+0012|1e+06"), "swprintf ' flag");
Require(snwprintf_s_nid_postfix(buffer, 48, u"%'lld %ls", 9876543210ll, u"x") == 12 && buffer == std::u16string(u"9876543210 x"),
"snwprintf_s ' flag");
}
static void CheckSwprintf() {
char16_t buffer[8];
for (auto& unit : buffer) unit = u'x';
@ -176,4 +184,5 @@ int main() {
Check(u"%.2s", "\xf0\x9f\x98\x80x", u"\U0001f600");
Check(u"%.1s", "\xf0\x9f\x98\x80x", u"");
Check(u"%.3s", "\xf0\x9f\x98\x80x", u"\U0001f600x");
CheckGroupingFlag();
}