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 <QVector>
58#if QT_CONFIG(icu)
59#include <unicode/ucol.h>
60#elif defined(Q_OS_OSX)
61#include <CoreServices/CoreServices.h>
62#elif defined(Q_OS_WIN)
63#include <qt_windows.h>
64#endif
65
66QT_BEGIN_NAMESPACE
67
68#if QT_CONFIG(icu)
69typedef UCollator *CollatorType;
70typedef QByteArray CollatorKeyType;
71const CollatorType NoCollator = nullptr;
72
73#elif defined(Q_OS_OSX)
74typedef CollatorRef CollatorType;
75typedef QVector<UCCollationValue> CollatorKeyType;
76const CollatorType NoCollator = 0;
77
78#elif defined(Q_OS_WIN)
79typedef QString CollatorKeyType;
80typedef int CollatorType;
81const CollatorType NoCollator = 0;
82# ifdef Q_OS_WINRT
83# define USE_COMPARESTRINGEX
84# endif
85
86#else // posix - ignores CollatorType collator, only handles system locale
87typedef QVector<wchar_t> CollatorKeyType;
88typedef bool CollatorType;
89const CollatorType NoCollator = false;
90#endif
91
92class QCollatorPrivate
93{
94public:
95 QAtomicInt ref = 1;
96 QLocale locale;
97#if defined(Q_OS_WIN) && !QT_CONFIG(icu)
98#ifdef USE_COMPARESTRINGEX
99 QString localeName;
100#else
101 LCID localeID;
102#endif
103#endif
104 Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive;
105 bool numericMode = false;
106 bool ignorePunctuation = false;
107 bool dirty = true;
108
109 CollatorType collator = NoCollator;
110
111 QCollatorPrivate(const QLocale &locale) : locale(locale) {}
112 ~QCollatorPrivate() { cleanup(); }
113 bool isC() { return locale.language() == QLocale::C; }
114
115 void clear() {
116 cleanup();
117 collator = NoCollator;
118 }
119
120 // Implemented by each back-end, in its own way:
121 void init();
122 void cleanup();
123
124private:
125 Q_DISABLE_COPY_MOVE(QCollatorPrivate)
126};
127
128class QCollatorSortKeyPrivate : public QSharedData
129{
130 friend class QCollator;
131public:
132 template <typename...T>
133 explicit QCollatorSortKeyPrivate(T &&...args)
134 : QSharedData()
135 , m_key(std::forward<T>(args)...)
136 {
137 }
138
139 CollatorKeyType m_key;
140
141private:
142 Q_DISABLE_COPY_MOVE(QCollatorSortKeyPrivate)
143};
144
145
146QT_END_NAMESPACE
147
148#endif // QCOLLATOR_P_H
149