Function: assoc-string
assoc-string is a function defined in minibuf.c.
Signature
(assoc-string KEY LIST &optional CASE-FOLD)
Documentation
Like assoc but specifically for strings (and symbols).
This returns the first element of LIST whose car matches the string or symbol KEY, or nil if no match exists. When performing the comparison, symbols are first converted to strings, and unibyte strings to multibyte. If the optional arg CASE-FOLD is non-nil, both KEY and the elements of LIST are upcased for comparison.
Unlike assoc, KEY can also match an entry in LIST consisting of a
single string, rather than a cons cell whose car is a string.
Other relevant functions are documented in the list, string and alist groups.
Probably introduced at or before Emacs version 22.1.
Shortdoc
;; alist
(assoc-string "foo" '(("foo" . "bar") ("zot" "baz")))
=> ("foo" . "bar")
;; string
(assoc-string "foo" '(("a" 1) (foo 2)))
=> (foo 2)
;; list
(assoc-string "foo" '(("a" 1) (foo 2)))
=> (foo 2)
Aliases
mh-assoc-string (obsolete since 29.1)
Source Code
// Defined in /usr/src/emacs/src/minibuf.c
{
register Lisp_Object tail;
if (SYMBOLP (key))
key = Fsymbol_name (key);
for (tail = list; CONSP (tail); tail = XCDR (tail))
{
register Lisp_Object elt, tem, thiscar;
elt = XCAR (tail);
thiscar = CONSP (elt) ? XCAR (elt) : elt;
if (SYMBOLP (thiscar))
thiscar = Fsymbol_name (thiscar);
else if (!STRINGP (thiscar))
continue;
tem = Fcompare_strings (thiscar, make_fixnum (0), Qnil,
key, make_fixnum (0), Qnil,
case_fold);
if (EQ (tem, Qt))
return elt;
maybe_quit ();
}
return Qnil;
}