MCPcopy Create free account
hub / github.com/KDE/kdiff3 / calcHistorySortKey

Function calcHistorySortKey

src/mergeresultwindow.cpp:965–1014  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

963}
964
965QString calcHistorySortKey(const QString& keyOrder, QRegularExpressionMatch& regExprMatch, const QStringList& parenthesesGroupList)
966{
967 const QStringList keyOrderList = keyOrder.split(',');
968 QString key;
969
970 for(const QString& keyIt : keyOrderList)
971 {
972 if(keyIt.isEmpty())
973 continue;
974 bool bOk = false;
975 qint32 groupIdx = keyIt.toInt(&bOk);
976 if(!bOk || groupIdx < 0 || groupIdx > parenthesesGroupList.size())
977 continue;
978 QString s = regExprMatch.captured(groupIdx);
979 if(groupIdx == 0)
980 {
981 key += s + ' ';
982 continue;
983 }
984
985 QString groupRegExp = parenthesesGroupList[groupIdx - 1];
986 if(groupRegExp.indexOf('|') < 0 || groupRegExp.indexOf('(') >= 0)
987 {
988 bOk = false;
989 qint32 i = s.toInt(&bOk);
990 if(bOk && i >= 0 && i < 10000)
991 {
992 s += QString(4 - s.size(), '0'); // This should help for correct sorting of numbers.
993 }
994 key += s + ' ';
995 }
996 else
997 {
998 // Assume that the groupRegExp consists of something like "Jan|Feb|Mar|Apr"
999 // s is the string that managed to match.
1000 // Now we want to know at which position it occurred. e.g. Jan=0, Feb=1, Mar=2, etc.
1001 QStringList sl = groupRegExp.split('|');
1002 qsizetype idx = sl.indexOf(s);
1003 if(idx >= 0)
1004 {
1005 QString sIdx;
1006 sIdx.setNum(idx);
1007 assert(sIdx.size() <= 2);
1008 sIdx += QString(2 - sIdx.size(), '0'); // Up to 99 words in the groupRegExp (more than 12 aren't expected)
1009 key += sIdx + ' ';
1010 }
1011 }
1012 }
1013 return key;
1014}
1015
1016void MergeResultWindow::collectHistoryInformation(
1017 e_SrcSelector src, const HistoryRange& historyRange,

Callers 2

slotRecalcMethod · 0.85

Calls 3

splitMethod · 0.80
isEmptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected