summaryrefslogtreecommitdiffstats
path: root/strsrch.scm
diff options
context:
space:
mode:
Diffstat (limited to 'strsrch.scm')
-rw-r--r--strsrch.scm19
1 files changed, 11 insertions, 8 deletions
diff --git a/strsrch.scm b/strsrch.scm
index 68bcf0e..a6ab7e1 100644
--- a/strsrch.scm
+++ b/strsrch.scm
@@ -5,7 +5,7 @@
; This code is in the public domain.
;;; Return the index of the first occurence of a-char in str, or #f
-(define (string-index str a-char)
+(define (strsrch:string-index str a-char)
(let loop ((pos 0))
(cond
;; whole string has been searched, in vain
@@ -40,7 +40,7 @@
(c2 (if (<= pat-len 1) #f (string-ref pattern 1))))
(cond
((not c1) 0) ; empty pattern, matches upfront
- ((not c2) (string-index str c1)) ; one-char pattern
+ ((not c2) (strsrch:string-index str c1)) ; one-char pattern
(else ; matching pattern of > two chars
(let outer ((pos 0))
(cond
@@ -66,16 +66,19 @@
(set! max-no-char (if (null? max-no-char) #f (car max-no-char)))
(letrec
((no-chars-read 0)
+ (peeked? #f)
(my-peek-char ; Return a peeked char or #f
(lambda () (and (or (not (number? max-no-char))
(< no-chars-read max-no-char))
(let ((c (peek-char <input-port>)))
- (and (not (eof-object? c))
- (if (procedure? max-no-char)
- (not (max-no-char c))
- (not (eqv? max-no-char c)))
- c)))))
- (next-char (lambda () (read-char <input-port>)
+ (cond (peeked? c)
+ ((eof-object? c) #f)
+ ((procedure? max-no-char)
+ (set! peeked? #t)
+ (if (max-no-char c) #f c))
+ ((eqv? max-no-char c) #f)
+ (else c))))))
+ (next-char (lambda () (set! peeked? #f) (read-char <input-port>)
(set! no-chars-read (+ 1 no-chars-read))))
(match-1st-char ; of the string str
(lambda ()