diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2012-04-11 18:06:11 +0300 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-12 10:39:22 +0200 |
commit | 1035c93245ef299c2f29be5b119b736430e81dc3 (patch) | |
tree | baee9d1c9d1edf1ba8d73f60c7d88081e4301a73 /src/corelib/tools/qstringlist.cpp | |
parent | 3127f23e3aded5cd70440e401e0915f5d6112329 (diff) |
make QStringList::sort() to take a Qt::CaseSensitivity param
Task-number: QTBUG-12892
Change-Id: I402e6fb12ff24ac26c5a8103bf81547946f9cc58
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
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); } |