r5151: *** empty log message ***
[kmrcl.git] / strings.lisp
index 7bd949dc34f5272002e9760164e8deb2bbe09161..48a29107a419dc110a0e71176b4d690a20672c32 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; 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
 ;;;;
@@ -426,3 +426,25 @@ for characters in a string"
            (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)))))