Merge pull request #10731 from Chocobo1/backport

Backport to v4_1_x
This commit is contained in:
Mike Tzou 2019-06-01 10:07:23 +08:00 committed by GitHub
commit 24ff369f29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -97,18 +97,29 @@ namespace
}
else if (leftChar.isDigit() && rightChar.isDigit()) {
// Both are digits, compare the numbers
const auto consumeNumber = [](const QString &str, int &pos) -> int
const auto numberView = [](const QString &str, int &pos) -> QStringRef
{
const int start = pos;
while ((pos < str.size()) && str[pos].isDigit())
++pos;
return str.midRef(start, (pos - start)).toInt();
return str.midRef(start, (pos - start));
};
const int numL = consumeNumber(left, posL);
const int numR = consumeNumber(right, posR);
if (numL != numR)
return (numL - numR);
const QStringRef numViewL = numberView(left, posL);
const QStringRef numViewR = numberView(right, posR);
if (numViewL.length() != numViewR.length())
return (numViewL.length() - numViewR.length());
// both string/view has the same length
for (int i = 0; i < numViewL.length(); ++i) {
const QChar numL = numViewL.at(i);
const QChar numR = numViewR.at(i);
if (numL != numR)
return (numL.unicode() - numR.unicode());
}
// String + digits do match and we haven't hit the end of both strings
// then continue to consume the remainings