X-Git-Url: http://git.kpe.io/?p=kmrcl.git;a=blobdiff_plain;f=strings.lisp;h=d8c0e439a1383bf383ea96c20c44374608a81c75;hp=35a177e9715371cc38eea292eddb09c05d380518;hb=aa610805927518a648eb0da6a8713cd0a83337df;hpb=8e31d13cfde9a2f7b6ea76a342a813e30dfe9696 diff --git a/strings.lisp b/strings.lisp index 35a177e..d8c0e43 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.9 2003/04/28 21:12:27 kevin Exp $ ;;;; ;;;; This file, part of KMRCL, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -144,18 +144,39 @@ (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)) + (len (length match))) + (dotimes (j len) + (setf (char new-string i) (char subst j)) + (incf i)) + (decf i)) + (progn + (setf (char new-string i) c))))) + new-string))) (defun escape-xml-string (string) "Escape invalid XML characters"