From: Gabriel Ivăncescu gabrielopcode@gmail.com
Fixes a regression introduced by 56099a31242dcc522fb94643e70553e152c522ec.
LOCALE_SGROUPING's string and the `Grouping` field in NUMBERFMTW are confusingly different. The former, which is what is fixed here, treats a '0' as a repeat of the previous grouping. But a 0 at the end of the `Grouping` field prevents it from repeating (it repeats by default otherwise) so it's the opposite. Note that without a '0' in the LOCALE_SGROUPING string, it shouldn't even repeat in the first place.
This fixes the typical "3;0" default grouping, for example.
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com ---
See: https://learn.microsoft.com/en-us/windows/win32/intl/locale-sgrouping --- dlls/kernelbase/locale.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/dlls/kernelbase/locale.c b/dlls/kernelbase/locale.c index 1e96e49622e..31664ae07b4 100644 --- a/dlls/kernelbase/locale.c +++ b/dlls/kernelbase/locale.c @@ -7272,9 +7272,9 @@ static WCHAR *prepend_str( WCHAR *end, const WCHAR *str ) static WCHAR *format_number( WCHAR *end, const WCHAR *value, const WCHAR *decimal_sep, const WCHAR *thousand_sep, const WCHAR *grouping, UINT digits, BOOL lzero ) { + UINT i, len = 0, limit = 0, repeat = 0; const WCHAR *frac = NULL; BOOL round = FALSE; - UINT i, len = 0;
*(--end) = 0;
@@ -7327,9 +7327,10 @@ static WCHAR *format_number( WCHAR *end, const WCHAR *value, const WCHAR *decima } if (len) lzero = FALSE;
+ if (*grouping >= '1' && *grouping <= '9') + limit = repeat = *grouping - '0'; while (len) { - UINT limit = *grouping == '0' ? ~0u : *grouping - '0'; while (len && limit--) { WCHAR ch = value[--len]; @@ -7345,7 +7346,16 @@ static WCHAR *format_number( WCHAR *end, const WCHAR *value, const WCHAR *decima *(--end) = ch; } if (len) end = prepend_str( end, thousand_sep ); - if (grouping[1] == ';') grouping += 2; + if (*grouping == '0') + limit = repeat; + else if (grouping[1] == ';') + { + grouping += 2; + if (*grouping == '0') + limit = repeat; + else if (*grouping >= '1' && *grouping <= '9') + limit = repeat = *grouping - '0'; + } } if (round) *(--end) = '1'; else if (lzero) *(--end) = '0';