unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Roland Winkler <winkler@gnu.org>
Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org
Subject: Re: case-insensitive string comparison
Date: Wed, 20 Jul 2022 20:50:16 +0300	[thread overview]
Message-ID: <83fsivlllz.fsf@gnu.org> (raw)
In-Reply-To: <87lesnlm7a.fsf@gnu.org> (message from Roland Winkler on Wed, 20 Jul 2022 12:37:29 -0500)

> From: Roland Winkler <winkler@gnu.org>
> Cc: monnier@iro.umontreal.ca,  emacs-devel@gnu.org
> Date: Wed, 20 Jul 2022 12:37:29 -0500
> 
> > I hear you, but your request is impossible to fulfill in practice.
> > That's because the collation rules used by this function are
> > implemented in the C library, and even if we know the locale,
> > different implementations of libc use different collation rules (in
> > addition, collation rules for some locales change with time).
> 
> Even mentioning the difficulties could be useful here.

I'm not sure I agree.  To describe all the important aspects of this
would take too long, and it isn't the job of our manual to document
this stuff.  Read this if you want to know:

  https://unicode.org/reports/tr10/

> The elisp manual is used by people who want to develop code that
> works for a wide range of users.  So even if string comparison is a
> slippery terrain these elisp hackers need to make design choices
> that work best for most users.

Luckily, Emacs Lisp programs rarely need this.

> What usage scenarios in elisp packages might benefit from
> string-collate-equalp even if this function depends on details that can
> be quite different for different users?

For example, sorting file names.  If you want to get anything similar
to what GNU 'ls' does on GNU/Linux (in particular, with punctuation
characters in file names), you need to use the locale's collation
rules as implemented by glibc.  Which is what string-collate-lessp
does.

> >> - BBDB needs to know whether a name is already present in the database
> >>   or not, ignoring case.  The function bbdb-string= is again what Sam
> >>   suggests to put into subr.el.  The function string-collate-equalp
> >>   might be better suited for this.  But which locale should it use?  The
> >>   records in my BBDB cover larger parts of the world and I do not even
> >>   know which locale(s) might work best for each of them, not to mention
> >>   that BBDB needs to loop over all records.  Is there a "univeral
> >>   default locale"?
> >
> > That "universal default locale" is what Emacs uses, modulo the few
> > problematic characters like the dotless I etc.  For 100% predictable
> > results, build your own case table, bind the buffer's case table to
> > it, and then call case-insensitive comparison.
> 
> I am not sure I can follow your argument.  Do you suggest that, likely,
> BBDB will work best if it compares names using compare-strings?

Yes.  But in addition, you should set up the case table of the current
buffer when you do so, because otherwise special cases with the likes
of the Turkish language's dotless I could in rare cases screw you.

> (I'd be glad to hear that.)  This code should work for users who do not
> want to build their own case table and stuff like that.

Not the users should build the case table, BBDB (or whatever Lisp
program that needs the comparison) should.  It's not that hard,
really: if you only need ASCII, use ascii-case-table, otherwise copy
the standard case-table and modify it to make sure I downcases to i
and similarly with a few other exceptional letters.



  reply	other threads:[~2022-07-20 17:50 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-19 17:27 case-insensitive string comparison Sam Steingold
2022-07-19 18:06 ` Mattias Engdegård
2022-07-19 18:56   ` Sam Steingold
2022-07-20  4:39     ` tomas
2022-07-20 11:35       ` Eli Zaretskii
2022-07-20 13:30         ` tomas
2022-07-19 18:16 ` Stefan Kangas
2022-07-19 19:39 ` Roland Winkler
2022-07-19 22:47   ` Sam Steingold
2022-07-20  2:21     ` Roland Winkler
2022-07-20  3:01     ` Stefan Monnier
2022-07-20 16:22       ` Sam Steingold
2022-07-25 14:23         ` Sam Steingold
2022-07-25 15:58           ` Eli Zaretskii
2022-07-25 19:39             ` Sam Steingold
2022-07-26 13:05               ` Eli Zaretskii
2022-07-26 14:16                 ` Sam Steingold
2022-07-26 15:53                   ` Eli Zaretskii
2022-07-26 16:00                     ` Sam Steingold
2022-07-26 16:16                     ` Lars Ingebrigtsen
2022-07-26 14:43                 ` Robert Pluim
2022-07-25 19:37           ` Bruno Haible
2022-07-26  3:24           ` Richard Stallman
2022-07-26  8:00             ` Helmut Eller
2022-07-26 12:21               ` Eli Zaretskii
2022-07-27  2:58               ` Richard Stallman
2022-07-31  8:24                 ` Eli Zaretskii
2022-07-26 14:28             ` Sam Steingold
2022-07-26 15:42               ` Sam Steingold
2022-07-26 16:10               ` Eli Zaretskii
2022-07-26 18:56                 ` Bruno Haible
2022-07-26 19:30                   ` Eli Zaretskii
2022-07-20 16:24       ` Roland Winkler
2022-07-20 17:06         ` Sam Steingold
2022-07-20 17:16           ` Eli Zaretskii
2022-07-20 17:12         ` Eli Zaretskii
2022-07-20 17:37           ` Roland Winkler
2022-07-20 17:50             ` Eli Zaretskii [this message]
2022-07-20 18:10               ` Roland Winkler
2022-07-20 18:16                 ` Eli Zaretskii
2022-07-20 18:18                   ` [External] : " Drew Adams
2022-07-21  6:56                   ` Eli Zaretskii
2022-07-21 14:19                     ` Roland Winkler
2022-07-21 15:53                       ` Eli Zaretskii
2022-07-21 16:35                         ` Roland Winkler

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83fsivlllz.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=winkler@gnu.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.savannah.gnu.org/cgit/emacs.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).