Recently I found out you cannot just simply sort file names with std.ascii.lessThanIgnoreCase
. One would expect a natural sort order.
That means instead of
a11
a2
you get
a2
a11
I didn’t find any Zig implementations, so here’s a port of the C implementation in Zig https://codeberg.org/knightpp/natural-ordering-zig.
But there’s room for improvement! I directly ported C code, but in C – strings end with \0
. Maybe it’s possible to rewrite it a bit to be aware of string lengths? Also, there are no benchmarks currently.