r5151: *** empty log message ***
authorKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 17 Jun 2003 13:56:38 +0000 (13:56 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 17 Jun 2003 13:56:38 +0000 (13:56 +0000)
package.lisp
strings.lisp

index 7499e2566e453186a341cddc08451251c75b9593..8471a1c1bc633d269e1193645e9038c7fb1c53ff 100644 (file)
@@ -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
 ;;;;
    #:hexchar
    #:escape-uri-field
    #:non-alphanumericp
+   #:random-string
+   #:first-char
+   #:last-char
    
    #:flatten
-   
    #:indent-spaces
    #:print-n-chars
    #:print-list
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)))))