From 91fbf8d66d62be228d442c227263cdb6f2ddd5aa Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 26 Nov 2018 20:43:03 -0800 Subject: [PATCH] shortening --- pitfall/pitfall/check-pdf.rkt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pitfall/pitfall/check-pdf.rkt b/pitfall/pitfall/check-pdf.rkt index 293c24a9..69abfd0e 100644 --- a/pitfall/pitfall/check-pdf.rkt +++ b/pitfall/pitfall/check-pdf.rkt @@ -118,6 +118,14 @@ (cons idx (parse-pdf-bytes (peek-bytes (- end start) start))))) < #:key car)) +(define (shorten-val v) + (cond + [(dict? v) (for/list ([(key val) (in-dict v)]) + (cons key (shorten-val val)))] + [(and (bytes? v) (> (bytes-length v) 100)) + (subbytes v 0 100)] + [else v])) + (define (dict-compare arg1 arg2) (define d1 (if (dict? arg1) arg1 (pdf->dict arg1))) (define d2 (if (dict? arg2) arg2 (pdf->dict arg2))) @@ -128,12 +136,8 @@ (unless (equal? k1 k2) (error (format "keys unequal in ~a and ~a: ~a ≠ ~a" arg1 arg2 k1 k2))) (unless (equal? v1 v2) - (define val1 (if (and (bytes? v1) (> (bytes-length v1) 200)) - (subbytes v1 0 200) - v1)) - (define val2 (if (and (bytes? v2) (> (bytes-length v2) 200)) - (subbytes v2 0 200) - v2)) + (define val1 (shorten-val v1)) + (define val2 (shorten-val v2)) (error (format "values unequal in ~a and ~a: ~a ≠ ~a" arg1 arg2 val1 val2))) (when (dict? v1) (dict-compare v1 v2))