forked from qt-creator/qt-creator
[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 lexicographically. Thus, the list: [item1, item10, item1b, item2] gets sorted as: [item1, item1b, item2, item10] Change-Id: I16a0106d9dc9bb27731f96c3f180ad20cd9a44f5 Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
This commit is contained in:
committed by
Leandro Melo
parent
ded2dd12b8
commit
0b12ed143e
@@ -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)
|
||||
continue;
|
||||
if (state != Letter) {
|
||||
if (!pa->isDigit() || !pb->isDigit())
|
||||
break;
|
||||
} else if (pa->isDigit() && pb->isDigit()) {
|
||||
if (charLessThan(*pa, *pb))
|
||||
state = SmallerNumber;
|
||||
else
|
||||
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
|
||||
|
Reference in New Issue
Block a user