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_P_H |
42 | #define QCOLLATOR_P_H |
43 | |
44 | // |
45 | // W A R N I N G |
46 | // ------------- |
47 | // |
48 | // This file is not part of the Qt API. It exists purely as an |
49 | // implementation detail. This header file may change from version to |
50 | // version without notice, or even be removed. |
51 | // |
52 | // We mean it. |
53 | // |
54 | |
55 | #include <QtCore/private/qglobal_p.h> |
56 | #include "qcollator.h" |
57 | #include <QList> |
58 | #if QT_CONFIG(icu) |
59 | #include <unicode/ucol.h> |
60 | #elif defined(Q_OS_MACOS) |
61 | #include <CoreServices/CoreServices.h> |
62 | #elif defined(Q_OS_WIN) |
63 | #include <qt_windows.h> |
64 | #endif |
65 | |
66 | QT_BEGIN_NAMESPACE |
67 | |
68 | #if QT_CONFIG(icu) |
69 | typedef UCollator *CollatorType; |
70 | typedef QByteArray CollatorKeyType; |
71 | const CollatorType NoCollator = nullptr; |
72 | |
73 | #elif defined(Q_OS_MACOS) |
74 | typedef CollatorRef CollatorType; |
75 | typedef QList<UCCollationValue> CollatorKeyType; |
76 | const CollatorType NoCollator = 0; |
77 | |
78 | #elif defined(Q_OS_WIN) |
79 | typedef QString CollatorKeyType; |
80 | typedef int CollatorType; |
81 | const CollatorType NoCollator = 0; |
82 | |
83 | #else // posix - ignores CollatorType collator, only handles system locale |
84 | typedef QList<wchar_t> CollatorKeyType; |
85 | typedef bool CollatorType; |
86 | const CollatorType NoCollator = false; |
87 | #endif |
88 | |
89 | class QCollatorPrivate |
90 | { |
91 | public: |
92 | QAtomicInt ref = 1; |
93 | QLocale locale; |
94 | #if defined(Q_OS_WIN) && !QT_CONFIG(icu) |
95 | #ifdef USE_COMPARESTRINGEX |
96 | QString localeName; |
97 | #else |
98 | LCID localeID; |
99 | #endif |
100 | #endif |
101 | Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive; |
102 | bool numericMode = false; |
103 | bool ignorePunctuation = false; |
104 | bool dirty = true; |
105 | |
106 | CollatorType collator = NoCollator; |
107 | |
108 | QCollatorPrivate(const QLocale &locale) : locale(locale) {} |
109 | ~QCollatorPrivate() { cleanup(); } |
110 | bool isC() { return locale.language() == QLocale::C; } |
111 | |
112 | void clear() { |
113 | cleanup(); |
114 | collator = NoCollator; |
115 | } |
116 | |
117 | // Implemented by each back-end, in its own way: |
118 | void init(); |
119 | void cleanup(); |
120 | |
121 | private: |
122 | Q_DISABLE_COPY_MOVE(QCollatorPrivate) |
123 | }; |
124 | |
125 | class QCollatorSortKeyPrivate : public QSharedData |
126 | { |
127 | friend class QCollator; |
128 | public: |
129 | template <typename...T> |
130 | explicit QCollatorSortKeyPrivate(T &&...args) |
131 | : QSharedData() |
132 | , m_key(std::forward<T>(args)...) |
133 | { |
134 | } |
135 | |
136 | CollatorKeyType m_key; |
137 | |
138 | private: |
139 | Q_DISABLE_COPY_MOVE(QCollatorSortKeyPrivate) |
140 | }; |
141 | |
142 | |
143 | QT_END_NAMESPACE |
144 | |
145 | #endif // QCOLLATOR_P_H |
146 | |