X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=strings.lisp;h=1832ff2a5dfa58f94564ee87f7b59587527c7b6e;hb=d60bf2d464b393bdff8482bcaacd8d49957467ce;hp=7310bef870c744d9e4bf2a662e8f0f0a3ca50da0;hpb=61100bfd2f0176c743db058160316a59441ce352;p=kmrcl.git diff --git a/strings.lisp b/strings.lisp index 7310bef..1832ff2 100644 --- a/strings.lisp +++ b/strings.lisp @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Apr 2000 ;;;; -;;;; $Id: strings.lisp,v 1.52 2003/08/12 06:37:53 kevin Exp $ +;;;; $Id$ ;;;; ;;;; This file, part of KMRCL, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -153,6 +153,8 @@ (defun is-string-empty (str) (zerop (length str))) +(defvar *whitespace-chars* '(#\space #\tab #\return #\linefeed)) + (defun is-char-whitespace (c) (declare (character c) (optimize (speed 3) (safety 0))) (or (char= c #\Space) (char= c #\Tab) (char= c #\Return) @@ -162,6 +164,15 @@ "Return t if string is all whitespace" (every #'is-char-whitespace str)) +(defun string-right-trim-whitespace (str) + (string-right-trim *whitespace-chars* str)) + +(defun string-left-trim-whitespace (str) + (string-left-trim *whitespace-chars* str)) + +(defun string-trim-whitespace (str) + (string-trim *whitespace-chars* str)) + (defun replaced-string-length (str repl-alist) (declare (simple-string str) (optimize (speed 3) (safety 0) (space 0))) @@ -591,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)))))