[plt-scheme] peek-char skip behavior
On Wed, Jun 14, 2006 at 12:17:08AM -0400, David T. Pierson wrote:
> I would like to skip chars. I don't see a built-in function for doing
> this, so here's an attempt at rolling my own. Comments welcome.
Of course I realize after sending that my tests did not include a skip-k
beyond eof. Here's an implementation that checks for eof:
(define (peek-char/skip-chars iport skip-k)
(let loop ((chars-to-skip skip-k)
(bytes-to-skip 0))
(let ((c (peek-char iport bytes-to-skip)))
(cond
((eof-object? c)
c)
((= 0 chars-to-skip)
c)
(else
(loop (- chars-to-skip 1)
(+ bytes-to-skip (char-utf-8-length c))))))))
David