diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-07-18 11:20:56 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-07-20 11:15:58 +0000 |
commit | 25de37381de37dab191bda85e6f1c2d172e6092e (patch) | |
tree | 3b6ccfb7ba123df2cb1755e022fe6bef9163d1c0 /src/corelib/text/qlocale_win.cpp | |
parent | 3174f44579ac448198c02518d42d9eff48c1ed75 (diff) |
QLocale/Win: statically assert that is_sorted(windows_to_iso_list)
Consequently, remove the corresponding comment.
Need to mark the array as constexpr in order to run q20::is_sorted on
it.
Instead of overloading op< (which would be wrong, because there's no
one natural ordering of these entries), write the idiomatic manual
mixed-mode comparator By<FieldName> and use that. A follow-up commit
will use the same function object to replace the hand-written binary
search with a call to lower_bound().
Task-number: QTBUG-103721
Change-Id: I47743b5620dc3cece73b2e5bae658d5a636554dd
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/text/qlocale_win.cpp')
-rw-r--r-- | src/corelib/text/qlocale_win.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/corelib/text/qlocale_win.cpp b/src/corelib/text/qlocale_win.cpp index f67965539b..97ef7a3970 100644 --- a/src/corelib/text/qlocale_win.cpp +++ b/src/corelib/text/qlocale_win.cpp @@ -12,6 +12,8 @@ #include "QtCore/private/qgregoriancalendar_p.h" // for yearSharingWeekDays() +#include <q20algorithm.h> + #ifdef Q_OS_WIN # include <qt_windows.h> # include <time.h> @@ -888,8 +890,14 @@ struct WindowsToISOListElt { char iso_name[6]; }; -/* NOTE: This array should be sorted by the first column! */ -static const WindowsToISOListElt windows_to_iso_list[] = { +namespace { +struct ByWindowsCode { + constexpr bool operator()(WindowsToISOListElt lhs, WindowsToISOListElt rhs) const noexcept + { return lhs.windows_code < rhs.windows_code; } +}; +} // unnamed namespace + +static constexpr WindowsToISOListElt windows_to_iso_list[] = { { 0x0401, "ar_SA" }, { 0x0402, "bg\0 " }, { 0x0403, "ca\0 " }, @@ -1003,6 +1011,9 @@ static const WindowsToISOListElt windows_to_iso_list[] = { static const int windows_to_iso_count = sizeof(windows_to_iso_list)/sizeof(WindowsToISOListElt); +static_assert(q20::is_sorted(std::begin(windows_to_iso_list), std::end(windows_to_iso_list), + ByWindowsCode{})); + static const char *winLangCodeToIsoName(int code) { int cmp = code - windows_to_iso_list[0].windows_code; |