all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Sam Steingold <sds@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: idiomatic case-insensitive string comparison?
Date: Mon, 18 Jul 2022 13:47:31 -0400	[thread overview]
Message-ID: <lzedyiuxcc.fsf@3c22fb11fdab.ant.amazon.com> (raw)

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.



             reply	other threads:[~2022-07-18 17:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-18 17:47 Sam Steingold [this message]
2022-07-18 19:41 ` idiomatic case-insensitive string comparison? Sam Steingold

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

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

  git send-email \
    --in-reply-to=lzedyiuxcc.fsf@3c22fb11fdab.ant.amazon.com \
    --to=sds@gnu.org \
    --cc=help-gnu-emacs@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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.