File indexing completed on 2024-05-12 16:06:33

0001 /*
0002     Natural order sorting of strings which contains numbers.
0003 
0004     SPDX-FileCopyrightText: 2007 Tobias Koenig <tokoe@kde.org>
0005     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
0006     based on the natural order code by Martin Pool <mbp sourcefrog net>
0007 */
0008 
0009 #ifndef QNATSORT_H
0010 #define QNATSORT_H
0011 
0012 #include <QString>
0013 
0014 /**
0015  * The two methods can be used in qSort to sort strings which contain
0016  * numbers in natural order.
0017  *
0018  * Normally strings are ordered like this: fam10g fam1g fam2g fam3g
0019  * natural ordered it would look like this: fam1g fam2g fam3g fam10g
0020  *
0021  * Code:
0022  *
0023  * QStringList list;
0024  * list << "fam10g" << "fam1g" << "fam2g" << "fam5g";
0025  *
0026  * qSort( list.begin(), list.end(), caseSensitiveNaturalOderLessThen );
0027  */
0028 
0029 /**
0030  * Returns whether the @p left string is lesser than the @p right string
0031  * in natural order.
0032  */
0033 bool caseSensitiveNaturalOrderLessThen(const QString &left, const QString &right);
0034 
0035 /**
0036  * Returns whether the @p left string is lesser than the @p right string
0037  * in natural order and case insensitive.
0038  */
0039 bool caseInsensitiveNaturalOrderLessThen(const QString &left, const QString &right);
0040 
0041 #endif