This commit is contained in:
Jay McCarthy 2019-01-18 16:20:13 +00:00
parent 8d64a0ad50
commit 7c08ded63b
2 changed files with 34 additions and 1 deletions

View File

@ -0,0 +1,23 @@
#lang racket/base
(require xml
xml/plist)
(module+ test
(require rackunit)
(define example
#<<END
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>Genre</key>
<string>Gospel &#38; Religious</string>
</dict>
</plist>
END
)
(check-equal?
(read-plist (open-input-string example))
'(dict (assoc-pair "Genre" "Gospel & Religious"))))

View File

@ -164,10 +164,20 @@
(cons `(assoc-pair ,(cadr key) ,(collapse-value value))
(collapse-assoc-pairs rest)))))
(define (convert-string-value x)
(cond [(string? x)
x]
[(integer? x)
(string (integer->char x))]
[else
(error 'read-plist "Illegal string value: ~e" x)]))
; collapse-value : xexpr -> value
(define (collapse-value value)
(case (car value)
[(string) (cadr value)]
[(string) (apply string-append
(map convert-string-value
(cdr value)))]
[(true false) value]
[(integer real) (list (car value) (string->number (cadr value)))]
[(dict) (collapse-dict value)]