aboutsummaryrefslogtreecommitdiff
path: root/module/hnh/util/path.scm
blob: b08932f9cdd7b98c1ea4a6ada96c08f70be58fc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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)))