(declare (type (integer 0 15) n))
(schar +hex-chars+ n))
-(defconstant +char-code-lower-a+ (char-code #\a))
-(defconstant +char-code-upper-a+ (char-code #\A))
-(defconstant +char-code-0+ (char-code #\0))
+(defconst +char-code-lower-a+ (char-code #\a))
+(defconst +char-code-upper-a+ (char-code #\A))
+(defconst +char-code-0+ (char-code #\0))
(declaim (type fixnum +char-code-0+ +char-code-upper-a+
+char-code-0))
(eval-when (:compile-toplevel :load-toplevel :execute)
- (defvar +unambigous-charset+
+ (defvar +unambiguous-charset+
"abcdefghjkmnpqrstuvwxyz123456789ABCDEFGHJKLMNPQSRTUVWXYZ")
- (defconstant +unambigous-length+ (length +unambigous-charset+)))
+ (defconstant +unambiguous-length+ (length +unambiguous-charset+)))
(defun random-char (&optional (set :lower-alpha))
(ecase set
(code-char (+ +char-code-lower-a+ n)))))
(:upper-alpha
(code-char (+ +char-code-upper-a+ (random 26))))
- (:unambigous
- (schar +unambigous-charset+ (random +unambigous-length+)))
+ (:unambiguous
+ (schar +unambiguous-charset+ (random +unambiguous-length+)))
(:upper-lower-alpha
(let ((n (random 52)))
(if (>= n 26)
(defun split-alphanumeric-string (string)
"Separates a string at any non-alphanumeric chararacter"
- (flet ((is-sep (char) (non-alphanumericp char)))
+ (declare (simple-string string)
+ (optimize (speed 3) (safety 0)))
+ (flet ((is-sep (char)
+ (declare (character char))
+ (and (non-alphanumericp char)
+ (not (char= #\_ char)))))
(let ((tokens nil))
(do* ((token-start
(position-if-not #'is-sep string)
(push (subseq string token-start token-end) tokens)))))
-
+(defun trim-non-alphanumeric (word)
+ "Strip non-alphanumeric characters from beginning and end of a word."
+ (declare (simple-string word)
+ (optimize (speed 3) (safety 0) (space 0)))
+ (let* ((start 0)
+ (len (length word))
+ (end len))
+ (declare (fixnum start end len))
+ (do ((done nil))
+ ((or done (= start end)))
+ (if (alphanumericp (schar word start))
+ (setq done t)
+ (incf start)))
+ (when (> end start)
+ (do ((done nil))
+ ((or done (= start end)))
+ (if (alphanumericp (schar word (1- end)))
+ (setq done t)
+ (decf end))))
+ (if (or (plusp start) (/= len end))
+ (subseq word start end)
+ word)))
+
+
(defun collapse-whitespace (s)
"Convert multiple whitespace characters to a single space character."
(declare (simple-string s)