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 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QCollatorSortKey) |
61 | void swap(QCollatorSortKey &other) noexcept |
62 | { d.swap(other.d); } |
63 | |
64 | int compare(const QCollatorSortKey &key) const; |
65 | |
66 | protected: |
67 | QCollatorSortKey(QCollatorSortKeyPrivate*); |
68 | |
69 | QExplicitlySharedDataPointer<QCollatorSortKeyPrivate> d; |
70 | |
71 | private: |
72 | QCollatorSortKey(); |
73 | }; |
74 | |
75 | inline bool operator<(const QCollatorSortKey &lhs, const QCollatorSortKey &rhs) |
76 | { |
77 | return lhs.compare(rhs) < 0; |
78 | } |
79 | |
80 | class Q_CORE_EXPORT QCollator |
81 | { |
82 | public: |
83 | QCollator(); |
84 | explicit QCollator(const QLocale &locale); |
85 | QCollator(const QCollator &); |
86 | ~QCollator(); |
87 | QCollator &operator=(const QCollator &); |
88 | QCollator(QCollator &&other) noexcept |
89 | : d(other.d) { other.d = nullptr; } |
90 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QCollator) |
91 | |
92 | void swap(QCollator &other) noexcept |
93 | { qSwap(d, other.d); } |
94 | |
95 | void setLocale(const QLocale &locale); |
96 | QLocale locale() const; |
97 | |
98 | Qt::CaseSensitivity caseSensitivity() const; |
99 | void setCaseSensitivity(Qt::CaseSensitivity cs); |
100 | |
101 | void setNumericMode(bool on); |
102 | bool numericMode() const; |
103 | |
104 | void setIgnorePunctuation(bool on); |
105 | bool ignorePunctuation() const; |
106 | |
107 | #if QT_STRINGVIEW_LEVEL < 2 |
108 | int compare(const QString &s1, const QString &s2) const; |
109 | int compare(const QChar *s1, int len1, const QChar *s2, int len2) const; |
110 | |
111 | bool operator()(const QString &s1, const QString &s2) const |
112 | { return compare(s1, s2) < 0; } |
113 | #endif |
114 | int compare(QStringView s1, QStringView s2) const; |
115 | |
116 | bool operator()(QStringView s1, QStringView s2) const |
117 | { return compare(s1, s2) < 0; } |
118 | |
119 | QCollatorSortKey sortKey(const QString &string) const; |
120 | |
121 | private: |
122 | QCollatorPrivate *d; |
123 | |
124 | void detach(); |
125 | }; |
126 | |
127 | Q_DECLARE_SHARED(QCollatorSortKey) |
128 | Q_DECLARE_SHARED(QCollator) |
129 | |
130 | QT_END_NAMESPACE |
131 | |
132 | #endif // QCOLLATOR_P_H |
133 | |