From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>,
Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Surprising behaviour with numeric glob sort
Date: Mon, 5 Jun 2017 20:15:55 +0100 [thread overview]
Message-ID: <20170605191555.GB15325@chaz.gmail.com> (raw)
In-Reply-To: <20170605115439.GA15325@chaz.gmail.com>
2017-06-05 12:54:39 +0100, Stephane Chazelas:
[...]
> Having NUL sort before any other character would be preferable
> in the C locale that sorts by code point though (like to sort
> UTF-16 text based on codepoint).
[...]
Well, only for UTF-16BE. Given that UTF-16 is mostly used only
on Microsoft and as little endian, that would rarely be useful.
Still, it would be more consistent to have 0 < 1 < ... < 255
and would make sure the order is deterministic which is generally
expected of the C locale. It should be only a matter of calling
memcmp() when we detect the locale (LC_COLLATE) to be C or
POSIX.
GNU sort seems to be treating the NUL byte as the character that
sorts first and seems to be doing it using several calls to
strcoll() in non-C locales:
$ printf '%b\n' 'X\0\0A\0B' 'X\0\0A\0\0C' | ltrace -e strcoll sort
sort->strcoll("X", "X") = 0
sort->strcoll("", "") = 0
sort->strcoll("A", "A") = 0
sort->strcoll("B", "") = 1
XAC
XAB
(I'd say there's scope for optimisation there).
In the C locale, it just calls memcmp().
Cheers,
Stephane
next prev parent reply other threads:[~2017-06-05 19:16 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-31 21:24 Stephane Chazelas
2017-06-01 22:29 ` Bart Schaefer
2017-06-02 9:03 ` Stephane Chazelas
2017-06-02 23:19 ` Bart Schaefer
2017-06-03 21:16 ` Stephane Chazelas
2017-06-04 0:07 ` Bart Schaefer
2017-06-04 17:31 ` Stephane Chazelas
2017-06-04 22:01 ` Bart Schaefer
2017-06-05 11:54 ` Stephane Chazelas
2017-06-05 19:15 ` Stephane Chazelas [this message]
2017-06-06 3:13 ` Bart Schaefer
2017-06-06 9:22 ` Stephane Chazelas
2017-06-07 8:41 ` Stephane Chazelas
2017-06-17 18:11 ` Bart Schaefer
2017-06-06 14:44 ` Vincent Lefevre
2017-06-06 16:47 ` Stephane Chazelas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170605191555.GB15325@chaz.gmail.com \
--to=stephane.chazelas@gmail.com \
--cc=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).