12#include <qt_windows.h>
18#ifndef SORT_DIGITSASNUMBERS
19#define SORT_DIGITSASNUMBERS 8
28 if (caseSensitivity == Qt::CaseInsensitive)
29 collator |= NORM_IGNORECASE;
36 if (ignorePunctuation)
37 collator |= NORM_IGNORESYMBOLS;
46int QCollator::compare(QStringView s1, QStringView s2)
const
49 return s2.size() ? -1 : 0;
54 d =
new QCollatorPrivate(QCollatorPrivate(QLocale().collation()));
57 return s1.compare(s2, d->caseSensitivity);
59 d->ensureInitialized();
69 const QString locale = d->locale.bcp47Name();
70 const int ret = CompareStringEx(
reinterpret_cast<
const wchar_t *>(locale.constData()),
72 reinterpret_cast<
const wchar_t *>(s1.data()), s1.size(),
73 reinterpret_cast<
const wchar_t *>(s2.data()), s2.size(),
78 switch (DWORD error = GetLastError()) {
79 case ERROR_INVALID_FLAGS:
80 qWarning(
"Unsupported flags (%d) used in QCollator",
int(d->collator));
82 case ERROR_INVALID_PARAMETER:
83 qWarning(
"Invalid parameter for QCollator::compare()");
86 qErrnoWarning(error,
"Failed comparison in QCollator::compare()");
94QCollatorSortKey QCollator::sortKey(
const QString &string)
const
96 if (string.isEmpty()) {
99 return QCollatorSortKey(
nullptr);
103 d =
new QCollatorPrivate(QCollatorPrivate(QLocale().collation()));
104 d->ensureInitialized();
107 return QCollatorSortKey(
new QCollatorSortKeyPrivate(string.toUtf8()));
109 const QString localeName = d->locale.bcp47Name();
110 auto callLcMapString = [&](LPWSTR lpDestStr,
int cchDest) {
112 return LCMapStringEx(
reinterpret_cast<
const wchar_t *>(localeName.constData()),
113 LCMAP_SORTKEY | d->collator,
114 reinterpret_cast<
const wchar_t*>(string.constData()), string.size(),
115 lpDestStr, cchDest,
nullptr,
nullptr, 0);
118 int size = callLcMapString(
nullptr, 0);
119 CollatorKeyType ret(size, Qt::Uninitialized);
120 size = callLcMapString(
reinterpret_cast<
wchar_t*>(ret.data()), ret.size());
121 if (size != ret.size())
124 qErrnoWarning(
"Error when generating the ::sortKey by LCMapStringEx");
126 return QCollatorSortKey(
new QCollatorSortKeyPrivate(std::move(ret)));
129int QCollatorSortKey::compare(
const QCollatorSortKey &otherKey)
const
132 return otherKey.d ? -1 : 0;
135 return d->m_key.compare(otherKey.d->m_key);
Combined button and popup list for selecting options.
#define SORT_DIGITSASNUMBERS