X-Git-Url: http://git.kpe.io/?p=kmrcl.git;a=blobdiff_plain;f=strings.lisp;h=9c6d4d1ebd61746262f6b7421feff40e58ef69f3;hp=35a177e9715371cc38eea292eddb09c05d380518;hb=d1e9c5969a0eecb7923dc350754ea9ab50417a1e;hpb=c6f58020561bb64e61442e89b82bf07e1323a04a diff --git a/strings.lisp b/strings.lisp index 35a177e..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.7 2003/02/07 14:21:55 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 ;;;; @@ -144,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"