From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Sam Steingold Newsgroups: gmane.emacs.devel Subject: Re: case-insensitive string comparison Date: Mon, 25 Jul 2022 15:39:34 -0400 Message-ID: References: <87ilnsq4cr.fsf@gnu.org> <83o7xddw10.fsf@gnu.org> Reply-To: sds@gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30309"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (darwin) To: emacs-devel@gnu.org, Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Jul 25 21:41:55 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oG3xj-0007gp-Jj for ged-emacs-devel@m.gmane-mx.org; Mon, 25 Jul 2022 21:41:55 +0200 Original-Received: from localhost ([::1]:38156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oG3xi-0004dd-6q for ged-emacs-devel@m.gmane-mx.org; Mon, 25 Jul 2022 15:41:54 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33296) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oG3wP-0003AG-Mz for emacs-devel@gnu.org; Mon, 25 Jul 2022 15:40:33 -0400 Original-Received: from mail-qt1-x82b.google.com ([2607:f8b0:4864:20::82b]:35826) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oG3vg-00016f-04; Mon, 25 Jul 2022 15:40:32 -0400 Original-Received: by mail-qt1-x82b.google.com with SMTP id g24so9056440qtu.2; Mon, 25 Jul 2022 12:39:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:subject:in-reply-to:references:user-agent :return-receipt-to:reply-to:mail-followup-to:date:message-id :mime-version:content-transfer-encoding; bh=JUGdb9CPITk4qpdQZ+1i7GqOnuU9YE7PWvA7zUMVGkA=; b=AglK/DfBCkoxLWGERPe+H/gDGmhhPh05QGPZKCmb6ghN/i8Jfeyy5htgdJunR53lBz VpwYL0prfD9hUW+YilRvfTV96FBQNz3t8SQTlBzlW94dWrzT5tRSyy3ZbS28MDBMbOLg 2p9V0wyQHpECr1L+Ju5iFMbydcbEYnm3gq829kewLYkOG8/Kf+EqAefBluofbHrkL0Ji xYuimJ1MOD/ZcKQ/ON7CsyhJsnf1ogjmXqjm0+Y+sEpy9m3WFpRTZ908vPaYFbQrzsuT Z/aQunGp42zXpcwHLCQHQGaux90U2xP8OIx/5TcIfx+x2Mb7J0g80A4rf3D6Xhhu0Ev0 PAJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:subject:in-reply-to:references :user-agent:return-receipt-to:reply-to:mail-followup-to:date :message-id:mime-version:content-transfer-encoding; bh=JUGdb9CPITk4qpdQZ+1i7GqOnuU9YE7PWvA7zUMVGkA=; b=Aw/40Ki7FqUab3+LS4NDMEdTnKLx2wii3H1L/mb84y2pG0E3giokFUeunWMwfCYzs9 rkVMogi2u2wfCZBm0bA0Gl5YZGBfxd8YGNlbr2mvWplilK33y28HmXOzrZGEL78nmz90 Tfyjerl6sDiKHa/GbmdgkUUUK0IJNcXHn7q2DBSUm7owuxFoI+8a9e9FRE7t02N9cLEY 685bhOQvdF+7DWHSSfdPlduvsIqiuRKKznxaflW7RLUatef2rJeuUnBP9mMRlEZBDgBn Ayc7WdJDkpZHtHdOjFJl3L2O6f/pSFuqrvEzU/Mt6A9ZqJ36UAuGaVgDhAdgFk+sc5s7 uwog== X-Gm-Message-State: AJIora8PYZxvgWZsY2rOhY6htouzVRmAMBaLtqTkkmuWePhRYmOg1wUv txybVQaVgnxG6A/yDX0cs9QLjQMnIg== X-Google-Smtp-Source: AGRyM1sdo8fN8Aj0MpWHz+Kr1j3vGIRSjqq4yKJDmi7kZDrrzSic9CKehE0g/ebC/46BA9pd+Z0X6Q== X-Received: by 2002:a05:622a:1007:b0:31e:df91:e4b7 with SMTP id d7-20020a05622a100700b0031edf91e4b7mr11629838qte.683.1658777976610; Mon, 25 Jul 2022 12:39:36 -0700 (PDT) Original-Received: from 3c22fb11fdab.ant.amazon.com (pool-108-30-23-113.nycmny.fios.verizon.net. [108.30.23.113]) by smtp.gmail.com with ESMTPSA id cg14-20020a05622a408e00b0031eb65e1cb6sm7948529qtb.5.2022.07.25.12.39.35 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Jul 2022 12:39:35 -0700 (PDT) In-Reply-To: <83o7xddw10.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 25 Jul 2022 18:58:19 +0300") X-Attribution: Sam X-Disclaimer: You should not expect anyone to agree with me. Mail-Followup-To: emacs-devel@gnu.org, Eli Zaretskii Received-SPF: pass client-ip=2607:f8b0:4864:20::82b; envelope-from=sam.steingold@gmail.com; helo=mail-qt1-x82b.google.com X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:292650 Archived-At: > * Eli Zaretskii [2022-07-25 18:58:19 +0300]: > >> From: Sam Steingold >> Date: Mon, 25 Jul 2022 10:23:30 -0400 >>=20 >> >> Hmm... `string-collate-equalp`? >> > >> > (string-collate-equalp "a" "A" current-locale-environment t) >> > =3D=3D> nil >> > current-locale-environment >> > =3D=3D> "en_US.UTF-8" > > I cannot reproduce this: > > (string-collate-equalp "a" "A" current-locale-environment t) > =3D> t > current-locale-environment > =3D> "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 Ve= rsion 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 >> So, how do we do case-insensitive string comparison in Emacs? > > If you want locale-specific collation, as Stefan said, above. Do I? Is it really true that "UTF-8" without "en_US" does _not_ define case conve= rsion? but https://docs.python.org/3/library/stdtypes.html#str.casefold says >>>>> The casefolding algorithm is described in section 3.13 of the Unicode= Standard. this seems to imply that user locale setting is not relevant. (locale _is_ mentioned in https://www.unicode.org/versions/Unicode14.0.0/ch03.pdf but it looks like a _specification_ of the algorithm, not its _modification_). >> It is okay to add a `string-equal-ignore-case' based on `compare-strings= '? >> (even though it does not recognize "SS" and "=C3=9F" 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'. And I don't want to have to think about encodings and locales. So I want the core Emacs maintainers who know about these things to provide me with something that works. Thanks in advance! ;-) The fact that there are ***TWO*** core functions that compare strings - `string-collate-equalp' and `compare-strings' - does not look right to me. _I_ should not have to decide which function to use. >> Or should we first implement something like casefold in Python? > > Ha! we already have that: > > (get-char-code-property ?=C3=9F 'special-uppercase) > =3D> "SS" Nice, but how does it help me if --8<---------------cut here---------------start------------->8--- (compare-strings "SS" 0 nil "=C3=9F" 0 nil t) =3D=3D> -1 (string-collate-equalp "SS" "=C3=9F" "en_US.UTF-8" t) =3D=3D> nil --8<---------------cut here---------------end--------------->8--- instead of `t'? > Give us some credit, yes? Sure, and I am very grateful! --=20 Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.2113 http://childpsy.net http://calmchildstories.com http://steingoldpsychology.= com https://fairforall.org https://camera.org https://thereligionofpeace.com He who laughs last did not get the joke.