The following method for stream-read-char reads a character from the stream. If the character read is a
, then the method returns
, otherwise the character read is returned. stream-read-char returns
at the end of the file.
(defmethod stream:stream-read-char ((stream unicode-ls-stream))
(let ((char (read-char (ls-stream-file-stream stream)
(if (eq char #\Line-Separator)
There is no need to define a new method for stream-read-line as the default method uses stream-read-char repeatedly to read a line, and our implementation of stream-read-char ensures that this will work.
We also need to make sure that if a
is unread, it is unread as a
. The following method for
uses the Common Lisp file stream function
to achieve this.
(defmethod stream:stream-unread-char ((stream unicode-ls-stream)
(unread-char (if (eq char #\Newline) #\Line-Separator char)
Finally, although the default methods for
would work for our stream, it is faster to use the functions provided by
, again using our accessor
(defmethod stream:stream-listen ((stream unicode-ls-stream))
(listen (ls-stream-file-stream stream)))
(defmethod stream:stream-clear-input ((stream unicode-ls-stream))
(clear-input (ls-stream-file-stream stream)))
LispWorks User Guide and Reference Manual - 21 Dec 2011