SMOLNET PORTAL home about changes
ireplace split function - cl-yag - Common Lisp Yet Another website Generator	Err	bitreich.org	70
hgit clone git://bitreich.org/cl-yag/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/cl-yag/	URL:git://bitreich.org/cl-yag/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/cl-yag/	bitreich.org	70
1Log	/scm/cl-yag/log.gph	bitreich.org	70
1Files	/scm/cl-yag/files.gph	bitreich.org	70
1Refs	/scm/cl-yag/refs.gph	bitreich.org	70
1Tags	/scm/cl-yag/tag	bitreich.org	70
1README	/scm/cl-yag/file/README.md.gph	bitreich.org	70
1LICENSE	/scm/cl-yag/file/LICENSE.gph	bitreich.org	70
i---	Err	bitreich.org	70
1commit 25582ad800216c04f8f575ccb0e0a099a7897535	/scm/cl-yag/commit/25582ad800216c04f8f575ccb0e0a099a7897535.gph	bitreich.org	70
1parent f586103e1a32e6e2b5b3891275218c0e7400bc0a	/scm/cl-yag/commit/f586103e1a32e6e2b5b3891275218c0e7400bc0a.gph	bitreich.org	70
hAuthor: Solene Rapenne <solene@perso.pw>	URL:mailto:solene@perso.pw	bitreich.org	70
iDate:   Tue, 28 Nov 2017 07:21:33 +0100	Err	bitreich.org	70
i	Err	bitreich.org	70
ireplace split function	Err	bitreich.org	70
i	Err	bitreich.org	70
iDiffstat:	Err	bitreich.org	70
i  M generator.lisp                      |      27 +++++++++++++++------------	Err	bitreich.org	70
i	Err	bitreich.org	70
i1 file changed, 15 insertions(+), 12 deletions(-)	Err	bitreich.org	70
i---	Err	bitreich.org	70
1diff --git a/generator.lisp b/generator.lisp	/scm/cl-yag/file/generator.lisp.gph	bitreich.org	70
i@@ -15,17 +15,20 @@	Err	bitreich.org	70
i                                while pos)))	Err	bitreich.org	70
i 	Err	bitreich.org	70
i ;; common-lisp don't have a split string function natively	Err	bitreich.org	70
i-;; thanks https://gist.github.com/siguremon/1174988	Err	bitreich.org	70
i-(defun split-str-1 (string &optional (separator " ") (r nil))	Err	bitreich.org	70
i-  (let ((n (position separator string	Err	bitreich.org	70
i-                     :from-end t	Err	bitreich.org	70
i-                     :test #'(lambda (x y)	Err	bitreich.org	70
i-                               (find y x :test #'string=)))))	Err	bitreich.org	70
i-    (if n	Err	bitreich.org	70
i-        (split-str-1 (subseq string 0 n) separator (cons (subseq string (1+ n)) r))	Err	bitreich.org	70
i-      (cons string r))))	Err	bitreich.org	70
i-(defun split-str (string &optional (separator " "))	Err	bitreich.org	70
i-  (split-str-1 string separator))	Err	bitreich.org	70
i+(defun split-str(text &optional (separator #\Space))	Err	bitreich.org	70
i+  "this function split a string with separator and return a list"	Err	bitreich.org	70
i+  (let ((text (concatenate 'string text (string separator))))	Err	bitreich.org	70
i+    (loop for char across text	Err	bitreich.org	70
i+          counting char into count	Err	bitreich.org	70
i+          when (char= char separator)	Err	bitreich.org	70
i+          collect	Err	bitreich.org	70
i+          ;; we look at the position of the left separator from right to left	Err	bitreich.org	70
i+          (let ((left-separator-position (position separator text :from-end t :end (- count 1))))	Err	bitreich.org	70
i+            (subseq text	Err	bitreich.org	70
i+                    ;; if we can't find a separator at the left of the current, then it's the start of	Err	bitreich.org	70
i+                    ;; the string	Err	bitreich.org	70
i+                    (if left-separator-position (+ 1 left-separator-position) 0)	Err	bitreich.org	70
i+                    (- count 1))))))	Err	bitreich.org	70
i 	Err	bitreich.org	70
i ;; we have to remove the quotes	Err	bitreich.org	70
i ;; when using collect in a loop	Err	bitreich.org	70
i@@ -225,4 +228,4 @@	Err	bitreich.org	70
i       (create-gopher-hole)))	Err	bitreich.org	70
i 	Err	bitreich.org	70
i (generate-site)	Err	bitreich.org	70
i-	Err	bitreich.org	70
i+(quit)	Err	bitreich.org	70
.
Response: text/plain
Original URLgopher://bitreich.org/0/scm/cl-yag/commit/25582ad800216c0...
Content-Typetext/plain; charset=utf-8