From 42d4441521052afeb51be763c5c2543fb376210c Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Thu, 10 Jul 2014 19:25:57 -0500 Subject: [PATCH] fix author parsing for the case where a name ends with the letters 'and' original commit: cc4344a585211b72629b995838fb73befdf95ec9 --- .../scribble-lib/scriblib/bibtex.rkt | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/pkgs/scribble-pkgs/scribble-lib/scriblib/bibtex.rkt b/pkgs/scribble-pkgs/scribble-lib/scriblib/bibtex.rkt index 67ce875b..54c1b282 100644 --- a/pkgs/scribble-pkgs/scribble-lib/scriblib/bibtex.rkt +++ b/pkgs/scribble-pkgs/scribble-lib/scriblib/bibtex.rkt @@ -216,11 +216,42 @@ (define (parse-author as) (and as (apply authors - (for/list ([a (in-list (regexp-split #rx" *and *" as))]) + (for/list ([a (in-list (regexp-split #rx" +and *" as))]) (match (regexp-split #rx" +" a) [(list one) (org-author-name one)] [(list one two) (author-name one two)] - [(list-rest first rest) (author-name first (apply string-append (add-between rest " ")))]))))) + [(list-rest first rest) + (author-name first (apply string-append (add-between rest " ")))]))))) + +(module+ test + (require rackunit) + + ;; use this as a predicate to hack around lack of + ;; ability to use equal? on author element structs + (define (print-as-equal-string? a b) + (equal? (format "~s" a) + (format "~s" b))) + + (check + print-as-equal-string? + (parse-author "James Earl Jones") + (authors + (author-name "James Earl" "Jones"))) + + (check + print-as-equal-string? + (parse-author "Tim Robbins and Morgan Freeman") + (authors (author-name "Tim" "Robbins") + (author-name "Morgan" "Freeman"))) + + (check + print-as-equal-string? + (parse-author "Edward L. Deci and Robert J. Vallerand and Luc G. Pelletier and Richard M. Ryan") + (authors (author-name "Edward L." "Deci") + (author-name "Robert J." "Vallerand") + (author-name "Luc G." "Pelletier") + (author-name "Richard M." "Ryan")))) + (define (parse-pages ps) (match ps [(regexp #rx"^([0-9]+)\\-+([0-9]+)$" (list _ f l))