GNU bug report logs -
#59275
Unexpected return value of `string-collate-lessp' on Mac
Previous Next
Full log
View this message in rfc822 format
Eli Zaretskii <eliz <at> gnu.org> writes:
>> > string-collate-lessp is inherently platform- (and locale-) dependent.
>> > Don't use it if you want consistent results across platforms and
>> > locales.
>>
>> Is there a better alternative?
>
> Alternative to do what job?
Reliable sorting.
In particular, I am looking for a better PREDICATE argument for
`sort-subr' for case-sensitive and case-insensitive sorting of strings.
>> Also, do I miss something, or is this pitfall not documented in the
>> docstring of `string-collate-lessp'?
>
> It isn't? then what is this about:
>
> This function obeys the conventions for collation order in your
> locale settings. For example, punctuation and whitespace characters
> might be considered less significant for sorting:
>
> (sort '("11" "12" "1 1" "1 2" "1.1" "1.2") 'string-collate-lessp)
> => ("11" "1 1" "1.1" "12" "1 2" "1.2")
> [...]
> To emulate Unicode-compliant collation on MS-Windows systems,
> bind ‘w32-collate-ignore-punctuation’ to a non-nil value, since
> the codeset part of the locale cannot be "UTF-8" on MS-Windows.
The above sounds like we just need to worry about some edge cases where
different approaches may exist to sorting. Like with punctuation,
numbers, and spaces.
Having
(string-collate-lessp "a" "B" "C" t) ; => nil
is totally unexpected because case-insensitive "a"<"B"<"C" sounds like
the only reasonable outcome.
I'd like the warning to be even more prominent.
Feel free to disagree.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
This bug report was last modified 2 years and 176 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.