diff options
| author | Edward Welbourne <edward.welbourne@qt.io> | 2021-10-05 16:39:42 +0200 |
|---|---|---|
| committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-01-13 19:47:22 +0100 |
| commit | d83dbc3db2f305e745cd75a9fd9c97128eaac42f (patch) | |
| tree | 32bb15e44097ec7ae3db5d10c241a891862793fc /src | |
| parent | 5d228beb520d92c985497fb43fa91d2920db6cb0 (diff) | |
Tidy up macOS collation and add some assertions
Change-Id: I7af21ce38f2f23498d7c8a7e027bfffb149a43e3
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src')
| -rw-r--r-- | src/corelib/text/qcollator_macx.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/corelib/text/qcollator_macx.cpp b/src/corelib/text/qcollator_macx.cpp index 62b3a904a05..713df755007 100644 --- a/src/corelib/text/qcollator_macx.cpp +++ b/src/corelib/text/qcollator_macx.cpp @@ -126,17 +126,19 @@ QCollatorSortKey QCollator::sortKey(const QString &string) const return QCollatorSortKey(nullptr); } - //Documentation recommends having it 5 times as big as the input + auto text = reinterpret_cast<const UniChar *>(string.constData()); + // Documentation recommends having it 5 times as big as the input QList<UCCollationValue> ret(string.size() * 5); ItemCount actualSize; - int status = UCGetCollationKey(d->collator, - reinterpret_cast<const UniChar *>(string.constData()), - string.count(), ret.size(), &actualSize, ret.data()); + int status = UCGetCollationKey(d->collator, text, string.count(), + ret.size(), &actualSize, ret.data()); ret.resize(actualSize + 1); if (status == kUCOutputBufferTooSmall) { - UCGetCollationKey(d->collator, reinterpret_cast<const UniChar *>(string.constData()), - string.count(), ret.size(), &actualSize, ret.data()); + status = UCGetCollationKey(d->collator, text, string.count(), + ret.size(), &actualSize, ret.data()); + Q_ASSERT(status != kUCOutputBufferTooSmall); + Q_ASSERT(ret.size() == actualSize + 1); } ret[actualSize] = 0; return QCollatorSortKey(new QCollatorSortKeyPrivate(std::move(ret))); @@ -150,7 +152,7 @@ int QCollatorSortKey::compare(const QCollatorSortKey &key) const SInt32 order; UCCompareCollationKeys(d->m_key.data(), d->m_key.size(), key.d->m_key.data(), key.d->m_key.size(), - 0, &order); + nullptr, &order); return order; } |
