diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-02-01 21:32:15 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-02-01 22:10:14 +0100 |
commit | 55477368f84f76b831d3b714c52784e7bb952021 (patch) | |
tree | dd8afcc594e1b8ec6f4c59777c343488ab049820 /module/hnh/util | |
parent | Document module-dependants. (diff) | |
download | calp-55477368f84f76b831d3b714c52784e7bb952021.tar.gz calp-55477368f84f76b831d3b714c52784e7bb952021.tar.xz |
Move path-append to own module.
Diffstat (limited to 'module/hnh/util')
-rw-r--r-- | module/hnh/util/io.scm | 1 | ||||
-rw-r--r-- | module/hnh/util/path.scm | 20 |
2 files changed, 20 insertions, 1 deletions
diff --git a/module/hnh/util/io.scm b/module/hnh/util/io.scm index 04e54a9e..161e09a0 100644 --- a/module/hnh/util/io.scm +++ b/module/hnh/util/io.scm @@ -12,7 +12,6 @@ (open-output-file str))) - (define-public (read-lines port) (with-input-from-port port (lambda () diff --git a/module/hnh/util/path.scm b/module/hnh/util/path.scm new file mode 100644 index 00000000..b08932f9 --- /dev/null +++ b/module/hnh/util/path.scm @@ -0,0 +1,20 @@ +(define-module (hnh util path) + :use-module (srfi srfi-1) + :use-module (hnh util)) + +;; TODO shouldn't this use `file-name-separator-string'? +(define-public (path-append . strings) + (fold (lambda (s done) + (string-append + done + (if (string-null? s) + (string-append s "/") + (if (char=? #\/ (string-last done)) + (if (char=? #\/ (string-first s)) + (string-drop s 1) s) + (if (char=? #\/ (string-first s)) + s (string-append "/" s)))))) + (let ((s (car strings))) + (if (string-null? s) + "/" s)) + (cdr strings))) |