Cleaned up the CONSTANT-GLOB? function a bit.

This commit is contained in:
shivers 1997-10-06 21:14:20 +00:00
parent ff5d65fc30
commit 38c76cdf84
1 changed files with 10 additions and 14 deletions

View File

@ -129,21 +129,17 @@
;;; Is the glob pattern free of *'s, ?'s and [...]'s? ;;; Is the glob pattern free of *'s, ?'s and [...]'s?
(define (constant-glob? pattern) (define (constant-glob? pattern)
(let ((patlen (string-length pattern))) (let ((patlen (string-length pattern)))
(let lp ((i 0) (let lp ((i 0))
(escape? #f)) ; Was last char an escape char (backslash)? (or (= i patlen)
(if (= i patlen)
(if escape?
(error "Ill-formed glob pattern" pattern)
#t)
(let ((next-i (+ i 1))) (let ((next-i (+ i 1)))
(if escape? (lp next-i #f) (case (string-ref pattern i)
(case (string-ref pattern i) ((#\\) ; Escape char
((#\* #\? #\[) #f) (if (= next-i patlen)
((#\\) (lp next-i #t)) (error "Ill-formed glob pattern -- ends in backslash"
(else (lp next-i #f))) pattern)
(lp next-i #f))))))) (lp (+ next-i 1))))
((#\* #\? #\[) #f)
(else (lp next-i))))))))
;;; Make an effort to get the files in the putative directory PATH. ;;; Make an effort to get the files in the putative directory PATH.