* idiomatic case-insensitive string comparison?
@ 2022-07-18 17:47 Sam Steingold
2022-07-18 19:41 ` Sam Steingold
0 siblings, 1 reply; 2+ messages in thread
From: Sam Steingold @ 2022-07-18 17:47 UTC (permalink / raw)
To: help-gnu-emacs
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-07-18 19:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-18 17:47 idiomatic case-insensitive string comparison? Sam Steingold
2022-07-18 19:41 ` Sam Steingold
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).