Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File list box doesn't sort items correctly #1363

Open
ldicker83 opened this issue May 17, 2023 · 2 comments
Open

File list box doesn't sort items correctly #1363

ldicker83 opened this issue May 17, 2023 · 2 comments

Comments

@ldicker83
Copy link
Collaborator

Seems the search function is case sensitive, counting upper case characters ahead of lowercase:

image

image

The only change between the above two images is I renamed 'researchtest' to 'Researchtest'

Correct behavior should sort alphanumerically without regard to case.

@ldicker83
Copy link
Collaborator Author

For additional reference, this is the correct sort in the Windows 10 file explorer

image

@DanRStevens
Copy link
Member

Internally the Filesystem code relies on std::filesystem::directory_iterator:
https://en.cppreference.com/w/cpp/filesystem/directory_iterator

The iteration order is unspecified, except that each directory entry is visited only once.

Many filesystems will store file info in sorted order, since there may be some lookup and update benefits to doing so. It's best not to rely on an assumption of filenames being already sorted, since there is no guarantee of it.


As for std::sort, you can specify a lambda as an optional third argument for the comparator:
https://en.cppreference.com/w/cpp/algorithm/sort

That can allow you do to a case insensitive sort.


The closest standard library function for string compare is strcmp:
https://en.cppreference.com/w/cpp/string/byte/strcmp

It seems stricmp (case insensitive string compare) is not part of the C++ standard, so is not supported by all compilers. Further, the meaning of case insensitive compare can be a bit ambiguous, depending on the language (think accented characters), or just not apply to languages that have no sense of case.

There are a few suggestions for writing string insensitive compare on Stack Overflow:
https://stackoverflow.com/questions/11635/case-insensitive-string-comparison-in-c


Of course, another option is to simply define the sort order as case sensitive. The way Windows does it is not necessarily "correct", just familiar. I think we would be perfectly justified if we wanted to impose a case sensitive sort here.

With that said, even on Linux, the file explorer and terminal listings show names sorted in a case insensitive manner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants