Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcollator.h
Go to the documentation of this file.
1// Copyright (C) 2020 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_H
6#define QCOLLATOR_H
7
8#include <QtCore/qstring.h>
9#include <QtCore/qstringlist.h>
10#include <QtCore/qlocale.h>
11
13
16QT_DECLARE_QESDP_SPECIALIZATION_DTOR(QCollatorSortKeyPrivate)
17
18class Q_CORE_EXPORT QCollatorSortKey
19{
20 friend class QCollator;
21public:
22 QCollatorSortKey(const QCollatorSortKey &other);
23 QCollatorSortKey(QCollatorSortKey &&other) noexcept = default;
24 ~QCollatorSortKey();
25 QCollatorSortKey &operator=(const QCollatorSortKey &other);
26 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QCollatorSortKey)
27 void swap(QCollatorSortKey &other) noexcept
28 { d.swap(other.d); }
29
30 int compare(const QCollatorSortKey &key) const;
31 friend bool operator<(const QCollatorSortKey &lhs, const QCollatorSortKey &rhs)
32 { return lhs.compare(rhs) < 0; }
33
34protected:
35 QCollatorSortKey(QCollatorSortKeyPrivate*);
36
37 QExplicitlySharedDataPointer<QCollatorSortKeyPrivate> d;
38
39private:
40 QCollatorSortKey();
41};
42
43class Q_CORE_EXPORT QCollator
44{
45public:
46 QCollator();
47 explicit QCollator(const QLocale &locale);
48 QCollator(const QCollator &);
49 ~QCollator();
50 QCollator &operator=(const QCollator &);
51 QCollator(QCollator &&other) noexcept
52 : d(other.d) { other.d = nullptr; }
53 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QCollator)
54
55 void swap(QCollator &other) noexcept
56 { qt_ptr_swap(d, other.d); }
57
58 void setLocale(const QLocale &locale);
59 QLocale locale() const;
60
61 Qt::CaseSensitivity caseSensitivity() const;
62 void setCaseSensitivity(Qt::CaseSensitivity cs);
63
64 void setNumericMode(bool on);
65 bool numericMode() const;
66
67 void setIgnorePunctuation(bool on);
68 bool ignorePunctuation() const;
69
70 int compare(const QString &s1, const QString &s2) const
71 { return compare(QStringView(s1), QStringView(s2)); }
72#if QT_CORE_REMOVED_SINCE(6, 4) && QT_POINTER_SIZE != 4
73 int compare(const QChar *s1, int len1, const QChar *s2, int len2) const
74 { return compare(QStringView(s1, len1), QStringView(s2, len2)); }
75#endif
76 int compare(const QChar *s1, qsizetype len1, const QChar *s2, qsizetype len2) const
77 { return compare(QStringView(s1, len1), QStringView(s2, len2)); }
78
79 bool operator()(const QString &s1, const QString &s2) const
80 { return compare(s1, s2) < 0; }
81 int compare(QStringView s1, QStringView s2) const;
82
83 bool operator()(QStringView s1, QStringView s2) const
84 { return compare(s1, s2) < 0; }
85
86 QCollatorSortKey sortKey(const QString &string) const;
87
88 static int defaultCompare(QStringView s1, QStringView s2);
89 static QCollatorSortKey defaultSortKey(QStringView key);
90
91private:
92 QCollatorPrivate *d;
93
94 void detach();
95};
96
98Q_DECLARE_SHARED(QCollator)
99
100QT_END_NAMESPACE
101
102#endif // QCOLLATOR_P_H
The QAbstractFileEngineIterator class provides an iterator interface for custom file engines.
virtual ~QAbstractFileEnginePrivate()
QAbstractFileEnginePrivate(QAbstractFileEngine *q)
QAbstractFileEngine *const q_ptr
\inmodule QtCore \reentrant
\inmodule QtCore
Definition qcollator.h:19
\inmodule QtCore
Definition qcollator.h:44
bool operator()(const QDirSortItem &, const QDirSortItem &) const
Definition qdir.cpp:247
QDirSortItemComparator(QDir::SortFlags flags, QCollator *coll=nullptr)
Definition qdir.cpp:221
int compareStrings(const QString &a, const QString &b, Qt::CaseSensitivity cs) const
Definition qdir.cpp:237
\inmodule QtCore
\inmodule QtCore
Definition qhash.h:1170
const_iterator & operator++() noexcept
The prefix ++ operator ({++i}) advances the iterator to the next item in the hash and returns an iter...
Definition qhash.h:1195
const_iterator(const iterator &o) noexcept
Constructs a copy of other.
Definition qhash.h:1186
qptrdiff difference_type
Definition qhash.h:1180
constexpr const_iterator() noexcept=default
Constructs an uninitialized iterator.
const_iterator operator++(int) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qhash.h:1200
std::forward_iterator_tag iterator_category
Definition qhash.h:1179
const T * operator->() const noexcept
Returns a pointer to the current item's value.
Definition qhash.h:1191
const T & reference
Definition qhash.h:1183
bool operator==(const const_iterator &o) const noexcept
Returns true if other points to the same item as this iterator; otherwise returns false.
Definition qhash.h:1192
const T & value() const noexcept
Returns the current item's value.
Definition qhash.h:1189
const Key & key() const noexcept
Returns the current item's key.
Definition qhash.h:1188
const T * pointer
Definition qhash.h:1182
bool operator!=(const const_iterator &o) const noexcept
Returns true if other points to a different item than this iterator; otherwise returns false.
Definition qhash.h:1193
const T & operator*() const noexcept
Returns the current item's value.
Definition qhash.h:1190
\inmodule QtCore
Definition qhash.h:1210
key_iterator & operator++() noexcept
The prefix ++ operator ({++i}) advances the iterator to the next item in the hash and returns an iter...
Definition qhash.h:1228
key_iterator() noexcept=default
bool operator!=(key_iterator o) const noexcept
Returns true if other points to a different item than this iterator; otherwise returns false.
Definition qhash.h:1226
key_iterator operator++(int) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qhash.h:1229
qptrdiff difference_type
Definition qhash.h:1215
const_iterator::iterator_category iterator_category
Definition qhash.h:1214
const Key & operator*() const noexcept
Returns the current item's key.
Definition qhash.h:1223
const Key * operator->() const noexcept
Returns a pointer to the current item's key.
Definition qhash.h:1224
const Key * pointer
Definition qhash.h:1217
key_iterator(const_iterator o) noexcept
Definition qhash.h:1221
bool operator==(key_iterator o) const noexcept
Returns true if other points to the same item as this iterator; otherwise returns false.
Definition qhash.h:1225
const Key & reference
Definition qhash.h:1218
const_iterator base() const noexcept
Returns the underlying const_iterator this key_iterator is based on.
Definition qhash.h:1230
\inmodule QtCore
Definition qhash.h:821
QKeyValueIterator< const Key &, T &, iterator > key_value_iterator
\inmodule QtCore
Definition qhash.h:1234
QHash & operator=(const QHash &other) noexcept(std::is_nothrow_destructible< Node >::value)
Assigns other to this hash and returns a reference to this hash.
Definition qhash.h:861
T & operator[](const K &key)
Definition qhash.h:1432
key_iterator keyEnd() const noexcept
Definition qhash.h:1246
const T operator[](const K &key) const noexcept
Definition qhash.h:1437
T take(const K &key)
Definition qhash.h:1401
std::pair< const_iterator, const_iterator > equal_range(const Key &key) const noexcept
Definition qhash.h:1276
float load_factor() const noexcept
Returns the current load factor of the QHash's internal hash table.
Definition qhash.h:1369
const_iterator constFind(const Key &key) const noexcept
Definition qhash.h:1324
~QHash()
Destroys the hash.
Definition qhash.h:852
QKeyValueIterator< const Key &, const T &, const_iterator > const_key_value_iterator
\inmodule QtCore
Definition qhash.h:1233
iterator erase(const_iterator it)
Definition qhash.h:1258
iterator emplace(const Key &key, Args &&... args)
Definition qhash.h:1349
key_value_iterator keyValueBegin()
Definition qhash.h:1247
const_iterator constFind(const K &key) const noexcept
Definition qhash.h:1464
T value(const K &key, const T &defaultValue) const noexcept
Definition qhash.h:1424
QHash(const QHash &other) noexcept
Constructs a copy of other.
Definition qhash.h:846
auto asKeyValueRange() const &&
Definition qhash.h:1256
iterator emplace(Key &&key, Args &&... args)
Inserts a new element into the container.
Definition qhash.h:1356
friend bool comparesEqual(const QHash &lhs, const QHash &rhs) noexcept
Definition qhash.h:917
const_key_value_iterator constKeyValueEnd() const noexcept
Definition qhash.h:1252
bool empty() const noexcept
This function is provided for STL compatibility.
Definition qhash.h:1374
const_iterator cbegin() const noexcept
Definition qhash.h:1239
iterator begin()
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
Definition qhash.h:1237
void insert(const QHash &hash)
Definition qhash.h:1333
const_iterator find(const Key &key) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qhash.h:1320
static float max_load_factor() noexcept
Definition qhash.h:1370
auto asKeyValueRange() &
Definition qhash.h:1253
const_key_value_iterator keyValueBegin() const noexcept
Definition qhash.h:1249
key_value_iterator keyValueEnd()
Definition qhash.h:1248
const_iterator end() const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qhash.h:1242
iterator find(const K &key)
Definition qhash.h:1454
const_key_value_iterator constKeyValueBegin() const noexcept
Definition qhash.h:1250
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition qhash.h:1328
qsizetype count(const K &key) const
Definition qhash.h:1411
std::pair< iterator, iterator > equal_range(const K &key)
Definition qhash.h:1443
key_iterator keyBegin() const noexcept
Definition qhash.h:1245
bool contains(const K &key) const
Definition qhash.h:1406
std::pair< const_iterator, const_iterator > equal_range(const K &key) const noexcept
Definition qhash.h:1449
iterator Iterator
Qt-style synonym for QHash::iterator.
Definition qhash.h:1313
size_t bucket_count() const noexcept
Definition qhash.h:1371
auto asKeyValueRange() &&
Definition qhash.h:1255
const_iterator ConstIterator
Qt-style synonym for QHash::const_iterator.
Definition qhash.h:1314
auto asKeyValueRange() const &
Definition qhash.h:1254
const_iterator constBegin() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
Definition qhash.h:1240
qsizetype count() const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qhash.h:1315
QHash(std::initializer_list< std::pair< Key, T > > list)
Definition qhash.h:840
T value(const K &key) const noexcept
Definition qhash.h:1416
const_iterator find(const K &key) const noexcept
Definition qhash.h:1459
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition qhash.h:1316
iterator end() noexcept
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last ...
Definition qhash.h:1241
QHash(QHash &&other) noexcept
Move-constructs a QHash instance, making it point at the same object that other was pointing to.
Definition qhash.h:874
std::pair< iterator, iterator > equal_range(const Key &key)
Definition qhash.h:1272
const_iterator cend() const noexcept
Definition qhash.h:1243
static size_t max_bucket_count() noexcept
Definition qhash.h:1372
bool remove(const K &key)
Definition qhash.h:1396
QHash() noexcept=default
Constructs an empty hash.
const_key_value_iterator keyValueEnd() const noexcept
Definition qhash.h:1251
const_iterator begin() const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qhash.h:1238
const_iterator constEnd() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the ...
Definition qhash.h:1244
\inmodule QtCore
Definition qmutex.h:313
constexpr size_t bucketForHash(size_t nBuckets, size_t hash) noexcept
Definition qhash.h:438
constexpr size_t bucketsForCapacity(size_t requestedCapacity) noexcept
Definition qhash.h:418
constexpr bool isRelocatable()
Definition qhash.h:217
constexpr bool HasStdHashSpecializationWithoutSeed
Definition qhash.h:47
size_t calculateHash(const T &t, size_t seed=0)
Definition qhash.h:55
constexpr bool HasQHashOverload
Definition qhash.h:31
constexpr bool HasStdHashSpecializationWithSeed
Definition qhash.h:39
Combined button and popup list for selecting options.
std::unique_ptr< QAbstractFileEngine > qt_custom_file_engine_handler_create(const QString &path)
static qsizetype rootLength(QStringView name, bool allowUncPaths)
Definition qdir.cpp:61
@ OSSupportsUncPaths
Definition qdir.cpp:56
static bool qt_cleanPath(QString *path)
Definition qdir.cpp:2380
QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2464
QDebug operator<<(QDebug debug, const QDir &dir)
Definition qdir.cpp:2516
static QDebug operator<<(QDebug debug, QDir::SortFlags sorting)
Definition qdir.cpp:2492
bool comparesEqual(const QDir &lhs, const QDir &rhs)
Definition qdir.cpp:1819
static bool treatAsAbsolute(const QString &path)
Definition qdir.cpp:756
bool qt_normalizePathSegments(QString *path, QDirPrivate::PathNormalizations flags)
Definition qdir.cpp:2224
Q_AUTOTEST_EXPORT bool qt_normalizePathSegments(QString *path, QDirPrivate::PathNormalizations flags)
Definition qdir.cpp:2224
bool qIsFilenameBroken(const QFileSystemEntry &entry)
bool qIsFilenameBroken(const QString &name)
#define Q_RETURN_ON_INVALID_FILENAME(message, result)
bool qIsFilenameBroken(const QByteArray &name)
qsizetype erase_if(QMultiHash< Key, T > &hash, Predicate pred)
Definition qhash.h:2562
size_t qHash(const QMultiHash< Key, T > &key, size_t seed=0) noexcept(noexcept(qHash(std::declval< Key & >())) &&noexcept(qHash(std::declval< T & >())))
Definition qhash.h:2542
qsizetype erase_if(QHash< Key, T > &hash, Predicate pred)
Definition qhash.h:2556
QFileInfo item
Definition qdir.cpp:209
QString suffix_cache
Definition qdir.cpp:208
QDirSortItem(const QFileInfo &fi, QDir::SortFlags sort)
Definition qdir.cpp:197
QDirSortItem()=default
QString filename_cache
Definition qdir.cpp:207
friend bool operator==(Bucket lhs, Bucket rhs) noexcept
Definition qhash.h:516
size_t offset() const noexcept
Definition qhash.h:498
bool isUnused() const noexcept
Definition qhash.h:494
Bucket(const Data *d, size_t bucket) noexcept
Definition qhash.h:473
Bucket(Span *s, size_t i) noexcept
Definition qhash.h:470
Node * insert() const
Definition qhash.h:510
void advance(const Data *d) noexcept
Definition qhash.h:490
Node & nodeAtOffset(size_t offset)
Definition qhash.h:502
iterator toIterator(const Data *d) const noexcept
Definition qhash.h:485
friend bool operator!=(Bucket lhs, Bucket rhs) noexcept
Definition qhash.h:520
void advanceWrapped(const Data *d) noexcept
Definition qhash.h:486
Bucket(iterator it) noexcept
Definition qhash.h:477
size_t toBucketIndex(const Data *d) const noexcept
Definition qhash.h:481
void reallocationHelper(const Data &other, size_t nSpans, bool resized)
Definition qhash.h:561
iterator begin() const noexcept
Definition qhash.h:623
size_t nextBucket(size_t bucket) const noexcept
Definition qhash.h:664
InsertionResult findOrInsert(const K &key) noexcept
Definition qhash.h:717
Node * findNode(const K &key) const noexcept
Definition qhash.h:703
static Data * detached(Data *d)
Definition qhash.h:591
iterator detachedIterator(iterator other) const noexcept
Definition qhash.h:618
constexpr iterator end() const noexcept
Definition qhash.h:631
bool shouldGrow() const noexcept
Definition qhash.h:676
void rehash(size_t sizeHint=0)
Definition qhash.h:636
void erase(Bucket bucket) noexcept(std::is_nothrow_destructible< Node >::value)
Definition qhash.h:736
QtPrivate::RefCount ref
Definition qhash.h:455
static Data * detached(Data *d, size_t size)
Definition qhash.h:600
float loadFactor() const noexcept
Definition qhash.h:672
Data(size_t reserve=0)
Definition qhash.h:554
static auto allocateSpans(size_t numBuckets)
Definition qhash.h:535
Data(const Data &other, size_t reserved)
Definition qhash.h:583
Data(const Data &other)
Definition qhash.h:577
static constexpr size_t maxNumBuckets() noexcept
Definition qhash.h:461
Bucket findBucket(const K &key) const noexcept
Definition qhash.h:681
size_t numBuckets
Definition qhash.h:457
qsizetype free() noexcept(std::is_nothrow_destructible_v< T >)
Definition qhash.h:124
bool contains(const T &val) const noexcept
Definition qhash.h:136
MultiNodeChain * next
Definition qhash.h:120
static qsizetype freeChain(MultiNode *n) noexcept(std::is_nothrow_destructible_v< T >)
Definition qhash.h:197
MultiNode(MultiNode &&other)
Definition qhash.h:174
void insertMulti(Args &&... args)
Definition qhash.h:204
MultiNode(const MultiNode &other)
Definition qhash.h:180
static void createInPlace(MultiNode *n, const Key &k, Args &&... args)
Definition qhash.h:162
MultiNode(const Key &k, Chain *c)
Definition qhash.h:165
static void createInPlace(MultiNode *n, Key &&k, Args &&... args)
Definition qhash.h:159
MultiNode(Key &&k, Chain *c) noexcept(std::is_nothrow_move_assignable_v< Key >)
Definition qhash.h:169
void emplaceValue(Args &&... args)
Definition qhash.h:210
static void createInPlace(Node *n, const Key &k, Args &&...)
Definition qhash.h:106
bool valuesEqual(const Node *) const
Definition qhash.h:113
static void createInPlace(Node *n, Key &&k, Args &&...)
Definition qhash.h:103
void emplaceValue(Args &&... args)
Definition qhash.h:85
bool valuesEqual(const Node *other) const
Definition qhash.h:93
static void createInPlace(Node *n, const Key &k, Args &&... args)
Definition qhash.h:82
static void createInPlace(Node *n, Key &&k, Args &&... args)
Definition qhash.h:79
T && takeValue() noexcept(std::is_nothrow_move_assignable_v< T >)
Definition qhash.h:89
static constexpr size_t SpanShift
Definition qhash.h:223
static constexpr size_t LocalBucketMask
Definition qhash.h:225
static constexpr size_t UnusedEntry
Definition qhash.h:226
static constexpr size_t NEntries
Definition qhash.h:224
unsigned char & nextFree()
Definition qhash.h:250
unsigned char data[sizeof(Node)]
Definition qhash.h:248
const Node & at(size_t i) const noexcept
Definition qhash.h:318
void moveLocal(size_t from, size_t to) noexcept
Definition qhash.h:337
void addStorage()
Definition qhash.h:371
void freeData() noexcept(std::is_nothrow_destructible< Node >::value)
Definition qhash.h:266
void erase(size_t bucket) noexcept(std::is_nothrow_destructible< Node >::value)
Definition qhash.h:291
unsigned char nextFree
Definition qhash.h:257
Span() noexcept
Definition qhash.h:258
unsigned char allocated
Definition qhash.h:256
unsigned char offsets[SpanConstants::NEntries]
Definition qhash.h:254
Entry * entries
Definition qhash.h:255
Node & atOffset(size_t o) noexcept
Definition qhash.h:325
size_t offset(size_t i) const noexcept
Definition qhash.h:303
Node * insert(size_t i)
Definition qhash.h:279
bool hasNode(size_t i) const noexcept
Definition qhash.h:307
void moveFromSpan(Span &fromSpan, size_t fromIndex, size_t to) noexcept(std::is_nothrow_move_constructible_v< Node >)
Definition qhash.h:344
const Node & atOffset(size_t o) const noexcept
Definition qhash.h:331
Node & at(size_t i) noexcept
Definition qhash.h:311
Node * node() const noexcept
Definition qhash.h:788
size_t span() const noexcept
Definition qhash.h:784
iterator operator++() noexcept
Definition qhash.h:795
size_t index() const noexcept
Definition qhash.h:785
const Data< Node > * d
Definition qhash.h:781
bool isUnused() const noexcept
Definition qhash.h:786
bool operator!=(iterator other) const noexcept
Definition qhash.h:811
bool atEnd() const noexcept
Definition qhash.h:793
bool operator==(iterator other) const noexcept
Definition qhash.h:809