1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // Copyright (C) 2013 Aleix Pol Gonzalez <aleixpol@kde.org> |
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_P_H |
6 | #define QCOLLATOR_P_H |
7 | |
8 | // |
9 | // W A R N I N G |
10 | // ------------- |
11 | // |
12 | // This file is not part of the Qt API. It exists purely as an |
13 | // implementation detail. This header file may change from version to |
14 | // version without notice, or even be removed. |
15 | // |
16 | // We mean it. |
17 | // |
18 | |
19 | #include <QtCore/private/qglobal_p.h> |
20 | #include "qcollator.h" |
21 | #include <QList> |
22 | #if QT_CONFIG(icu) |
23 | #include <unicode/ucol.h> |
24 | #elif defined(Q_OS_MACOS) |
25 | #include <CoreServices/CoreServices.h> |
26 | #elif defined(Q_OS_WIN) |
27 | #include <qt_windows.h> |
28 | #endif |
29 | |
30 | QT_BEGIN_NAMESPACE |
31 | |
32 | #if QT_CONFIG(icu) |
33 | typedef UCollator *CollatorType; |
34 | typedef QByteArray CollatorKeyType; |
35 | const CollatorType NoCollator = nullptr; |
36 | |
37 | #elif defined(Q_OS_MACOS) |
38 | typedef CollatorRef CollatorType; |
39 | typedef QList<UCCollationValue> CollatorKeyType; |
40 | const CollatorType NoCollator = 0; |
41 | |
42 | #elif defined(Q_OS_WIN) |
43 | typedef QString CollatorKeyType; |
44 | typedef int CollatorType; |
45 | const CollatorType NoCollator = 0; |
46 | |
47 | #else // posix - ignores CollatorType collator, only handles system locale |
48 | typedef QList<wchar_t> CollatorKeyType; |
49 | typedef bool CollatorType; |
50 | const CollatorType NoCollator = false; |
51 | #endif |
52 | |
53 | class QCollatorPrivate |
54 | { |
55 | public: |
56 | QAtomicInt ref = 1; |
57 | QLocale locale; |
58 | #if defined(Q_OS_WIN) && !QT_CONFIG(icu) |
59 | LCID localeID; |
60 | #endif |
61 | Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive; |
62 | bool numericMode = false; |
63 | bool ignorePunctuation = false; |
64 | bool dirty = true; |
65 | |
66 | CollatorType collator = NoCollator; |
67 | |
68 | QCollatorPrivate(const QLocale &locale) : locale(locale) {} |
69 | ~QCollatorPrivate() { cleanup(); } |
70 | bool isC() { return locale.language() == QLocale::C; } |
71 | |
72 | void clear() { |
73 | cleanup(); |
74 | collator = NoCollator; |
75 | } |
76 | |
77 | void ensureInitialized() |
78 | { |
79 | if (dirty) |
80 | init(); |
81 | } |
82 | |
83 | // Implemented by each back-end, in its own way: |
84 | void init(); |
85 | void cleanup(); |
86 | |
87 | private: |
88 | Q_DISABLE_COPY_MOVE(QCollatorPrivate) |
89 | }; |
90 | |
91 | class QCollatorSortKeyPrivate : public QSharedData |
92 | { |
93 | friend class QCollator; |
94 | public: |
95 | template <typename...T> |
96 | explicit QCollatorSortKeyPrivate(T &&...args) |
97 | : QSharedData() |
98 | , m_key(std::forward<T>(args)...) |
99 | { |
100 | } |
101 | |
102 | CollatorKeyType m_key; |
103 | |
104 | private: |
105 | Q_DISABLE_COPY_MOVE(QCollatorSortKeyPrivate) |
106 | }; |
107 | |
108 | |
109 | QT_END_NAMESPACE |
110 | |
111 | #endif // QCOLLATOR_P_H |
112 | |