reintroduced epub support
This commit is contained in:
49 files changed
+5048
-205
No files matched your search
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <QBuffer>
|
||||
#include <QCollator>
|
||||
#include <QFileInfo>
|
||||
#include <QImageReader>
|
||||
#include <QXmlStreamReader>
|
||||
@@ -55,17 +54,68 @@ static void parseComicInfo(const QByteArray &data,
|
||||
outAuthor = writer;
|
||||
}
|
||||
|
||||
static int naturalCompare(QStringView a, QStringView b)
|
||||
{
|
||||
int i = 0, j = 0;
|
||||
const int lenA = a.size();
|
||||
const int lenB = b.size();
|
||||
|
||||
while (i < lenA && j < lenB) {
|
||||
const QChar ca = a[i];
|
||||
const QChar cb = b[j];
|
||||
|
||||
if (ca.isDigit() && cb.isDigit()) {
|
||||
const int startA = i;
|
||||
while (i < lenA && a[i] == QLatin1Char('0'))
|
||||
++i;
|
||||
const int startB = j;
|
||||
while (j < lenB && b[j] == QLatin1Char('0'))
|
||||
++j;
|
||||
|
||||
const int numStartA = i;
|
||||
while (i < lenA && a[i].isDigit())
|
||||
++i;
|
||||
const int numStartB = j;
|
||||
while (j < lenB && b[j].isDigit())
|
||||
++j;
|
||||
|
||||
const int numLenA = i - numStartA;
|
||||
const int numLenB = j - numStartB;
|
||||
|
||||
if (numLenA != numLenB)
|
||||
return (numLenA < numLenB) ? -1 : 1;
|
||||
|
||||
for (int kA = numStartA, kB = numStartB; kA < i; ++kA, ++kB) {
|
||||
if (a[kA] != b[kB])
|
||||
return (a[kA] < b[kB]) ? -1 : 1;
|
||||
}
|
||||
|
||||
const int zerosA = numStartA - startA;
|
||||
const int zerosB = numStartB - startB;
|
||||
if (zerosA != zerosB)
|
||||
return (zerosA < zerosB) ? -1 : 1;
|
||||
} else {
|
||||
const QChar la = ca.toLower();
|
||||
const QChar lb = cb.toLower();
|
||||
if (la != lb)
|
||||
return (la < lb) ? -1 : 1;
|
||||
++i;
|
||||
++j;
|
||||
}
|
||||
}
|
||||
|
||||
if (i < lenA) return 1;
|
||||
if (j < lenB) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void naturalSortEntries(QStringList &entries)
|
||||
{
|
||||
if (entries.size() <= 1)
|
||||
return;
|
||||
|
||||
QCollator collator{QLocale(QLocale::English)};
|
||||
collator.setNumericMode(true);
|
||||
collator.setCaseSensitivity(Qt::CaseInsensitive);
|
||||
|
||||
std::sort(entries.begin(), entries.end(), [&collator](const QString &a, const QString &b) {
|
||||
const int cmp = collator.compare(a, b);
|
||||
std::sort(entries.begin(), entries.end(), [](const QString &a, const QString &b) {
|
||||
const int cmp = naturalCompare(a, b);
|
||||
if (cmp != 0)
|
||||
return cmp < 0;
|
||||
return a < b;
|
||||
|
||||
Reference in new issue
Block a user