From e0dd3a2bae6bb97422b4fd7c14523778277ed78a Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Mon, 24 Jan 2000 17:07:29 +0000 Subject: [PATCH] ... original commit: 1c578b136fcf785a8584dae1282efe62e6dd0e05 --- collects/framework/guiutils.ss | 73 +++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/collects/framework/guiutils.ss b/collects/framework/guiutils.ss index 279d065d..b89b0c85 100644 --- a/collects/framework/guiutils.ss +++ b/collects/framework/guiutils.ss @@ -177,41 +177,48 @@ (send dialog show #t) result)])) - ;; better to treat all snips uniformly -- always processes text - ;; snips, etc. in certain way, rather than just the top-level ones. - ;; process sexp-snip<%> returned text%s as if top-level. (define read-snips/chars-from-text - (case-lambda - [(text) (read-snips/chars-from-text text 0)] - [(text start) (read-snips/chars-from-text text start (send text last-position))] - [(text start end) - (define pos-box (box 0)) - (define (get-next) - (let loop ([snip (send text find-snip start 'after-or-none pos-box)]) - (cond - [(not snip) - (set! get-next (lambda () eof)) - eof] - [(not (<= (+ (unbox pos-box) (send snip get-count)) end)) - (set! get-next (lambda () eof)) - eof] - [(is-a? snip string-snip%) - (let ([str (send snip get-text 0 (send snip get-count))]) - (let string-loop ([n 0]) - (cond - [(< n (string-length str)) - (set! get-next (lambda () (string-loop (+ n 1)))) - (string-ref str n)] - [else - (loop (send snip next))])))] - [else - (set! get-next (lambda () (loop (send snip next)))) - snip]))) - (let ([read-snips/chars-from-text-thunk - (lambda () - (get-next))]) - read-snips/chars-from-text-thunk)])) + (letrec ([get-snips + (lambda (text start end) + (let* ([pos-box (box 0)] + [snip (send text find-snip start 'after-or-none pos-box)]) + (cond + [(not snip) null] + [(> (+ (unbox pos-box) (send snip get-count)) end) null] + [else (cons snip (get-snips text (+ start (send snip get-count)) end))])))]) + (case-lambda + [(text) (read-snips/chars-from-text text 0)] + [(text start) (read-snips/chars-from-text text start (send text last-position))] + [(text start end) + (define pos-box (box 0)) + (define (get-next) + (send text split-snip start) + (send text split-snip end) + ;; must get all of the snips out of the buffer before reading -- they may change. + (let loop ([snips (get-snips text start end)]) + + (cond + [(null? snips) + (set! get-next (lambda () eof)) + eof] + [(is-a? (car snips) string-snip%) + (let ([str (send (car snips) get-text 0 (send (car snips) get-count))]) + (let string-loop ([n 0]) + (cond + [(< n (string-length str)) + (set! get-next (lambda () (string-loop (+ n 1)))) + (string-ref str n)] + [else + (loop (cdr snips))])))] + [else + (set! get-next (lambda () (loop (cdr snips)))) + (car snips)]))) + (let ([read-snips/chars-from-text-thunk + (lambda () + (get-next))]) + read-snips/chars-from-text-thunk)]))) + (define open-input-buffer (lambda (buffer) (let ([pos 0])