Sort files in file browser properly

This commit is contained in:
Huntereb 2019-11-22 14:46:48 -05:00
parent 4ac0308063
commit 98a1d58a4d

View file

@ -50,6 +50,16 @@ namespace inst::util {
splExit();
}
struct caseInsensitiveLess : public std::binary_function< char,char,bool > {
bool operator () (char x, char y) const {
return toupper(static_cast< unsigned char >(x)) < toupper(static_cast< unsigned char >(y));
}
};
bool ignoreCaseCompare(const std::string &a, const std::string &b) {
return std::lexicographical_compare(a.begin(), a.end() , b.begin() ,b.end() , caseInsensitiveLess());
}
std::vector<std::filesystem::path> getDirectoryFiles(const std::string & dir, const std::vector<std::string> & extensions) {
std::vector<std::filesystem::path> files;
for(auto & p: std::filesystem::directory_iterator(dir))
@ -64,7 +74,7 @@ namespace inst::util {
}
}
}
std::sort(files.begin(), files.end());
std::sort(files.begin(), files.end(), ignoreCaseCompare);
return files;
}
@ -77,7 +87,7 @@ namespace inst::util {
files.push_back(p.path());
}
}
std::sort(files.begin(), files.end());
std::sort(files.begin(), files.end(), ignoreCaseCompare);
return files;
}