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-readln { input-port utf8 } { input-port ascii } ;
|
||||
|
||||
HINTS: M\ input-port stream-read-partial-unsafe
|
||||
{ fixnum byte-array input-port }
|
||||
{ fixnum string input-port } ;
|
||||
|
|
|
@ -111,28 +111,20 @@ M: decoder stream-contents*
|
|||
{ CHAR: \n [ line-ends\n ] }
|
||||
} 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 f, returns ``string f'' or ``f f''
|
||||
: read-until-loop ( buf quot: ( -- char stop? ) -- string/f sep/f )
|
||||
dup call
|
||||
[ nip [ "" like ] dip [ f like f ] unless* ]
|
||||
[ 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) ( quot: ( -- char stop? ) -- string/f sep/f )
|
||||
[ 100 <sbuf> ] dip over [ push ] curry until
|
||||
[ "" like ] dip [ f like f ] unless* ; inline
|
||||
|
||||
: decoder-read-until ( seps stream encoding -- string/f sep/f )
|
||||
[ decode-char dup [ dup rot member? ] [ 2drop f t ] if ] 3curry
|
||||
(read-until) ;
|
||||
[ decode-char dup ] 2curry swap [ dupd member? ] curry
|
||||
[ [ drop f t ] if ] curry compose (decoder-read-until) ; inline
|
||||
|
||||
M: decoder stream-read-until >decoder< decoder-read-until ;
|
||||
|
||||
: decoder-readln ( stream encoding -- string/f sep/f )
|
||||
[ decode-char dup [ dup "\r\n" member? ] [ drop f t ] if ] 2curry
|
||||
(read-until) ;
|
||||
|
||||
M: decoder stream-readln dup >decoder< decoder-readln handle-readln ;
|
||||
M: decoder stream-readln
|
||||
"\r\n" over >decoder< decoder-read-until handle-readln ;
|
||||
|
||||
M: decoder dispose stream>> dispose ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue