-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.lisp
42 lines (30 loc) · 1.08 KB
/
utils.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(in-package :cl-string-generator)
(defun word-char-p (c)
(or (alphanumericp c)
(char= c #\_)))
(defun random-choice (sequence)
(elt sequence (random (length sequence))))
(defun random-integer (min max)
(+ min (random (1+ (- max min)))))
(defun random-expected-char (test-function)
(loop :for char := (code-char (random 128))
:until (funcall test-function char)
:finally (return char)))
(defun random-char ()
(random-expected-char #'graphic-char-p))
(defun random-digit-char ()
(digit-char (random-integer 0 9)))
(defun random-non-digit-char ()
(random-expected-char (complement #'digit-char-p)))
(defun random-word-char ()
(random-expected-char #'word-char-p))
(defun random-non-word-char ()
(random-expected-char (complement #'word-char-p)))
(defun random-whitespace-char ()
(random-choice ppcre::+whitespace-char-string+))
(defun random-non-whitespace-char ()
(random-expected-char (complement #'ppcre::whitespacep)))
(defun string-append (&rest strings)
(with-output-to-string (out)
(dolist (str strings)
(write-string str out))))