aboutsummaryrefslogtreecommitdiff
path: root/module/hnh
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-02-01 21:32:51 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2022-02-01 22:10:14 +0100
commit20063a926b0b4daf96c06b31b11e5d028225e6e2 (patch)
tree325f1fe5b8ea7aa31e79cdf2e78bb391b031c88d /module/hnh
parentAdd path-join. (diff)
downloadcalp-20063a926b0b4daf96c06b31b11e5d028225e6e2.tar.gz
calp-20063a926b0b4daf96c06b31b11e5d028225e6e2.tar.xz
Add path-split.
Diffstat (limited to 'module/hnh')
-rw-r--r--module/hnh/util/path.scm21
1 files changed, 21 insertions, 0 deletions
diff --git a/module/hnh/util/path.scm b/module/hnh/util/path.scm
index 41b2e1fc..49338d01 100644
--- a/module/hnh/util/path.scm
+++ b/module/hnh/util/path.scm
@@ -20,3 +20,24 @@
(cdr strings)))
(define-public (path-join lst) (apply path-append lst))
+
+;; @example
+;; (path-split "usr/lib/test")
+;; ⇒ ("usr" "lib" "test")
+;; (path-split "/usr/lib/test")
+;; ⇒ ("" "usr" "lib" "test")
+;; (path-split "//usr////lib/test")
+;; ⇒ ("" "usr" "lib" "test")
+;; @end example
+(define-public (path-split path)
+ (let* ((head tail
+ (car+cdr
+ (reverse
+ (map reverse-list->string
+ (fold (lambda (c done)
+ (if (file-name-separator? c)
+ (cons '() done)
+ (cons (cons c (car done)) (cdr done))))
+ '(())
+ (string->list path)))))))
+ (cons head (remove string-null? tail))))