mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2025-12-06 02:40:26 -08:00
streams: bring bivalent streams UNREAD-CHAR and UNREAD-BYTE together
This finishes the commit that adds unread-byte and peek-byte functions to the mix in that for bivalent stream UNREAD-BYTE will work for the subsequent READ-CHAR and vice versa. This also caters to transcoding etc.
This commit is contained in:
parent
b7eaf35502
commit
688eceb9ed
2 changed files with 7 additions and 10 deletions
|
|
@ -25,11 +25,8 @@ ecl_binary_read_byte(cl_object strm)
|
|||
unsigned char *buf = strm->stream.byte_buffer;
|
||||
cl_object byte;
|
||||
cl_index nbytes;
|
||||
byte = strm->stream.last_byte;
|
||||
unlikely_if (byte != OBJNULL) {
|
||||
strm->stream.last_byte = OBJNULL;
|
||||
return byte;
|
||||
}
|
||||
strm->stream.last_char = EOF;
|
||||
strm->stream.last_byte = OBJNULL;
|
||||
read_byte8 = strm->stream.ops->read_byte8;
|
||||
nbytes = strm->stream.byte_size/8;
|
||||
if (read_byte8(strm, buf, nbytes) < nbytes)
|
||||
|
|
@ -48,13 +45,11 @@ ecl_binary_write_byte(cl_object strm, cl_object byte)
|
|||
write_byte8(strm, buf, nbytes);
|
||||
}
|
||||
|
||||
/* FIXME this function should spill octets into the buffer like eformat does, so
|
||||
that when we read-char next, or change the element type and re-read byte, it
|
||||
will be possible to reinterpret these octets. */
|
||||
void
|
||||
ecl_binary_unread_byte(cl_object strm, cl_object byte)
|
||||
{
|
||||
unlikely_if (strm->stream.last_byte != OBJNULL) {
|
||||
unlikely_if (strm->stream.last_char != EOF
|
||||
|| strm->stream.last_byte != OBJNULL) {
|
||||
ecl_unread_twice(strm);
|
||||
}
|
||||
strm->stream.last_byte = byte;
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ ecl_eformat_read_char(cl_object strm)
|
|||
unsigned char *buffer_end = buffer;
|
||||
cl_index byte_size = (strm->stream.byte_size / 8);
|
||||
strm->stream.last_char = EOF;
|
||||
strm->stream.last_byte = OBJNULL;
|
||||
do {
|
||||
if (ecl_read_byte8(strm, buffer_end, byte_size) < byte_size) {
|
||||
c = EOF;
|
||||
|
|
@ -83,7 +84,8 @@ ecl_eformat_read_char(cl_object strm)
|
|||
void
|
||||
ecl_eformat_unread_char(cl_object strm, ecl_character c)
|
||||
{
|
||||
unlikely_if (strm->stream.last_char != EOF) {
|
||||
unlikely_if (strm->stream.last_char != EOF
|
||||
|| strm->stream.last_byte != OBJNULL) {
|
||||
ecl_unread_twice(strm);
|
||||
}
|
||||
strm->stream.last_char = c;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue