Re: Sorting order for filenames



Ole Laursen wrote:

> ...
> Now, it turns out that the problem can be fixed by making a custom
> collate key generation function (instead of using g_utf8_collate_key).
> I've made one that fixes both the above problem with dots and also
> sorts numbers better, e.g. as
>
>   file1.txt   file2.txt   file10.txt
> The algorithm sorts files with small basenames before files with large
> basenames and small numbers before large ones. The cleanest solution
> seems to be to put the function in glib, but it was suggested in the
> above bug report that I asked here first for comments on the sorting
> algorithm.
> ...

Just to add some info, this ordering is called "natural order", and you can view an explanation and C implementation in
http://sourcefrog.net/projects/natsort/   (sourcefrog is not mispelled)

Personally, I have missed it in the "order by string_field" sql clause of mysql and others rdbms.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]