aboutsummaryrefslogtreecommitdiff
path: root/module/output/common.scm
blob: 3955442fea6d0427294e5fcef41ccfc1630e8eb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
;;; Commentary:
;; Common code between all serializers.
;; (ical and xcal). Not for graphical output stuff.
;;; Code:

(define-module (output common)
  :use-module (util)
  :use-module (srfi srfi-1)
  :use-module (vcomponent)
  )

;; TODO this is also defined @ (vcomponent parse component)
(define-public (x-property? symb)
  (string=? "X-" (string-take (symbol->string symb) 2)))

;; TODO this is also defined twice
(define-public (generate-uuid)
  ((@ (rnrs io ports) call-with-port)
   ((@ (ice-9 popen) open-input-pipe) "uuidgen")
   (@ (ice-9 rdelim) read-line)))

(define*-public (internal-field? symbol optional: (prefix "X-HNH-"))
  (string=? prefix
            (string-take-to (symbol->string symbol)
                            (string-length prefix))))

(define-public (->string a)
  (with-output-to-string (lambda () (display a))))

(define-public (get-tz-names events)
  (lset-difference
   equal? (lset-union
           equal? '("dummy")
           (filter-map
            (lambda (vline) (and=> (prop vline 'TZID) car))
            (filter-map (extract* 'DTSTART)
                        events)))
   '("dummy" "local")))

(define-public (downcase-symbol symb)
  (-> symb
      symbol->string
      string-downcase
      string->symbol))