io.encodings: remove duplication in decoder-readln.
parent
d4b47612e1
commit
86b2dea8d5
|
@ -232,8 +232,6 @@ M: object underlying-handle underlying-port handle>> ;
|
||||||
|
|
||||||
HINTS: decoder-read-until { string input-port utf8 } { string input-port ascii } ;
|
HINTS: decoder-read-until { string input-port utf8 } { string input-port ascii } ;
|
||||||
|
|
||||||
HINTS: decoder-readln { input-port utf8 } { input-port ascii } ;
|
|
||||||
|
|
||||||
HINTS: M\ input-port stream-read-partial-unsafe
|
HINTS: M\ input-port stream-read-partial-unsafe
|
||||||
{ fixnum byte-array input-port }
|
{ fixnum byte-array input-port }
|
||||||
{ fixnum string input-port } ;
|
{ fixnum string input-port } ;
|
||||||
|
|
|
@ -111,28 +111,20 @@ M: decoder stream-contents*
|
||||||
{ CHAR: \n [ line-ends\n ] }
|
{ CHAR: \n [ line-ends\n ] }
|
||||||
} case ; inline
|
} case ; inline
|
||||||
|
|
||||||
! If the stop? branch is taken convert the sbuf to a string
|
|
||||||
! If sep is present, returns ``string sep'' (string can be "")
|
! If sep is present, returns ``string sep'' (string can be "")
|
||||||
! If sep is f, returns ``string f'' or ``f f''
|
! If sep is f, returns ``string f'' or ``f f''
|
||||||
: read-until-loop ( buf quot: ( -- char stop? ) -- string/f sep/f )
|
: (decoder-read-until) ( quot: ( -- char stop? ) -- string/f sep/f )
|
||||||
dup call
|
[ 100 <sbuf> ] dip over [ push ] curry until
|
||||||
[ nip [ "" like ] dip [ f like f ] unless* ]
|
[ "" like ] dip [ f like f ] unless* ; inline
|
||||||
[ pick push read-until-loop ] if ; inline recursive
|
|
||||||
|
|
||||||
: (read-until) ( quot -- string/f sep/f )
|
|
||||||
[ 100 <sbuf> ] dip read-until-loop ; inline
|
|
||||||
|
|
||||||
: decoder-read-until ( seps stream encoding -- string/f sep/f )
|
: decoder-read-until ( seps stream encoding -- string/f sep/f )
|
||||||
[ decode-char dup [ dup rot member? ] [ 2drop f t ] if ] 3curry
|
[ decode-char dup ] 2curry swap [ dupd member? ] curry
|
||||||
(read-until) ;
|
[ [ drop f t ] if ] curry compose (decoder-read-until) ; inline
|
||||||
|
|
||||||
M: decoder stream-read-until >decoder< decoder-read-until ;
|
M: decoder stream-read-until >decoder< decoder-read-until ;
|
||||||
|
|
||||||
: decoder-readln ( stream encoding -- string/f sep/f )
|
M: decoder stream-readln
|
||||||
[ decode-char dup [ dup "\r\n" member? ] [ drop f t ] if ] 2curry
|
"\r\n" over >decoder< decoder-read-until handle-readln ;
|
||||||
(read-until) ;
|
|
||||||
|
|
||||||
M: decoder stream-readln dup >decoder< decoder-readln handle-readln ;
|
|
||||||
|
|
||||||
M: decoder dispose stream>> dispose ;
|
M: decoder dispose stream>> dispose ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue