diff options
Diffstat (limited to 'src/corelib/tools/qstringlist.cpp')
-rw-r--r-- | src/corelib/tools/qstringlist.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
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); } |