[Top][All Lists]

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

idiomatic case-insensitive string comparison?

From: Sam Steingold
Subject: idiomatic case-insensitive string comparison?
Date: Mon, 18 Jul 2022 13:47:31 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (darwin)

Suppose I need to compare strings in a case-insensitive manner.

Common Lisp provides `string-equal', `string-lessp' and `string-greaterp'

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()
( others do not

Sam Steingold ( on darwin Ns 10.3.2113
recursion, n: See recursion.

reply via email to

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