-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace-cow.lisp
More file actions
20 lines (16 loc) · 818 Bytes
/
replace-cow.lisp
File metadata and controls
20 lines (16 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
;;;; replace-cow.lisp
(defpackage #:cl-cowsay.replace-cow
(:export #:replace-cow))
(in-package #:cl-cowsay.replace-cow)
(defun replace-cow (cow eyes tongue thoughts)
(setf cow (extract-cow cow)
cow (cl-ppcre:regex-replace-all "\\$thoughts" cow thoughts)
cow (cl-ppcre:regex-replace-all "\\$eyes" cow eyes)
cow (cl-ppcre:regex-replace-all "\\$\\{eyes\\}" cow eyes)
cow (cl-ppcre:regex-replace-all "\\$tongue" cow tongue)
cow (cl-ppcre:regex-replace-all "\\$\\{tongue\\}" cow tongue)
cow (cl-ppcre:regex-replace "\\$eye" cow (string (char eyes 0)))
cow (cl-ppcre:regex-replace "\\$eye" cow (string (char eyes 1)))))
(defun extract-cow (str)
(cl-ppcre:register-groups-bind (cow)
("\\$the_cow\\s*=\\s*<<\"*EOC\"*;*\\n([\\s\\S]+)\\nEOC\\n" str) cow))