X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=strings.lisp;h=9c6d4d1ebd61746262f6b7421feff40e58ef69f3;hb=d1e9c5969a0eecb7923dc350754ea9ab50417a1e;hp=d91d9ac9e1d92a7316d3455fca89c13fb47d7b8d;hpb=0785aaa6c33301cdb5d23ab1a09f262d33dba21d;p=kmrcl.git diff --git a/strings.lisp b/strings.lisp index d91d9ac..9c6d4d1 100644 --- a/strings.lisp +++ b/strings.lisp @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Apr 2000 ;;;; -;;;; $Id: strings.lisp,v 1.6 2003/01/13 21:40:20 kevin Exp $ +;;;; $Id: strings.lisp,v 1.8 2003/04/28 16:07:43 kevin Exp $ ;;;; ;;;; This file, part of KMRCL, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -66,12 +66,10 @@ #-excl (defun list-to-delimited-string (list &optional (separator #\space)) - (let ((output (when list (format nil "~A" (car list))))) - (dolist (obj (rest list)) - (setq output (concatenate 'string output - (format nil "~A" separator) - (format nil "~A" obj)))) - output)) + (if (consp list) + (let ((fmt (format nil "~~A~~{~A~~A~~}" separator))) + (format nil fmt (first list) (rest list))) + "")) (defun string-invert (str) "Invert case of a string" @@ -146,18 +144,37 @@ (when (stringp str) (null (find-if #'not-whitespace? str)))) -#+ignore (defun string-replace-chars-strings (str repl-alist) "Replace all instances of a chars with a string. repl-alist is an assoc list of characters and replacement strings." + (declare (string str)) (let* ((orig-len (length str)) - (new-len orign-len)) + (new-len orig-len)) (declare (fixnum orig-len new-len)) - (dotimes (i orign-len) + (dotimes (i orig-len) (declare (fixnum i)) - (let ((c (schar i str))) - ))) - str) + (let* ((c (char str i)) + (match (assoc c repl-alist :test #'char=))) + (declare (character c)) + (when match + (incf new-len (length (cdr match)))))) + (let ((new-string (make-string new-len)) + (i 0)) + (declare (string new-string) + (fixnum i)) + (dotimes (i orig-len) + (declare (fixnum i)) + (let* ((c (char str i)) + (match (assoc c repl-alist :test #'char=))) + (declare (character c)) + (if match + (let ((subst (cdr match))) + (dotimes (j (length subst)) + (setf (char new-string i) (char subst j)) + (incf i))) + (progn + (setf (char new-string i) c))))) + new-string))) (defun escape-xml-string (string) "Escape invalid XML characters"