Commits

Jerry James  committed 956c7e5

Implement assoc-string (in Lisp, versus the C implementation used in Emacs).
See <CAHCOHQk9m6pmDz9HSVoWdGZpvzVc6Y1gEk5m6UNF15b0VwGuDQ@mail.gmail.com> in
xemacs-patches.

  • Participants
  • Parent commits 06f247e

Comments (0)

Files changed (2)

+2014-08-04  Jerry James  <james@xemacs.org>
+
+	* subr-more.el (assoc-string): New function from GNU Emacs.
+
 2014-05-15  Norbert Koch  <viteno@xemacs.org>
 
 	* Makefile (VERSION): XEmacs package 2.41 released.

File subr-more.el

          (progn ,@body)
        (error (message "Error: %S" ,err) nil))))
 
+;;;###autoload
+(defun assoc-string (key list &optional case-fold)
+  "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.  If the optional arg CASE-FOLD
+is non-nil, case is ignored.
+
+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."
+  (when (symbolp key)
+    (setq key (symbol-name key)))
+  (let* ((tail list) elt elt2 elt3 result)
+    (while (and (null result) tail)
+      (setq elt (car tail)
+	    elt2 (if (consp elt) (car elt) elt)
+	    elt3 (if (symbolp elt2) (symbol-name elt2) elt2)
+	    result (and (stringp elt3)
+			(eq (compare-strings elt3 0 nil key 0 nil case-fold) t)
+			elt)
+	    tail (cdr tail)))
+    result))
+
 ;;; subr-more.el ends here