;;;; 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
;;;;
(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"