-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1943 from daschuer/qcollator
Use QCollator for sort library.
- Loading branch information
Showing
5 changed files
with
34 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,29 @@ | ||
#ifndef MIXXX_STRING_H | ||
#define MIXXX_STRING_H | ||
|
||
#include <QLocale> | ||
#include <QCollator> | ||
#include <QString> | ||
#include <QStringRef> | ||
|
||
// The default comparison of strings for sorting. | ||
inline int compareLocaleAwareCaseInsensitive( | ||
const QString& first, const QString& second) { | ||
return QString::localeAwareCompare(first.toLower(), second.toLower()); | ||
} | ||
class StringCollator { | ||
public: | ||
explicit StringCollator(QLocale locale = QLocale()) | ||
: m_collator(std::move(locale)) { | ||
m_collator.setCaseSensitivity(Qt::CaseInsensitive); | ||
} | ||
|
||
int compare(const QString& s1, const QString& s2) const { | ||
return m_collator.compare(s1, s2); | ||
} | ||
|
||
int compare(const QStringRef& s1, const QStringRef& s2) const { | ||
return m_collator.compare(s1, s2); | ||
} | ||
|
||
private: | ||
QCollator m_collator; | ||
}; | ||
|
||
#endif // MIXXX_STRING_H |