![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\inmodule QtCore More...
#include <qcollator.h>
Public Types | |
| enum class | CollationOption { CaseInsensitive = 0x1 , IgnorePunctuation = 0x2 , NumericSort = 0x4 , DiacriticInsensitive = 0x8 } |
Public Member Functions | |
| QCollator () | |
| QCollator (const QLocale &locale) | |
| Constructs a QCollator using the given locale. | |
| QCollator (const QCollator &) | |
| Creates a copy of other. | |
| ~QCollator () | |
| Destroys this collator. | |
| QCollator & | operator= (const QCollator &) |
| Assigns other to this collator. | |
| QCollator (QCollator &&other) noexcept | |
| void | swap (QCollator &other) noexcept |
| \memberswap{collator} | |
| void | setLocale (const QLocale &locale) |
| Sets the locale of the collator to locale. | |
| QLocale | locale () const |
| Returns the locale of the collator. | |
| Qt::CaseSensitivity | caseSensitivity () const |
| Returns case sensitivity of the collator. | |
| void | setCaseSensitivity (Qt::CaseSensitivity cs) |
| Sets the case-sensitivity of the collator to cs. | |
| void | setNumericMode (bool on) |
Enables numeric sorting mode when on is true. | |
| bool | numericMode () const |
Returns true if numeric sorting is enabled, false otherwise. | |
| void | setIgnorePunctuation (bool on) |
Ignores punctuation and symbols if on is true, attends to them if false. | |
| bool | ignorePunctuation () const |
| Returns whether punctuation and symbols are ignored when collating. | |
| void | setOptions (CollationOptions options) |
| CollationOptions | options () const |
| int | compare (const QString &s1, const QString &s2) const |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| int | compare (const QChar *s1, qsizetype len1, const QChar *s2, qsizetype len2) const |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| bool | operator() (const QString &s1, const QString &s2) const |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| int | compare (QStringView s1, QStringView s2) const |
| bool | operator() (QStringView s1, QStringView s2) const |
| QCollatorSortKey | sortKey (const QString &string) const |
| Returns a sortKey for string. | |
Static Public Member Functions | |
| static int | defaultCompare (QStringView s1, QStringView s2) |
| static QCollatorSortKey | defaultSortKey (QStringView key) |
Friends | |
| Q_CORE_EXPORT bool | comparesEqual (const QCollator &lhs, const QCollator &rhs) |
\inmodule QtCore
The QCollator class compares strings according to a localized collation algorithm. \compares equality
\reentrant
QCollator is initialized with a QLocale. It can then be used to compare and sort strings by using the ordering appropriate for that locale.
A QCollator object can be used together with template-based sorting algorithms, such as std::sort(), to sort a list with QString entries.
In addition to the locale, several optional flags can be set that influence the result of the collation.
Definition at line 48 of file qcollator.h.
|
strong |
Options that control how strings are compared by \l QCollator.
The \macos, Windows, and ICU backends support all options, with variations where indicated. On non-\macos Unix (including Linux), if ICU is not available a fallback (POSIX) backend is used, which supports none of these options.
\value CaseInsensitive Ignore case differences when comparing strings.
\value IgnorePunctuation Ignore punctuation and symbols when comparing strings.
\value NumericSort Sort strings containing numbers by their numeric value, so that for example "file10" sorts after "file9" instead of between "file1" and "file2".
\value DiacriticInsensitive Ignore diacritical marks when comparing strings, so that for example "e" and "é" compare as equal. Depending on the locale, this may also include ligature folding such as æ == ae. See \l {DiacriticInsensitive behavior details} below.
| Enumerator | |
|---|---|
| CaseInsensitive | |
| IgnorePunctuation | |
| NumericSort | |
| DiacriticInsensitive | |
Definition at line 51 of file qcollator.h.
| QCollator::QCollator | ( | ) |
Constructs a QCollator using the default locale's collation locale.
The system locale, when used as default locale, may have a collation locale other than itself (e.g. on Unix, if LC_COLLATE is set differently to LANG in the environment). All other locales are their own collation locales.
Definition at line 155 of file qcollator.cpp.
|
explicit |
Constructs a QCollator using the given locale.
Definition at line 165 of file qcollator.cpp.
| QCollator::QCollator | ( | const QCollator & | other | ) |
Creates a copy of other.
Definition at line 173 of file qcollator.cpp.
| QCollator::~QCollator | ( | ) |
Destroys this collator.
Definition at line 186 of file qcollator.cpp.
|
inlinenoexcept |
Definition at line 64 of file qcollator.h.
| Qt::CaseSensitivity QCollator::caseSensitivity | ( | ) | const |
Returns case sensitivity of the collator.
This defaults to case-sensitive until set.
Definition at line 326 of file qcollator.cpp.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Compares s1 with s2. len1 and len2 specify the lengths of the QChar arrays pointed to by s1 and s2.
Returns a negative integer if s1 is less than s2, a positive integer if it is greater than s2, and zero if they are equal.
{int}, not {qsizetype}. Definition at line 92 of file qcollator.h.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 86 of file qcollator.h.
| int QCollator::compare | ( | QStringView | s1, |
| QStringView | s2 ) const |
Compares s1 with s2.
Returns a negative integer if s1 is less than s2, a positive integer if it is greater than s2, and zero if they are equal.
Definition at line 95 of file qcollator_icu.cpp.
|
static |
Compares the strings s1 and s2, returning their sorting order. This function performs the same operation as compare() on a default-constructed QCollator object.
Definition at line 474 of file qcollator.cpp.
|
static |
Returns the sort key for the string key. This function performs the same operation as sortKey() on a default-constructed QCollator object.
Definition at line 487 of file qcollator.cpp.
| bool QCollator::ignorePunctuation | ( | ) | const |
Returns whether punctuation and symbols are ignored when collating.
When true, strings are compared as if all punctuation and symbols were removed from each string.
Definition at line 383 of file qcollator.cpp.
| QLocale QCollator::locale | ( | ) | const |
Returns the locale of the collator.
Unless supplied to the constructor or by calling setLocale(), the system's default collation locale is used.
Definition at line 295 of file qcollator.cpp.
| bool QCollator::numericMode | ( | ) | const |
Returns true if numeric sorting is enabled, false otherwise.
When true, numerals are recognized as numbers and sorted in arithmetic order; for example, 100 sortes after 99. When false, numbers are sorted in lexical order, so that 100 sorts before 99 (because 1 is before 9). By default, this option is disabled.
Definition at line 356 of file qcollator.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 95 of file qcollator.h.
|
inline |
A QCollator can be used as the comparison function of a sorting algorithm. It returns true if s1 sorts before s2, otherwise false.
Definition at line 99 of file qcollator.h.
Assigns other to this collator.
Move-assigns other to this QCollator instance.
\fn QCollator::QCollator(QCollator &&other) Move constructor. Moves from \a other into this collator.
! [partially-formed]
partially-formed
Definition at line 195 of file qcollator.cpp.
| QCollator::CollationOptions QCollator::options | ( | ) | const |
Definition at line 412 of file qcollator.cpp.
Referenced by testing.tools.test_runner._TestCaseRunner::_NewImageArtifact(), testing.tools.test_runner._TestCaseRunner::_RegenerateIfNeeded(), testing.tools.test_runner.TestRunner::IsSkiaGoldEnabled(), testing.tools.test_runner._TestCaseRunner::TestPixel(), and testing.tools.test_runner._TestCaseRunner::TestText().
| void QCollator::setCaseSensitivity | ( | Qt::CaseSensitivity | cs | ) |
Sets the case-sensitivity of the collator to cs.
Definition at line 305 of file qcollator.cpp.
| void QCollator::setIgnorePunctuation | ( | bool | on | ) |
Ignores punctuation and symbols if on is true, attends to them if false.
Definition at line 366 of file qcollator.cpp.
Sets the locale of the collator to locale.
Definition at line 278 of file qcollator.cpp.
| void QCollator::setNumericMode | ( | bool | on | ) |
Enables numeric sorting mode when on is true.
Definition at line 337 of file qcollator.cpp.
| void QCollator::setOptions | ( | CollationOptions | options | ) |
Definition at line 398 of file qcollator.cpp.
| QCollatorSortKey QCollator::sortKey | ( | const QString & | string | ) | const |
Returns a sortKey for string.
Creating the sort key is usually somewhat slower, than using the compare() methods directly. But if the string is compared repeatedly (e.g. when sorting a whole list of strings), it's usually faster to create the sort keys for each string and then sort using the keys.
Definition at line 117 of file qcollator_icu.cpp.
\memberswap{collator}
Definition at line 68 of file qcollator.h.
Definition at line 244 of file qcollator.cpp.