Commit 0b12ed14 authored by Francois Ferrand's avatar Francois Ferrand Committed by Leandro Melo
Browse files

[CodeAssist] Logical sort of proposals.

Improve the sorting of proposals, so that "logical" sort is used: if there are
numeric parts in the strings, these are compared as numbers instead of purely

Thus, the list: [item1, item10, item1b, item2]
gets sorted as: [item1, item1b, item2, item10]

Change-Id: I16a0106d9dc9bb27731f96c3f180ad20cd9a44f5
Reviewed-by: default avatarLeandro Melo <>
parent ded2dd12
......@@ -74,7 +74,34 @@ struct ContentLessThan
bool lessThan(const QString &a, const QString &b)
return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), CharLessThan());
QString::const_iterator pa = a.begin();
QString::const_iterator pb = b.begin();
CharLessThan charLessThan;
enum { Letter, SmallerNumber, BiggerNumber } state = Letter;
for (; pa != a.end() && pb != b.end(); ++pa, ++pb) {
if (*pa == *pb)
if (state != Letter) {
if (!pa->isDigit() || !pb->isDigit())
} else if (pa->isDigit() && pb->isDigit()) {
if (charLessThan(*pa, *pb))
state = SmallerNumber;
state = BiggerNumber;
} else {
return charLessThan(*pa, *pb);
if (state == Letter)
return pa == a.end() && pb != b.end();
if (pa != a.end() && pa->isDigit())
return false; //more digits
if (pb != b.end() && pb->isDigit())
return true; //fewer digits
return state == SmallerNumber; //same length, compare first different digit in the sequence
struct CharLessThan
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment