r7819: more getopt improvements, tests
[kmrcl.git] / strings.lisp
index 87d325425c8e7902b9ea06542952e31836aa408e..1832ff2a5dfa58f94564ee87f7b59587527c7b6e 100644 (file)
@@ -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)))))