From d95f4d00189082e0217ab06aa0911e6bbffb3ade Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 6 Aug 2021 12:24:37 +0200 Subject: [PATCH] qlocale_win: Simplify and explain month-name format lookup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/corelib/text/qlocale_win.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/corelib/text/qlocale_win.cpp b/src/corelib/text/qlocale_win.cpp index 38f04d686d..bfb20538eb 100644 --- a/src/corelib/text/qlocale_win.cpp +++ b/src/corelib/text/qlocale_win.cpp @@ -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)