commit ef09ef12335cb0501c9de17f8a4e8090421c2dfd
parent 247adff668154a3334ccb2607b6078a29bdeea37
Author: Tomas Hlavaty <tom@logand.com>
Date: Mon, 19 Aug 2013 21:41:09 +0200
rw:till and rw:skip need rw:peek-reader, wraping in place where used
Diffstat:
2 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/email.lisp b/email.lisp
@@ -30,11 +30,11 @@
;;(with-open-file (s "~/Mail/goethe/27") (rw:till (rw:peek-reader (rw:char-reader s))))
(defun header-reader (reader)
- (flet ((peek () (rw:peek reader))
- (next () (rw:next reader))
- (skip () (rw:skip reader))
- (till (items) (rw:till reader items)))
- (let (eof)
+ (let (eof (r (rw:peek-reader reader)))
+ (flet ((peek () (rw:peek r))
+ (next () (rw:next r))
+ (skip () (rw:skip r))
+ (till (items) (rw:till r items)))
(lambda ()
(or eof
(case (peek)
@@ -55,7 +55,7 @@
(line))))))))))))
(defun header-alist (reader)
- (rw:till (rw:peek-reader (header-reader (rw:peek-reader (rw:char-reader reader))))))
+ (rw:till (rw:peek-reader (header-reader (rw:char-reader reader)))))
(defun content-type (reader)
(flet ((peek () (rw:peek reader))
diff --git a/rw.lisp b/rw.lisp
@@ -106,7 +106,7 @@
;;(with-open-file (s "/etc/passwd") (till (peek-reader (char-reader s)) '(#\:)))
(defun search-reader (reader needle)
- (let ((all (till reader)) ;; TODO optimize? use kmp algorithm
+ (let ((all (till (peek-reader reader))) ;; TODO optimize? use kmp algorithm
(start 0))
(lambda ()
(let? i (search needle all :start2 start)
@@ -181,10 +181,11 @@
;; TODO write-s8|16|32|64|128
(defun line-reader (reader)
- (lambda ()
- (let ((x (till reader '(#\newline))))
- (when (next reader)
- (or x :empty-line)))))
+ (let ((r (peek-reader reader)))
+ (lambda ()
+ (let ((x (till r '(#\newline))))
+ (when (next r)
+ (or x :empty-line))))))
(defun filter-reader (reader predicate)
(lambda ()