diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2024-02-28 16:48:58 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2024-04-22 16:01:01 +0200 |
commit | a472362f36ae92c68e167d79c9f945d1f0d158d2 (patch) | |
tree | fa49fad915b07a268566150a40bdd742157a49e2 /src/corelib/text/qlocale.cpp | |
parent | f20be43b827ffa5c9361bc128fd930841435bdf6 (diff) |
Assert consistency between locale and calendar data
They're indexed by the same key and should have the same language,
script and country. Just to be sure, assert that.
Change-Id: I9d4d9c0ef7078d6dcbb6ceccafdfaff671737689
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qlocale.cpp')
-rw-r--r-- | src/corelib/text/qlocale.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index d2550fadff..ab95b300eb 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -3018,6 +3018,14 @@ QString QLocale::standaloneDayName(int day, FormatType type) const // Calendar look-up of month and day names: +// Only used in assertions +[[maybe_unused]] static bool sameLocale(const QLocaleData *locale, const QCalendarLocale &calendar) +{ + return locale->m_language_id == calendar.m_language_id + && locale->m_script_id == calendar.m_script_id + && locale->m_territory_id == calendar.m_territory_id; +} + /*! \internal */ @@ -3126,8 +3134,9 @@ QString QCalendarBackend::monthName(const QLocale &locale, int month, int, QLocale::FormatType format) const { Q_ASSERT(month >= 1 && month <= maximumMonthsInYear()); - return rawMonthName(localeMonthIndexData()[locale.d->m_index], - localeMonthData(), month, format); + const QCalendarLocale &monthly = localeMonthIndexData()[locale.d->m_index]; + Q_ASSERT(sameLocale(locale.d->m_data, monthly)); + return rawMonthName(monthly, localeMonthData(), month, format); } QString QRomanCalendar::monthName(const QLocale &locale, int month, int year, @@ -3161,8 +3170,9 @@ QString QCalendarBackend::standaloneMonthName(const QLocale &locale, int month, QLocale::FormatType format) const { Q_ASSERT(month >= 1 && month <= maximumMonthsInYear()); - return rawStandaloneMonthName(localeMonthIndexData()[locale.d->m_index], - localeMonthData(), month, format); + const QCalendarLocale &monthly = localeMonthIndexData()[locale.d->m_index]; + Q_ASSERT(sameLocale(locale.d->m_data, monthly)); + return rawStandaloneMonthName(monthly, localeMonthData(), month, format); } QString QRomanCalendar::standaloneMonthName(const QLocale &locale, int month, int year, |