You probably know that Finder uses natural sort order rather than ASCII order, when sorting files by name. See:
How does finder sort folders when they contain digits and characters?
and particularly https://web.archive.org/web/20070821004601/http://docs.info.apple.com/article.html?artnum=300989
Recently, I was trying to reproduce the exact sorting behavior of Finder in some code. Punctuation and symbols come before letters and numbers, but I do not understand the ordering within the class of punctuation marks.
I found a blog post (original source here) where the ordering for some special characters was worked out. I did some experimenting to fill in the gaps in the table. The complete ordering (with ASCII values) appears to be as follows:
_ underscore 0x5f
- dash (hyphen) 0x2d
, comma 0x2c
; semicolon 0x3b
! exclamation point 0x21
? question mark 0x3f
. period 0x2e
' single quote 0x27
" double quote 0x22
( open parenthesis 0x28
) close parenthesis 0x29
[ open bracket 0x5b
] close bracket 0x5d
{ open brace 0x7b
} close brace 0x7d
@ at symbol 0x40
* asterisk 0x2a
/ forward slash 0x2f
\ backward slash 0x5c
& ampersand 0x26
# number sign 0x23
% percent sign 0x25
` backtick 0x60
^ caret 0x5e
+ plus sign 0x2b
< less than 0x3c
= equal sign 0x3d
> greater than 0x3e
| vertical bar 0x7c
~ tilde 0x7e
$ dollar sign 0x24
Can someone explain to me the logic behind this ordering?
LANG=en_US.UTF-8