From 1035c93245ef299c2f29be5b119b736430e81dc3 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Wed, 11 Apr 2012 18:06:11 +0300 Subject: make QStringList::sort() to take a Qt::CaseSensitivity param Task-number: QTBUG-12892 Change-Id: I402e6fb12ff24ac26c5a8103bf81547946f9cc58 Reviewed-by: Oswald Buddenhagen Reviewed-by: Lars Knoll --- src/corelib/tools/qstringlist.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/corelib/tools/qstringlist.cpp') diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/tools/qstringlist.cpp index 50e155db81..bfe2c5ec2d 100644 --- a/src/corelib/tools/qstringlist.cpp +++ b/src/corelib/tools/qstringlist.cpp @@ -213,9 +213,11 @@ QT_BEGIN_NAMESPACE */ /*! - \fn void QStringList::sort() + \fn void QStringList::sort(Qt::CaseSensitivity cs) - Sorts the list of strings in ascending order (case sensitively). + Sorts the list of strings in ascending order. + If \a cs is \l Qt::CaseSensitive (the default), the string comparison + is case sensitive; otherwise the comparison is case insensitive. Sorting is performed using Qt's qSort() algorithm, which operates in \l{linear-logarithmic time}, i.e. O(\e{n} log \e{n}). @@ -229,9 +231,18 @@ QT_BEGIN_NAMESPACE \sa qSort() */ -void QtPrivate::QStringList_sort(QStringList *that) + +static inline bool caseInsensitiveLessThan(const QString &s1, const QString &s2) +{ + return s1.compare(s2, Qt::CaseInsensitive) < 0; +} + +void QtPrivate::QStringList_sort(QStringList *that, Qt::CaseSensitivity cs) { - qSort(*that); + if (cs == Qt::CaseSensitive) + qSort(that->begin(), that->end()); + else + qSort(that->begin(), that->end(), caseInsensitiveLessThan); } -- cgit v1.2.3