| 1 | // Copyright (C) 2020 The Qt Company Ltd. |
| 2 | // Copyright (C) 2013 Aleix Pol Gonzalez <[email protected]> |
| 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 4 | |
| 5 | #ifndef QCOLLATOR_H |
| 6 | #define QCOLLATOR_H |
| 7 | |
| 8 | #include <QtCore/qstring.h> |
| 9 | #include <QtCore/qstringlist.h> |
| 10 | #include <QtCore/qlocale.h> |
| 11 | |
| 12 | QT_BEGIN_NAMESPACE |
| 13 | |
| 14 | class QCollatorPrivate; |
| 15 | class QCollatorSortKeyPrivate; |
| 16 | QT_DECLARE_QESDP_SPECIALIZATION_DTOR(QCollatorSortKeyPrivate) |
| 17 | |
| 18 | class Q_CORE_EXPORT QCollatorSortKey |
| 19 | { |
| 20 | friend class QCollator; |
| 21 | public: |
| 22 | QCollatorSortKey(const QCollatorSortKey &other); |
| 23 | QCollatorSortKey(QCollatorSortKey &&other) noexcept = default; |
| 24 | ~QCollatorSortKey(); |
| 25 | QCollatorSortKey &operator=(const QCollatorSortKey &other); |
| 26 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QCollatorSortKey) |
| 27 | void swap(QCollatorSortKey &other) noexcept |
| 28 | { d.swap(other&: other.d); } |
| 29 | |
| 30 | int compare(const QCollatorSortKey &key) const; |
| 31 | friend bool operator<(const QCollatorSortKey &lhs, const QCollatorSortKey &rhs) |
| 32 | { return lhs.compare(key: rhs) < 0; } |
| 33 | |
| 34 | protected: |
| 35 | QCollatorSortKey(QCollatorSortKeyPrivate*); |
| 36 | |
| 37 | QExplicitlySharedDataPointer<QCollatorSortKeyPrivate> d; |
| 38 | |
| 39 | private: |
| 40 | QCollatorSortKey(); |
| 41 | }; |
| 42 | |
| 43 | class Q_CORE_EXPORT QCollator |
| 44 | { |
| 45 | public: |
| 46 | QCollator(); |
| 47 | explicit QCollator(const QLocale &locale); |
| 48 | QCollator(const QCollator &); |
| 49 | ~QCollator(); |
| 50 | QCollator &operator=(const QCollator &); |
| 51 | QCollator(QCollator &&other) noexcept |
| 52 | : d(other.d) { other.d = nullptr; } |
| 53 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QCollator) |
| 54 | |
| 55 | void swap(QCollator &other) noexcept |
| 56 | { qt_ptr_swap(lhs&: d, rhs&: other.d); } |
| 57 | |
| 58 | void setLocale(const QLocale &locale); |
| 59 | QLocale locale() const; |
| 60 | |
| 61 | Qt::CaseSensitivity caseSensitivity() const; |
| 62 | void setCaseSensitivity(Qt::CaseSensitivity cs); |
| 63 | |
| 64 | void setNumericMode(bool on); |
| 65 | bool numericMode() const; |
| 66 | |
| 67 | void setIgnorePunctuation(bool on); |
| 68 | bool ignorePunctuation() const; |
| 69 | |
| 70 | int compare(const QString &s1, const QString &s2) const |
| 71 | { return compare(s1: QStringView(s1), s2: QStringView(s2)); } |
| 72 | #if QT_CORE_REMOVED_SINCE(6, 4) && QT_POINTER_SIZE != 4 |
| 73 | int compare(const QChar *s1, int len1, const QChar *s2, int len2) const |
| 74 | { return compare(QStringView(s1, len1), QStringView(s2, len2)); } |
| 75 | #endif |
| 76 | int compare(const QChar *s1, qsizetype len1, const QChar *s2, qsizetype len2) const |
| 77 | { return compare(s1: QStringView(s1, len1), s2: QStringView(s2, len2)); } |
| 78 | |
| 79 | bool operator()(const QString &s1, const QString &s2) const |
| 80 | { return compare(s1, s2) < 0; } |
| 81 | int compare(QStringView s1, QStringView s2) const; |
| 82 | |
| 83 | bool operator()(QStringView s1, QStringView s2) const |
| 84 | { return compare(s1, s2) < 0; } |
| 85 | |
| 86 | QCollatorSortKey sortKey(const QString &string) const; |
| 87 | |
| 88 | static int defaultCompare(QStringView s1, QStringView s2); |
| 89 | static QCollatorSortKey defaultSortKey(QStringView key); |
| 90 | |
| 91 | private: |
| 92 | QCollatorPrivate *d; |
| 93 | |
| 94 | void detach(); |
| 95 | }; |
| 96 | |
| 97 | Q_DECLARE_SHARED(QCollatorSortKey) |
| 98 | Q_DECLARE_SHARED(QCollator) |
| 99 | |
| 100 | QT_END_NAMESPACE |
| 101 | |
| 102 | #endif // QCOLLATOR_P_H |
| 103 | |