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.help Subject: idiomatic case-insensitive string comparison? Date: Mon, 18 Jul 2022 13:47:31 -0400 Message-ID: Reply-To: sds@gnu.org Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19279"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (darwin) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jul 19 06:34:54 2022 Return-path: Envelope-to: geh-help-gnu-emacs@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 1oDewg-0004qo-BG for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 19 Jul 2022 06:34:54 +0200 Original-Received: from localhost ([::1]:38684 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDewf-00079x-8o for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 19 Jul 2022 00:34:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDUqI-0000yP-S7 for help-gnu-emacs@gnu.org; Mon, 18 Jul 2022 13:47:38 -0400 Original-Received: from mail-qv1-xf31.google.com ([2607:f8b0:4864:20::f31]:39916) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oDUqE-0005SA-Q7; Mon, 18 Jul 2022 13:47:37 -0400 Original-Received: by mail-qv1-xf31.google.com with SMTP id nd6so9334346qvb.6; Mon, 18 Jul 2022 10:47:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:subject:user-agent:return-receipt-to:reply-to :mail-followup-to:date:message-id:mime-version; bh=o67C300cNz5+rtSgmbaGIfiGduouMM42XDzaphvUs1A=; b=RLsywo10cTVdLLFttn2TVqKP0GjmgUGFXmC1MQRdfS2e2qaX7TGOgrb2p7CFF5+Flq HtY7d9wqtJ2XF0FtDCnOa19h1obuy4s/WzdepBXm4Uu/SOBN0UnnWhfmcOk0G1KWVOZV ScyMp71UtmJSVOrxSizzet3W75lU0s/0Xsagmb+Pb60hsC9UrfSBi2DE4FzbY4AzBGA2 I5uMKxsHGYycXpmJIzqcjPnytWG0HVzW5dWDnZ9BJphw8RInTPv12VntHHrl0/aIBhKK wr/7Rd9EkFeXLyw0tlQj2O4aJzGE1kMzB6ZfD/H0cRhlhROr0WLxOclxUSYcjQp26Nrr o7QQ== 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:user-agent :return-receipt-to:reply-to:mail-followup-to:date:message-id :mime-version; bh=o67C300cNz5+rtSgmbaGIfiGduouMM42XDzaphvUs1A=; b=eV1QUWTxM+AZ0Tv6TaXJVhsYxvSMoUJfV9fheRrk/Hb/UikVwkQ8z5tzyMqbE0HuRU +AZrT2p/LgOF1wBnknrnEYLPKNiwRi0V3bXWLXjyhGcfYHYa3przbhGEnI5HORCX8ioz /8TA2mH57ORr7Vn/qZYsGDuAdulXy2uSrNLUtGwpTWdojY+NLXOiRLOKtK5heBgTgdTp NM5r3qDwI6jxYz58XLV4pBcc7pCKSaMLbs6ndcLjquX1wf5PZswvDW6LVazTweJV5W0g Y4JlgOMnwoqFqD7bm+siL6Y41oVwMLr4Gel6Mo5dntuu/g+KY16zIBoZOsSmm5lxmEzF jyMg== X-Gm-Message-State: AJIora/gHif3CiC/HaKXLWP8LNeg0d/OGmGw50byqISS4jr5RKHKvBKK 6wf5k5byr/KYjuEOXf5qreL8eDI3nQ== X-Google-Smtp-Source: AGRyM1tmRLEuVxsrfHZLLtATX3eoQROkvG0Sw4f0WltaY61u3vWubegqtbZYQLnoD1G5WXyzz1JsCA== X-Received: by 2002:a05:6214:f05:b0:473:7874:5e7a with SMTP id gw5-20020a0562140f0500b0047378745e7amr22115639qvb.19.1658166453026; Mon, 18 Jul 2022 10:47:33 -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 bj30-20020a05620a191e00b006b59f02224asm3432671qkb.60.2022.07.18.10.47.32 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Jul 2022 10:47:32 -0700 (PDT) X-Attribution: Sam X-Disclaimer: You should not expect anyone to agree with me. Mail-Followup-To: help-gnu-emacs@gnu.org Received-SPF: pass client-ip=2607:f8b0:4864:20::f31; envelope-from=sam.steingold@gmail.com; helo=mail-qv1-xf31.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, 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-Mailman-Approved-At: Tue, 19 Jul 2022 00:33:33 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:138522 Archived-At: Hi, Suppose I need to compare strings in a case-insensitive manner. Common Lisp provides `string-equal', `string-lessp' and `string-greaterp' (http://clhs.lisp.se/Body/f_stgeq_.htm). However, in Emacs Lisp `string=' and `string-equal' are the same (and are not affected by `case-fold-search'). I suppose I can define --8<---------------cut here---------------start------------->8--- (defun string=-case-fold (a b) "case-insensitive string equality test" (string= (downcase a) (downcase b))) --8<---------------cut here---------------end--------------->8--- but this has at least two problems: 1. It can break down for some non-ASCII characters (e.g., Eszett) 2. It allocates fresh memory unnecessarily So, what is the Emacs Lisp idiom for case-insensitive string equality? PS. Some languages offer strcasecmp() (https://en.wikipedia.org/wiki/C_string_handling) others do not (https://stackoverflow.com/q/319426/850781). -- Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.2113 http://childpsy.net http://calmchildstories.com http://steingoldpsychology.com https://iris.org.il https://www.memritv.org https://www.dhimmitude.org recursion, n: See recursion.