12#include <qt_windows.h>
18#ifndef SORT_DIGITSASNUMBERS
19#define SORT_DIGITSASNUMBERS 8
28 if (options.testFlag(Opt::CaseInsensitive))
29 collator |= NORM_IGNORECASE;
33 if (options.testFlag(Opt::NumericSort))
36 if (options.testFlag(Opt::IgnorePunctuation))
37 collator |= NORM_IGNORESYMBOLS;
39 if (options.testFlag(Opt::DiacriticInsensitive))
40 collator |= LINGUISTIC_IGNOREDIACRITIC;
49int QCollator::compare(QStringView s1, QStringView s2)
const
52 return s2.size() ? -1 : 0;
57 d =
new QCollatorPrivate(QCollatorPrivate(QLocale().collation()));
60 return s1.compare(s2, caseSensitivity());
62 d->ensureInitialized();
72 const QString locale = d->locale.bcp47Name();
73 const int ret = CompareStringEx(
reinterpret_cast<
const wchar_t *>(locale.constData()),
75 reinterpret_cast<
const wchar_t *>(s1.data()), s1.size(),
76 reinterpret_cast<
const wchar_t *>(s2.data()), s2.size(),
81 switch (DWORD error = GetLastError()) {
82 case ERROR_INVALID_FLAGS:
83 qWarning(
"Unsupported flags (%d) used in QCollator",
int(d->collator));
85 case ERROR_INVALID_PARAMETER:
86 qWarning(
"Invalid parameter for QCollator::compare()");
89 qErrnoWarning(error,
"Failed comparison in QCollator::compare()");
97QCollatorSortKey QCollator::sortKey(
const QString &string)
const
99 if (string.isEmpty()) {
102 return QCollatorPrivate::sortKeyFromData(QByteArray());
106 d =
new QCollatorPrivate(QCollatorPrivate(QLocale().collation()));
107 d->ensureInitialized();
110 return QCollatorPrivate::sortKeyFromData(string.toUtf8());
112 const QString localeName = d->locale.bcp47Name();
113 auto callLcMapString = [&](LPWSTR lpDestStr,
int cchDest) {
115 return LCMapStringEx(
reinterpret_cast<
const wchar_t *>(localeName.constData()),
116 LCMAP_SORTKEY | d->collator,
117 reinterpret_cast<
const wchar_t*>(string.constData()), string.size(),
118 lpDestStr, cchDest,
nullptr,
nullptr, 0);
121 int size = callLcMapString(
nullptr, 0);
122 CollatorKeyType ret(size, Qt::Uninitialized);
123 size = callLcMapString(
reinterpret_cast<
wchar_t*>(ret.data()), ret.size());
124 if (size != ret.size())
127 qErrnoWarning(
"Error when generating the ::sortKey by LCMapStringEx");
129 return QCollatorPrivate::sortKeyFromData(std::move(ret));
132int QCollatorSortKey::compare(
const QCollatorSortKey &otherKey)
const noexcept
134 return d->m_key.compare(otherKey.d->m_key);
Combined button and popup list for selecting options.
#define SORT_DIGITSASNUMBERS