Skip to content

Commit

Permalink
Issue 746: Replace natural ordering function in peakdetector with Qt-…
Browse files Browse the repository at this point in the history
…based approach.
  • Loading branch information
PMSeitzer committed Sep 12, 2024
1 parent d4d2c04 commit 9ae112f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/peakdetector/peakdetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1453,10 +1453,18 @@ void loadSamples(vector<string>&filenames) {
cout << "loadSamples() done: loaded " << samples.size() << " samples\n";

if (sampleIdMappingFile.empty()) {
//sort using natural sorting
sort(samples.begin(), samples.end(), [](const mzSample* lhs, const mzSample* rhs){
return strnatcmp(lhs->sampleName.c_str(), rhs->sampleName.c_str()) < 0;
});

// Issue 746: Enforce natural ordering
QCollator collator;
collator.setNumericMode(true);

sort(samples.begin(), samples.end(), [collator](mzSample* lhs, mzSample* rhs){

QString leftName = QString(lhs->sampleName.c_str());
QString rightName = QString(rhs->sampleName.c_str());

return collator.compare(leftName, rightName) < 0;
});

//ids match natural order
for (unsigned int i = 0; i < samples.size(); i++){
Expand Down

0 comments on commit 9ae112f

Please sign in to comment.