introduce co-string struct

main
Matthew Butterick 7 years ago
parent 625cd7c92d
commit f765b2b942

@ -50,17 +50,17 @@
[("f") "\f"]
[else sub])))]
[str (regexp-replace* @pregexp{\\(\d{2,3})} str (λ (m sub) (string (integer->char (string->number sub 8)))))])
str)]))
(co-string str))]))
(module+ test
(check-equal? @pf-string{(Testing)} "Testing")
(check-equal? @pf-string{(Testing)} (co-string "Testing"))
(check-equal? (pf-string @string-append{(Test\
ing)}) "Testing")
(check-equal? @pf-string{(Test\)ing)} "Test)ing")
(check-equal? @pf-string{(Test\ning)} "Test\ning")
(check-equal? @pf-string{(Test\\ing)} "Test\\ing")
(check-equal? @pf-string{(A\53B)} "A+B")
(check-equal? @pf-string{(A\053B)} "A+B")
ing)}) (co-string "Testing"))
(check-equal? @pf-string{(Test\)ing)} (co-string "Test)ing"))
(check-equal? @pf-string{(Test\ning)} (co-string "Test\ning"))
(check-equal? @pf-string{(Test\\ing)} (co-string "Test\\ing"))
(check-equal? @pf-string{(A\53B)} (co-string "A+B"))
(check-equal? @pf-string{(A\053B)} (co-string "A+B"))
#;(check-equal? @pf-string{(D:19990209153925-08\'00\')})
#;(check-true (andmap byte? @pf-string{<1C2D3F>}))
#;(check-true (andmap byte? @pf-string{<1C 2D 3F>})))

@ -34,7 +34,7 @@
(if (co-io? cosexpr)
(cons (cons (co-io-idx cosexpr) offset) io-locs)
io-locs))))
(define header-str (cosexpr->bytes (co-header "%PDF-1.3\n%¥±ë")))
(define header-str (cosexpr->bytes (co-header "%PDF-1.4\n%¥±ë")))
(define trailer-str (cosexpr->bytes
(co-trailer (co-dict (hasheq 'Size (length bstrs) 'Root (co-io-ref 1 0))))))
(define last-offset (for/sum ([bstr (in-list bstrs)])
@ -78,6 +78,7 @@
>>}]
[(co-io-ref? x)
@string-append{@(loop (co-io-ref-idx x)) @(loop (co-io-ref-rev x)) R}]
[(co-string? x) (format "(~a)" (co-string-string x))]
[(co-stream? x)
@string-append{
@(loop (co-stream-dict x))
@ -120,4 +121,6 @@
(co-dict (apply hasheq xs)))
(define (make-co-stream bstr)
(co-stream (make-co-dict 'Length (bytes-length bstr)) bstr))
(co-stream (make-co-dict 'Length (bytes-length bstr)) bstr))
(cosexpr->bytes (make-co-dict 'Hello (co-string "World")))

@ -6,7 +6,8 @@
(struct co-stream (dict data) #:transparent)
(struct co-version (num) #:transparent)
(struct co-header (string) #:transparent)
(struct co-string (string) #:transparent)
(struct co-io (idx rev thing) #:transparent)
(struct co-io-ref (idx rev) #:transparent)
(struct co-comment (text) #:transparent)
(struct co-trailer (dict) #:transparent)
(struct co-trailer (dict) #:transparent)

Loading…
Cancel
Save