Commit | Line | Data |
---|---|---|
8e198a08 MB |
1 | (in-package :js) |
2 | ||
3 | (defun list-join (list elt) | |
4 | (let (res) | |
5 | (dolist (i list) | |
6 | (push i res) | |
7 | (push elt res)) | |
8 | (pop res) | |
9 | (nreverse res))) | |
10 | ||
11 | ;;; wie herrlich effizient | |
12 | (defun list-to-string (list) | |
13 | (reduce #'(lambda (str1 &optional (str2 "")) | |
14 | (concatenate 'string str1 str2)) | |
15 | list)) | |
16 | ||
17 | (defun append-to-last (form elt) | |
18 | (cond ((stringp form) | |
19 | (concatenate 'string form elt)) | |
20 | ((consp form) | |
21 | (let ((last (last form))) | |
22 | (if (stringp (car last)) | |
23 | (rplaca last (concatenate 'string (car last) elt)) | |
24 | (append-to-last (car last) elt)) | |
25 | form)) | |
26 | (t (error "unsupported form ~S" form)))) | |
27 | ||
28 | (defun prepend-to-first (form elt) | |
29 | (cond ((stringp form) | |
30 | (concatenate 'string elt form)) | |
31 | ((consp form) | |
32 | (let ((first (first form))) | |
33 | (if (stringp first) | |
34 | (rplaca form (concatenate 'string elt first)) | |
35 | (prepend-to-first first elt)) | |
36 | form)) | |
37 | (t (error "unsupported form ~S" form)))) | |
38 | ||
39 | (defun string-join (strings elt) | |
40 | (list-to-string (list-join strings elt))) | |
41 | ||
42 | (defun val-to-string (val) | |
43 | (cond ((stringp val) val) | |
44 | ((symbolp val) (string-downcase (symbol-name val))) | |
45 | (t (princ-to-string val)))) | |
46 | ||
47 | (defun string-split (string separators) | |
48 | (do ((len (length string)) | |
49 | (i 0 (1+ i)) | |
50 | (last 0) | |
51 | res) | |
52 | ((= i len) | |
53 | (nreverse (if (> i last) | |
54 | (cons (subseq string last i) res) | |
55 | res))) | |
56 | (when (member (char string i) separators) | |
57 | (push (subseq string last i) res) | |
58 | (setf last (1+ i))))) |