diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-02-01 21:32:51 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-02-01 22:10:14 +0100 |
commit | 20063a926b0b4daf96c06b31b11e5d028225e6e2 (patch) | |
tree | 325f1fe5b8ea7aa31e79cdf2e78bb391b031c88d /module/hnh/util/path.scm | |
parent | Add path-join. (diff) | |
download | calp-20063a926b0b4daf96c06b31b11e5d028225e6e2.tar.gz calp-20063a926b0b4daf96c06b31b11e5d028225e6e2.tar.xz |
Add path-split.
Diffstat (limited to 'module/hnh/util/path.scm')
-rw-r--r-- | module/hnh/util/path.scm | 21 |
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)))) |