X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=strings.lisp;h=48a29107a419dc110a0e71176b4d690a20672c32;hb=22d1e67006cc5f8ba1f668ec7f991df02e8bc570;hp=7bd949dc34f5272002e9760164e8deb2bbe09161;hpb=4ff29163b47297935f50ad17f2bf908567beee9e;p=kmrcl.git diff --git a/strings.lisp b/strings.lisp index 7bd949d..48a2910 100644 --- a/strings.lisp +++ b/strings.lisp @@ -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)))))