;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Apr 2000
;;;;
-;;;; $Id: strings.lisp,v 1.43 2003/06/17 06:18:09 kevin Exp $
+;;;; $Id: strings.lisp,v 1.44 2003/06/17 13:56:38 kevin Exp $
;;;;
;;;; This file, part of KMRCL, is Copyright (c) 2002 by Kevin M. Rosenberg
;;;;
(setf (schar str dpos) (hexchar (logand c 15))))
(setf (schar str dpos) ch)))))
+(defconstant +char-code-a+ (char-code #\a))
+
+(defun random-string (&optional (len 10))
+ "Returns a random lower-case string."
+ (declare (optimize (speed 3)))
+ (let ((s (make-string len)))
+ (declare (simple-string s)
+ (dotimes (i len s)
+ (setf (schar s i) (code-char (+ +code-char-a+ (random 26))))))))
+
+
+(defun first-char (s)
+ (declare (simple-string s))
+ (when (and (stringp s) (plusp (length s)))
+ (schar s 0)))
+
+(defun last-char (s)
+ (declare (simple-string s))
+ (when (stringp s)
+ (let ((len (length s)))
+ (when (plusp len))
+ (schar s (1- len)))))