| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Copyright (C) 2013 Aleix Pol Gonzalez <aleixpol@kde.org> |
| 5 | ** Contact: https://www.qt.io/licensing/ |
| 6 | ** |
| 7 | ** This file is part of the QtCore module of the Qt Toolkit. |
| 8 | ** |
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 10 | ** Commercial License Usage |
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 12 | ** accordance with the commercial license agreement provided with the |
| 13 | ** Software or, alternatively, in accordance with the terms contained in |
| 14 | ** a written agreement between you and The Qt Company. For licensing terms |
| 15 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 16 | ** information use the contact form at https://www.qt.io/contact-us. |
| 17 | ** |
| 18 | ** GNU Lesser General Public License Usage |
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 20 | ** General Public License version 3 as published by the Free Software |
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 22 | ** packaging of this file. Please review the following information to |
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 25 | ** |
| 26 | ** GNU General Public License Usage |
| 27 | ** Alternatively, this file may be used under the terms of the GNU |
| 28 | ** General Public License version 2.0 or (at your option) the GNU General |
| 29 | ** Public license version 3 or any later version approved by the KDE Free |
| 30 | ** Qt Foundation. The licenses are as published by the Free Software |
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 32 | ** included in the packaging of this file. Please review the following |
| 33 | ** information to ensure the GNU General Public License requirements will |
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 36 | ** |
| 37 | ** $QT_END_LICENSE$ |
| 38 | ** |
| 39 | ****************************************************************************/ |
| 40 | |
| 41 | #ifndef QCOLLATOR_H |
| 42 | #define QCOLLATOR_H |
| 43 | |
| 44 | #include <QtCore/qstring.h> |
| 45 | #include <QtCore/qstringlist.h> |
| 46 | #include <QtCore/qlocale.h> |
| 47 | |
| 48 | QT_BEGIN_NAMESPACE |
| 49 | |
| 50 | class QCollatorPrivate; |
| 51 | class QCollatorSortKeyPrivate; |
| 52 | |
| 53 | class Q_CORE_EXPORT QCollatorSortKey |
| 54 | { |
| 55 | friend class QCollator; |
| 56 | public: |
| 57 | QCollatorSortKey(const QCollatorSortKey &other); |
| 58 | ~QCollatorSortKey(); |
| 59 | QCollatorSortKey &operator=(const QCollatorSortKey &other); |
| 60 | inline QCollatorSortKey &operator=(QCollatorSortKey &&other) noexcept |
| 61 | { swap(other); return *this; } |
| 62 | void swap(QCollatorSortKey &other) noexcept |
| 63 | { d.swap(other&: other.d); } |
| 64 | |
| 65 | int compare(const QCollatorSortKey &key) const; |
| 66 | |
| 67 | protected: |
| 68 | QCollatorSortKey(QCollatorSortKeyPrivate*); |
| 69 | |
| 70 | QExplicitlySharedDataPointer<QCollatorSortKeyPrivate> d; |
| 71 | |
| 72 | private: |
| 73 | QCollatorSortKey(); |
| 74 | }; |
| 75 | |
| 76 | inline bool operator<(const QCollatorSortKey &lhs, const QCollatorSortKey &rhs) |
| 77 | { |
| 78 | return lhs.compare(key: rhs) < 0; |
| 79 | } |
| 80 | |
| 81 | class Q_CORE_EXPORT QCollator |
| 82 | { |
| 83 | public: |
| 84 | QCollator(); |
| 85 | explicit QCollator(const QLocale &locale); |
| 86 | QCollator(const QCollator &); |
| 87 | ~QCollator(); |
| 88 | QCollator &operator=(const QCollator &); |
| 89 | QCollator(QCollator &&other) noexcept |
| 90 | : d(other.d) { other.d = nullptr; } |
| 91 | QCollator &operator=(QCollator &&other) noexcept |
| 92 | { swap(other); return *this; } |
| 93 | |
| 94 | void swap(QCollator &other) noexcept |
| 95 | { qSwap(value1&: d, value2&: other.d); } |
| 96 | |
| 97 | void setLocale(const QLocale &locale); |
| 98 | QLocale locale() const; |
| 99 | |
| 100 | Qt::CaseSensitivity caseSensitivity() const; |
| 101 | void setCaseSensitivity(Qt::CaseSensitivity cs); |
| 102 | |
| 103 | void setNumericMode(bool on); |
| 104 | bool numericMode() const; |
| 105 | |
| 106 | void setIgnorePunctuation(bool on); |
| 107 | bool ignorePunctuation() const; |
| 108 | |
| 109 | #if QT_STRINGVIEW_LEVEL < 2 |
| 110 | int compare(const QString &s1, const QString &s2) const; |
| 111 | int compare(const QStringRef &s1, const QStringRef &s2) const; |
| 112 | int compare(const QChar *s1, int len1, const QChar *s2, int len2) const; |
| 113 | |
| 114 | bool operator()(const QString &s1, const QString &s2) const |
| 115 | { return compare(s1, s2) < 0; } |
| 116 | #endif |
| 117 | int compare(QStringView s1, QStringView s2) const; |
| 118 | |
| 119 | bool operator()(QStringView s1, QStringView s2) const |
| 120 | { return compare(s1, s2) < 0; } |
| 121 | |
| 122 | QCollatorSortKey sortKey(const QString &string) const; |
| 123 | |
| 124 | private: |
| 125 | QCollatorPrivate *d; |
| 126 | |
| 127 | void detach(); |
| 128 | }; |
| 129 | |
| 130 | Q_DECLARE_SHARED(QCollatorSortKey) |
| 131 | Q_DECLARE_SHARED(QCollator) |
| 132 | |
| 133 | QT_END_NAMESPACE |
| 134 | |
| 135 | #endif // QCOLLATOR_P_H |
| 136 | |