X-Git-Url: http://git.kpe.io/?p=kmrcl.git;a=blobdiff_plain;f=strings.lisp;h=1832ff2a5dfa58f94564ee87f7b59587527c7b6e;hp=87d325425c8e7902b9ea06542952e31836aa408e;hb=d60bf2d464b393bdff8482bcaacd8d49957467ce;hpb=ea87515673ba2fd46e6e1ad270c4abf88d575a19 diff --git a/strings.lisp b/strings.lisp index 87d3254..1832ff2 100644 --- a/strings.lisp +++ b/strings.lisp @@ -602,3 +602,20 @@ for characters in a string" (push (subseq string token-start token-end) tokens))))) +(defun match-unique-abbreviation (abbr strings) + "Returns position of ABBR in STRINGS. ABBR may be a unique abbreviation. +Returns NIL if no match found." + (let ((len (length abbr)) + (matches nil)) + (dotimes (i (length strings)) + (let* ((s (nth i strings)) + (l (length s))) + (cond + ((= len l) + (when (string= abbr s) + (push (cons s i) matches))) + ((< len l) + (when (string= abbr (subseq s 0 len)) + (push (cons s i) matches)))))) + (when (= 1 (length matches)) + (cdr (first matches)))))