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;
42 if (options.testFlag(Opt::WidthInsensitive))
43 collator |= NORM_IGNOREWIDTH;
52int QCollator::compare(QStringView s1, QStringView s2)
const
55 return s2.size() ? -1 : 0;
60 d =
new QCollatorPrivate(QCollatorPrivate(QLocale().collation()));
63 return s1.compare(s2, caseSensitivity());
65 d->ensureInitialized();
75 const QString locale = d->locale.bcp47Name();
76 const int ret = CompareStringEx(
reinterpret_cast<
const wchar_t *>(locale.constData()),
78 reinterpret_cast<
const wchar_t *>(s1.data()), s1.size(),
79 reinterpret_cast<
const wchar_t *>(s2.data()), s2.size(),
84 switch (DWORD error = GetLastError()) {
85 case ERROR_INVALID_FLAGS:
86 qCWarning(lcQCollator,
"Unsupported flags (%d) used in QCollator",
int(d->collator));
88 case ERROR_INVALID_PARAMETER:
89 qCWarning(lcQCollator,
"Invalid parameter for QCollator::compare()");
92 qErrnoWarning(error,
"Failed comparison in QCollator::compare()");
100QCollatorSortKey QCollator::sortKey(
const QString &string)
const
102 if (string.isEmpty()) {
105 return QCollatorPrivate::sortKeyFromData(QByteArray());
109 d =
new QCollatorPrivate(QCollatorPrivate(QLocale().collation()));
110 d->ensureInitialized();
113 return QCollatorPrivate::sortKeyFromData(string.toUtf8());
115 const QString localeName = d->locale.bcp47Name();
116 auto callLcMapString = [&](LPWSTR lpDestStr,
int cchDest) {
118 return LCMapStringEx(
reinterpret_cast<
const wchar_t *>(localeName.constData()),
119 LCMAP_SORTKEY | d->collator,
120 reinterpret_cast<
const wchar_t*>(string.constData()), string.size(),
121 lpDestStr, cchDest,
nullptr,
nullptr, 0);
124 int size = callLcMapString(
nullptr, 0);
125 CollatorKeyType ret(size, Qt::Uninitialized);
126 size = callLcMapString(
reinterpret_cast<
wchar_t*>(ret.data()), ret.size());
127 if (size != ret.size())
130 qErrnoWarning(
"Error when generating the ::sortKey by LCMapStringEx");
132 return QCollatorPrivate::sortKeyFromData(std::move(ret));
135int QCollatorSortKey::compare(
const QCollatorSortKey &otherKey)
const noexcept
137 return d->m_key.compare(otherKey.d->m_key);
Combined button and popup list for selecting options.
#define SORT_DIGITSASNUMBERS