commit d34569cebeba877256103f778943b8d796ea3933
parent aee15712e562d08e88642f7f4276858cf2a55d4b
Author: Georges Dupéron <georges.duperon@gmail.com>
Date: Wed, 17 May 2017 17:33:07 +0200
Changed " +" to "\\s+" in parse-author. Added more test for Last,First format for names in bibtex.
Diffstat:
1 file changed, 71 insertions(+), 5 deletions(-)
diff --git a/scribble-lib/scriblib/bibtex.rkt b/scribble-lib/scriblib/bibtex.rkt
@@ -209,7 +209,7 @@
(λ (key)
(and (not (string=? "\n" key))
(generate-bib bibtex-db key)))
- (append-map (curry regexp-split #rx" +")
+ (append-map (curry regexp-split #px"\\s+")
(cons f r)))))
(define ~cite-id (make-citer autobib-cite))
(define citet-id (make-citer autobib-citet))))
@@ -217,9 +217,9 @@
(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 #px"\\s+and\\s+" as))])
(define (trim s)
- (string-trim (regexp-replace #rx" +" s " ")))
+ (string-trim (regexp-replace #px"\\s+" s " ")))
(match a
[(pregexp #px"^(.*),(.*),(.*)$" (list _ two suffix one))
(author-name (trim one) (trim two) #:suffix (trim suffix))]
@@ -228,7 +228,7 @@
[(pregexp #px"^(.*) (von|de la|van der) (.*)$" (list _ one von-like two))
(author-name (string-trim one) (string-append von-like " " (string-trim two)))]
[space-separated
- (match (regexp-split #rx" +" space-separated)
+ (match (regexp-split #px"\\s+" space-separated)
[(list one) (org-author-name one)]
[(list one two) (author-name one two)]
[(list-rest first rest)
@@ -274,36 +274,96 @@
(check
print-as-equal-string?
+ (parse-author "Lst,Fst")
+ (authors
+ (author-name "Fst" "Lst")))
+
+ (check
+ print-as-equal-string?
(parse-author "James, Earl Jones")
(authors
(author-name "Earl Jones" "James")))
(check
print-as-equal-string?
+ (parse-author "James,Earl Jones")
+ (authors
+ (author-name "Earl Jones" "James")))
+
+ (check
+ print-as-equal-string?
(parse-author "LstA LstB, Fst")
(authors
(author-name "Fst" "LstA LstB")))
(check
print-as-equal-string?
+ (parse-author "LstA LstB,Fst")
+ (authors
+ (author-name "Fst" "LstA LstB")))
+
+ (check
+ print-as-equal-string?
(parse-author "LstA LstB, FstA FstB")
(authors
(author-name "FstA FstB" "LstA LstB")))
(check
print-as-equal-string?
+ (parse-author "LstA LstB,FstA FstB")
+ (authors
+ (author-name "FstA FstB" "LstA LstB")))
+
+ (check
+ print-as-equal-string?
(parse-author "James, Jr, Earl Jones")
(authors
(author-name "Earl Jones" "James" #:suffix "Jr")))
(check
print-as-equal-string?
+ (parse-author "James,Jr, Earl Jones")
+ (authors
+ (author-name "Earl Jones" "James" #:suffix "Jr")))
+
+ (check
+ print-as-equal-string?
+ (parse-author "James, Jr,Earl Jones")
+ (authors
+ (author-name "Earl Jones" "James" #:suffix "Jr")))
+
+ (check
+ print-as-equal-string?
+ (parse-author "James,Jr,Earl Jones")
+ (authors
+ (author-name "Earl Jones" "James" #:suffix "Jr")))
+
+ (check
+ print-as-equal-string?
(parse-author "James, III, Earl Jones")
(authors
(author-name "Earl Jones" "James" #:suffix "III")))
(check
print-as-equal-string?
+ (parse-author "James,III, Earl Jones")
+ (authors
+ (author-name "Earl Jones" "James" #:suffix "III")))
+
+ (check
+ print-as-equal-string?
+ (parse-author "James, III,Earl Jones")
+ (authors
+ (author-name "Earl Jones" "James" #:suffix "III")))
+
+ (check
+ print-as-equal-string?
+ (parse-author "James,III,Earl Jones")
+ (authors
+ (author-name "Earl Jones" "James" #:suffix "III")))
+
+ (check
+ print-as-equal-string?
(parse-author "James Jack von Earl Jones")
(authors
(author-name "James Jack" "von Earl Jones")))
@@ -326,7 +386,13 @@
(authors (author-name "Edward L." "Deci")
(author-name "Robert J." "Vallerand")
(author-name "Luc G." "Pelletier")
- (author-name "Richard M." "Ryan" #:suffix "Jr"))))
+ (author-name "Richard M." "Ryan" #:suffix "Jr")))
+
+ (check
+ print-as-equal-string?
+ (parse-author "Foo anderson") ;; Should not be parsed as the two authors "Foo" & "erson"
+ (authors
+ (author-name "Foo" "anderson"))))
(define (parse-pages ps)
(match ps