-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.lisp
More file actions
75 lines (60 loc) · 2.52 KB
/
string.lisp
File metadata and controls
75 lines (60 loc) · 2.52 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
;; (c) Дмитрий Пинский <demetrius@neverblued.info>
;; Допускаю использование и распространение согласно
;; LLGPL -> http://opensource.franz.com/preamble.html
(in-package #:cl-blackjack)
(defun begins-with? (whole beginning)
(let ((beginning-length (length beginning))
(whole-length (length whole)))
(if (> beginning-length whole-length)
nil
(equal beginning (subseq whole 0 beginning-length)))))
(defun capitalize-1st (string)
(if (< 0 (length string))
(string-capitalize string :start 0 :end 1)
string))
(defun checksum (secret)
(byte-array-to-hex-string (digest-sequence :sha256 (string-to-octets secret))))
(defun clean-unicode (source)
(remove #\Nul source))
(defun join (&rest strings)
(format nil "~{~a~}" strings))
(defun join-by (separator &rest strings)
(format nil (format nil "~~{~~a~~^~a~~}" separator) strings))
(defun join-rec (&rest strings-or-lists)
(apply #'join (mapcar (lambda (item)
(if (listp item)
(apply #'join-rec item)
item))
strings-or-lists)))
(defun name-keyword (string)
(unless (string= (string-downcase string) "nil")
(intern (string-upcase string) (find-package :keyword))))
(defun split-once (regex source)
(split regex source :limit 2))
(defun trim-left (cut source)
(regex-replace (create-scanner `(:sequence
:start-anchor
,cut
(:sequence (:register (:greedy-repetition 0 nil :everything)) :end-anchor)
))
source "\\1"))
(defun trim-right (cut source)
(regex-replace (create-scanner `(:sequence
(:sequence (:register (:greedy-repetition 0 nil :everything)) :end-anchor)
,cut
:end-anchor
))
source "\\1"))
(defun regex-cut (regex source)
(regex-replace-all regex source ""))
(defun safely-read-from-string (str &rest read-from-string-args)
"Read an expression from the string STR, with *READ-EVAL* set
to NIL. Any unsafe expressions will be replaced by NIL in the
resulting S-Expression."
(let ((*read-eval* nil))
(ignore-errors
(apply #'read-from-string str read-from-string-args))))
(defun string-null
(this)
(or (cl:null this)
(string= "" (join this))))