File indexing completed on 2026-05-20 08:19:51
0001
0002
0003
0004
0005
0006 #ifndef QCOLLATOR_H
0007 #define QCOLLATOR_H
0008
0009 #include <QtCore/qstring.h>
0010 #include <QtCore/qstringlist.h>
0011 #include <QtCore/qlocale.h>
0012
0013 QT_BEGIN_NAMESPACE
0014
0015 class QCollatorPrivate;
0016 class QCollatorSortKeyPrivate;
0017 QT_DECLARE_QESDP_SPECIALIZATION_DTOR(QCollatorSortKeyPrivate)
0018
0019 class Q_CORE_EXPORT QCollatorSortKey
0020 {
0021 friend class QCollator;
0022 public:
0023 QCollatorSortKey(const QCollatorSortKey &other);
0024 QCollatorSortKey(QCollatorSortKey &&other) noexcept = default;
0025 ~QCollatorSortKey();
0026 QCollatorSortKey &operator=(const QCollatorSortKey &other);
0027 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QCollatorSortKey)
0028 void swap(QCollatorSortKey &other) noexcept
0029 { d.swap(other.d); }
0030
0031 int compare(const QCollatorSortKey &key) const;
0032 friend bool operator<(const QCollatorSortKey &lhs, const QCollatorSortKey &rhs)
0033 { return lhs.compare(rhs) < 0; }
0034
0035 protected:
0036 QCollatorSortKey(QCollatorSortKeyPrivate*);
0037
0038 QExplicitlySharedDataPointer<QCollatorSortKeyPrivate> d;
0039
0040 private:
0041 QCollatorSortKey();
0042 };
0043
0044 class Q_CORE_EXPORT QCollator
0045 {
0046 public:
0047 QCollator();
0048 explicit QCollator(const QLocale &locale);
0049 QCollator(const QCollator &);
0050 ~QCollator();
0051 QCollator &operator=(const QCollator &);
0052 QCollator(QCollator &&other) noexcept
0053 : d(other.d) { other.d = nullptr; }
0054 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QCollator)
0055
0056 void swap(QCollator &other) noexcept
0057 { qt_ptr_swap(d, other.d); }
0058
0059 void setLocale(const QLocale &locale);
0060 QLocale locale() const;
0061
0062 Qt::CaseSensitivity caseSensitivity() const;
0063 void setCaseSensitivity(Qt::CaseSensitivity cs);
0064
0065 void setNumericMode(bool on);
0066 bool numericMode() const;
0067
0068 void setIgnorePunctuation(bool on);
0069 bool ignorePunctuation() const;
0070
0071 int compare(const QString &s1, const QString &s2) const
0072 { return compare(QStringView(s1), QStringView(s2)); }
0073 #if QT_CORE_REMOVED_SINCE(6, 4) && QT_POINTER_SIZE != 4
0074 int compare(const QChar *s1, int len1, const QChar *s2, int len2) const
0075 { return compare(QStringView(s1, len1), QStringView(s2, len2)); }
0076 #endif
0077 int compare(const QChar *s1, qsizetype len1, const QChar *s2, qsizetype len2) const
0078 { return compare(QStringView(s1, len1), QStringView(s2, len2)); }
0079
0080 bool operator()(const QString &s1, const QString &s2) const
0081 { return compare(s1, s2) < 0; }
0082 int compare(QStringView s1, QStringView s2) const;
0083
0084 bool operator()(QStringView s1, QStringView s2) const
0085 { return compare(s1, s2) < 0; }
0086
0087 QCollatorSortKey sortKey(const QString &string) const;
0088
0089 static int defaultCompare(QStringView s1, QStringView s2);
0090 static QCollatorSortKey defaultSortKey(QStringView key);
0091
0092 private:
0093 QCollatorPrivate *d;
0094
0095 void detach();
0096 };
0097
0098 Q_DECLARE_SHARED(QCollatorSortKey)
0099 Q_DECLARE_SHARED(QCollator)
0100
0101 QT_END_NAMESPACE
0102
0103 #endif