2
3
Fork
You've already forked ncsu
0

Use natsort when sorting by name #181

Closed
opened 2021年12月22日 11:29:58 +01:00 by cipri_tom · 1 comment
cipri_tom commented 2021年12月22日 11:29:58 +01:00 (Migrated from code.blicky.net)
Copy link

The name sorting is poorly suited for human consumption. Because many files have some number in them, they are not in the expected order. See attached for my example.

Here is a more detailed discussion about it: https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/

I realize it may not be obvious to implement in Zig/C, since not even unicode aware one seems to not be available out of the box.

If you are willing to use an existing implementation, I've found it here: https://github.com/sourcefrog/natsort (in C, very permissive licence).

As a fun Advent of Code, I am playing with Zig now to see if it would be simpler to do here. No High hopes, though ^^

Many thanks for an already awesome utility !

The name sorting is poorly suited for human consumption. Because many files have some number in them, they are not in the expected order. See attached for my example. Here is a more detailed discussion about it: https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/ I realize it may not be obvious to implement in Zig/C, since not even unicode aware one seems to not be available out of the box. If you are willing to use an existing implementation, I've found it here: https://github.com/sourcefrog/natsort (in C, very permissive licence). As a fun Advent of Code, I am playing with Zig now to see if it would be simpler to do here. No High hopes, though ^^ Many thanks for an already awesome utility !
yorhel commented 2021年12月22日 12:13:58 +01:00 (Migrated from code.blicky.net)
Copy link

Oh yeah, I'm totally in favor of using natsort. That C implementation doesn't look too large or complex, so I'll be happy to accept a PR for a Zig port if it doesn't perform too poorly.

Unicode-aware sorting is more of a challenge. Implementations of proper Unicode collation tend to not be small, so depending on an additional library doesn't seem like a great idea. Calling out to libc strcoll() or strxfrm() is a possibility, but I'm not sure to what extend libcs implement that or how they perform. I know glibc tends to do a good job based on the user's locale, while musl just calls strcmp(); no idea about others.

Either way, ASCII-only natsort would already be a good improvement.

Oh yeah, I'm totally in favor of using natsort. That C implementation doesn't look too large or complex, so I'll be happy to accept a PR for a Zig port if it doesn't perform too poorly. Unicode-aware sorting is more of a challenge. Implementations of proper Unicode collation tend to not be small, so depending on an additional library doesn't seem like a great idea. Calling out to libc `strcoll()` or `strxfrm()` is a possibility, but I'm not sure to what extend libcs implement that or how they perform. I know glibc tends to do a good job based on the user's locale, while musl just calls `strcmp()`; no idea about others. Either way, ASCII-only natsort would already be a good improvement.
Sign in to join this conversation.
No Branch/Tag specified
zig
zig0.16
master
zig-threaded
openat
chdir
clear
compll
v2.9.3
v2.9.2
v2.9.1
v2.9
v2.8.2
v2.8.1
v2.8
v1.22
v1.21
v2.7
v2.6
v2.5
v1.20
v2.4
v1.19
v2.3
v1.18.1
v2.2.2
v1.18
v2.2.1
v2.2
v1.17
v2.1.2
v2.1.1
v2.1
v2.0.1
v2.0
v2.0-beta3
v2.0-beta2
v2.0-beta1
v1.16
v1.15.1
v1.15
v1.14.2
v1.14.1
v1.14
v1.13
v1.12
v1.11
v1.10
v1.9
v1.8
v1.7
v1.6
v1.5
v1.4
v1.3
v1.2
v1.1
No labels
1.x
2.x
bug
feature
imported
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
selfisekai/ncsu#181
Reference in a new issue
selfisekai/ncsu
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?