9#include <emscripten/val.h>
26 emscripten::val collatorOptions = emscripten::val::object();
27 if (options.testFlag(Opt::NumericSort))
28 collatorOptions.set(
"numeric",
true);
29 collatorOptions.set(
"sensitivity",
30 options.testFlag(Opt::CaseInsensitive) ?
"accent" :
"variant");
31 if (options.testFlag(Opt::IgnorePunctuation))
32 collatorOptions.set(
"ignorePunctuation",
true);
36 const QString bcp47 = locale.bcp47Name();
37 const emscripten::val locales = bcp47.isEmpty()
38 ? emscripten::val::undefined()
39 : emscripten::val(bcp47.toStdString());
41 const emscripten::val intl = emscripten::val::global(
"Intl");
42 collator =
new emscripten::val(intl[
"Collator"].new_(locales, collatorOptions));
58int compareImpl(
const emscripten::val &collator, QStringView s1, QStringView s2,
59 Qt::CaseSensitivity cs)
62 return s2.isEmpty() ? 0 : -1;
65 if (collator.isUndefined())
66 return s1.compare(s2, cs);
68 const int result = collator.call<
int>(
"compare",
69 s1.toString().toStdString(), s2.toString().toStdString());
70 return result < 0 ? -1 : (result > 0 ? 1 : 0);
74int QCollator::compare(QStringView s1, QStringView s2)
const
77 d =
new QCollatorPrivate(QLocale().collation());
80 return compareImpl(emscripten::val::undefined(), s1, s2, caseSensitivity());
82 d->ensureInitialized();
83 return compareImpl(*d->collator, s1, s2, caseSensitivity());
86QCollatorSortKey QCollator::sortKey(
const QString &string)
const
89 d =
new QCollatorPrivate(QLocale().collation());
94 QCollatorSortKeyWasm key;
97 d->ensureInitialized();
98 key.collator = *d->collator;
100 return QCollatorPrivate::sortKeyFromData(std::move(key));
103int QCollatorSortKey::compare(
const QCollatorSortKey &otherKey)
const noexcept
105 return compareImpl(d->m_key.collator, d->m_key.string, otherKey.d->m_key.string, Qt::CaseSensitive);
Combined button and popup list for selecting options.
const CollatorType NoCollator