bkyk8rc3zvpnsf5inmcqq4n3k98cv6hj-my-site-hyper-literate-git.test.suzanne.soy-0.0.1

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit db64a47dd7e17446ba4d0acd6a8b29700ab710a9
parent 1efd01584e13aabc228bf7ad4485032304323ea2
Author: Danny Yoo <dyoo@cs.wpi.edu>
Date:   Mon, 25 Jun 2012 16:55:01 -0400

Changing decode-string so it avoids allocation and interns the individual string components.

original commit: 2f4671235c322f3450b0633cd866f18b95f58f13

Diffstat:
Mcollects/scribble/decode.rkt | 34+++++++++++++++++++++-------------
1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/collects/scribble/decode.rkt b/collects/scribble/decode.rkt @@ -92,20 +92,28 @@ [s (regexp-replace* #rx" $" s "")]) (datum-intern-literal s))) + (define (decode-string s) - (let loop ([l '((#rx"---" mdash) - (#rx"--" ndash) - (#rx"``" ldquo) - (#rx"''" rdquo) - (#rx"'" rsquo))]) - (cond [(null? l) (list s)] - [(regexp-match-positions (caar l) s) - => (lambda (m) - (datum-intern-literal - (append (decode-string (substring s 0 (caar m))) - (cdar l) - (decode-string (substring s (cdar m))))))] - [else (loop (cdr l))]))) + (define pattern #rx"(---|--|``|''|')") + (let loop ([start 0]) + (cond + [(regexp-match-positions pattern s start) + => (lambda (m) + (define the-match (substring s (caar m) (cdar m))) + (list* (datum-intern-literal (substring s start (caar m))) + (cond + [(string=? the-match "---") 'mdash] + [(string=? the-match "--") 'ndash] + [(string=? the-match "``") 'ldquo] + [(string=? the-match "''") 'rdquo] + [(string=? the-match "'") 'rsquo]) + (loop (cdar m))))] + ;; Common case: nothing to decode, so don't copy strings. + [(= start 0) + (list (datum-intern-literal s))] + [else + (list (datum-intern-literal (substring s start)))]))) + (define (line-break? v) (equal? v "\n"))