qlocale_win: Simplify and explain month-name format lookup

Retain the given month number and simply subtract one from it in the
one place it's used (once the two array dereferencs are unified). That
makes it clear that the off-by-one numbering is just down to our
arrays, not some weired quirk of the MS API. Simplify a condition by
inverting it: compare to LongFormat instead of ||-ing comparisons to
the other two members of the enum.

Change-Id: Ia03486b7869255ecdb1372de62d5c745d35d0a0a
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Edward Welbourne 2021-08-06 12:24:37 +02:00
parent 17d7a8dc2e
commit d95f4d0018

View File

@ -380,13 +380,12 @@ QVariant QSystemLocalePrivate::monthName(int month, QLocale::FormatType type)
LOCALE_SMONTHNAME7, LOCALE_SMONTHNAME8, LOCALE_SMONTHNAME9,
LOCALE_SMONTHNAME10, LOCALE_SMONTHNAME11, LOCALE_SMONTHNAME12 };
month -= 1;
if (month < 0 || month > 11)
if (month < 1 || month > 12)
return {};
LCTYPE lctype = (type == QLocale::ShortFormat || type == QLocale::NarrowFormat)
? short_month_map[month] : long_month_map[month];
return getLocaleInfo(lctype);
// Month is Jan = 1, ... Dec = 12; adjust by 1 to match array indexing from 0:
return getLocaleInfo(
(type == QLocale::LongFormat ? long_month_map : short_month_map)[month - 1]);
}
QVariant QSystemLocalePrivate::toString(QDate date, QLocale::FormatType type)