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
30QT_BEGIN_NAMESPACE
31
32#if QT_CONFIG(icu)
33typedef UCollator *CollatorType;
34typedef QByteArray CollatorKeyType;
35const CollatorType NoCollator = nullptr;
36
37#elif defined(Q_OS_MACOS)
38typedef CollatorRef CollatorType;
39typedef QList<UCCollationValue> CollatorKeyType;
40const CollatorType NoCollator = 0;
41
42#elif defined(Q_OS_WIN)
43typedef QString CollatorKeyType;
44typedef int CollatorType;
45const CollatorType NoCollator = 0;
46
47#else // posix - ignores CollatorType collator, only handles system locale
48typedef QList<wchar_t> CollatorKeyType;
49typedef bool CollatorType;
50const CollatorType NoCollator = false;
51#endif
52
53class QCollatorPrivate
54{
55public:
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
87private:
88 Q_DISABLE_COPY_MOVE(QCollatorPrivate)
89};
90
91class QCollatorSortKeyPrivate : public QSharedData
92{
93 friend class QCollator;
94public:
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
104private:
105 Q_DISABLE_COPY_MOVE(QCollatorSortKeyPrivate)
106};
107
108
109QT_END_NAMESPACE
110
111#endif // QCOLLATOR_P_H
112

source code of qtbase/src/corelib/text/qcollator_p.h