From 67e9cc5c98d4c206f81aa07dc977451c13cb46cd Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Tue, 17 Jun 2003 13:56:38 +0000 Subject: [PATCH] r5151: *** empty log message *** --- package.lisp | 6 ++++-- strings.lisp | 24 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/package.lisp b/package.lisp index 7499e25..8471a1c 100644 --- a/package.lisp +++ b/package.lisp @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Apr 2000 ;;;; -;;;; $Id: package.lisp,v 1.39 2003/06/15 07:48:30 kevin Exp $ +;;;; $Id: package.lisp,v 1.40 2003/06/17 13:56:38 kevin Exp $ ;;;; ;;;; This file, part of KMRCL, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -54,9 +54,11 @@ #:hexchar #:escape-uri-field #:non-alphanumericp + #:random-string + #:first-char + #:last-char #:flatten - #:indent-spaces #:print-n-chars #:print-list 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))))) -- 2.34.1