From f1bfc3c9cec26febfb37b585dc09b332231d55b6 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Sat, 25 Feb 2023 11:02:25 +0200 Subject: [PATCH] Improve parse-section-in-parentheses Recognize "foo(3scm)." in addition to "foo(3scm)," --- scm/html/man.scm | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scm/html/man.scm b/scm/html/man.scm index 1d59cff..a6706d5 100644 --- a/scm/html/man.scm +++ b/scm/html/man.scm @@ -162,16 +162,21 @@ (format #f "~a" url body))) (define (parse-section-in-parentheses str) + (define (is i choices) + (let ((char (string-ref str i))) + (let loop ((k 0)) + (and (< k (string-length choices)) + (or (char=? char (string-ref choices k)) + (loop (+ k 1))))))) (let* ((n (string-length str)) (r (and (>= n 3) - (char=? #\( (string-ref str 0)) - (char<=? #\1 (string-ref str 1)) - (char<=? (string-ref str 1) #\9) - (cond ((char=? #\) (string-ref str (- n 1))) + (is 0 "(") + (is 1 "123456789") + (cond ((is (- n 1) ")") 1) ((and (>= n 4) - (char=? #\) (string-ref str (- n 2))) - (char=? #\, (string-ref str (- n 1)))) + (is (- n 2) ")") + (is (- n 1) ",.")) 2) (else #f)))))