From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: case-insensitive string comparison Date: Wed, 20 Jul 2022 20:50:16 +0300 Message-ID: <83fsivlllz.fsf@gnu.org> References: <87ilnsq4cr.fsf@gnu.org> <87mtd3n455.fsf@gnu.org> <83ilnrlnd1.fsf@gnu.org> <87lesnlm7a.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31948"; mail-complaints-to="usenet@ciao.gmane.io" Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org To: Roland Winkler Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Jul 20 19:51:45 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 1oEDrM-000845-5q for ged-emacs-devel@m.gmane-mx.org; Wed, 20 Jul 2022 19:51:44 +0200 Original-Received: from localhost ([::1]:51294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oEDrK-0005ru-R0 for ged-emacs-devel@m.gmane-mx.org; Wed, 20 Jul 2022 13:51:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41778) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEDq5-00055V-Si for emacs-devel@gnu.org; Wed, 20 Jul 2022 13:50:29 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:34644) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEDq4-0004WT-VG; Wed, 20 Jul 2022 13:50:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=N24HiQ/clB7y2hsRBJOJ6aNQ93mKb1voTMdjYX8FyIw=; b=ctUxeImpW3WF 3ajj0uUdCYwVh6GFsDVTWV4MlvH6BQ165VotHs9St3WgidDuDetuvxeNHDSma8AEgH4Eu2XdT5aOm /aVhjsBTj64rRwmz0A/YmNrqgddK/CctQi0hxHWed85ZBwLhfzJ9e0xBuPy2GyBeWudA2gL7Mwt28 4YPQHdU/XwzdEnvVR0tywyp1dtHir+pOFrg8lqn+6NwhWRqu6yPQo83dgBn/aYhA9MwVB8qhiLptZ sfkXF88Mw9xzsCrnbj8mNsW4iTY3L11o6hw2HevCNNuAnaS2zO1v5ESIMGUBofzMAO2QOCrhX0hhS zh8E0I4KMohtxJi/OtfGVA==; Original-Received: from [87.69.77.57] (port=4768 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEDq4-0007DG-DY; Wed, 20 Jul 2022 13:50:24 -0400 In-Reply-To: <87lesnlm7a.fsf@gnu.org> (message from Roland Winkler on Wed, 20 Jul 2022 12:37:29 -0500) 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:292314 Archived-At: > From: Roland Winkler > 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.