emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: case-insensitive string comparison


From: Sam Steingold
Subject: Re: case-insensitive string comparison
Date: Tue, 26 Jul 2022 10:16:08 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (darwin)

> * Eli Zaretskii <ryvm@tah.bet> [2022-07-26 16:05:50 +0300]:
>
>> From: Sam Steingold <sds@gnu.org>
>> Date: Mon, 25 Jul 2022 15:39:34 -0400
>> 
>> > * Eli Zaretskii <ryvm@tah.bet> [2022-07-25 18:58:19 +0300]:
>> >
>> >> > (string-collate-equalp "a" "A" current-locale-environment t)
>> >> > ==> nil
>> >> > current-locale-environment
>> >> > ==> "en_US.UTF-8"
>> >
>> > I cannot reproduce this:
>> >
>> >   (string-collate-equalp "a" "A" current-locale-environment t)
>> >     => t
>> >   current-locale-environment
>> >     => "en_US.UTF-8"
>> >
>> > What OS is this, and which Emacs version?
>> 
>> GNU Emacs 29.0.50 (build 5, x86_64-apple-darwin21.5.0, NS appkit-2113.50 
>> Version 12.4 (Build 21F79))
>>  of 2022-07-25
>> Repository revision: ffe12ff2503917e47c0356195b31430996c148f9
>> Repository branch: master
>> Windowing system distributor 'Apple', version 10.3.2113
>> System Description:  macOS 12.4
>
> Could be something macOS-specific.  Maybe your system doesn't define
> the __STDC_ISO_10646__ feature?  In that case, string-collate-equalp
> (see the doc string) behaves like string-equal, and that one doesn't
> have a case-insensitive variant.

How do I find out?
--8<---------------cut here---------------start------------->8---
echo  > .zzz.c;
gcc -E -dM .zzz.c | grep __STDC_ISO_10646__
--8<---------------cut here---------------end--------------->8---
does not print anything, but maybe I need to `#include' something?

> In general, locale-specific comparison is a bad idea in Emacs...
> For that reason, I suggest always using compare-strings instead.

Thank you very much for the clear and detailed explanation!

>> >> It is okay to add a `string-equal-ignore-case' based on `compare-strings'?
>> >> (even though it does not recognize "SS" and "ß" as equal)
>> >
>> > What's wrong with calling compare-strings directly?
>>
>> I want to be able to use `string-equal-ignore-case' as a :test argument
>> to things like `cl-find'.
>
> Then write a thin wrapper around compare-strings, and be done.

I think the need is sufficiently generic, e.g., BBDB provides such a
wrapper, as, I am sure, do many other packages.
Many core files can be simplified by using `string-equal-ignore-case'
(just like with the `string-prefix-p').

Thank again!

-- 
Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.2113
http://childpsy.net http://calmchildstories.com http://steingoldpsychology.com
https://www.dhimmitude.org https://thereligionofpeace.com
When you are arguing with an idiot, your opponent is doing the same.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]