[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) |
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.
- idiomatic case-insensitive string comparison?,
Sam Steingold <=