io: minor cleanups.

db4
John Benediktsson 2014-02-25 10:04:08 -08:00
parent bf1f4e9aa2
commit b0195bb448
2 changed files with 11 additions and 10 deletions

View File

@ -106,8 +106,7 @@ M: decoder stream-element-type
: fix-cr ( decoder c -- c' )
over cr>> [
over cr-
dup CHAR: \n eq? [ drop (read1) ] [ nip ] if
over cr- dup CHAR: \n eq? [ drop (read1) ] [ nip ] if
] [ nip ] if ; inline
M: decoder stream-read1 ( decoder -- ch )
@ -151,8 +150,9 @@ M: decoder stream-contents*
: line-ends\r ( stream str -- str ) swap cr+ ; inline
: line-ends\n ( stream str -- str )
over cr>> over empty? and
[ drop dup cr- stream-readln ] [ swap cr- ] if ; inline
over cr>> [
over cr- [ stream-readln ] [ nip ] if-empty
] [ nip ] if ; inline
: handle-readln ( stream str ch -- str )
{
@ -188,6 +188,7 @@ M: encoder dispose stream>> dispose ; inline
M: encoder stream-flush stream>> stream-flush ; inline
INSTANCE: encoder plain-writer
PRIVATE>
GENERIC# re-encode 1 ( stream encoding -- newstream )

View File

@ -28,16 +28,16 @@ SLOT: i
[ [ dup pick + ] change-i underlying>> ] bi
[ <sequence-copy> (copy) drop ] 2curry keep ; inline
: check-byte-array ( buf -- buf )
dup byte-array? [ "not a byte array" throw ] unless ; inline
: check-byte-array ( buf stream -- buf stream )
over byte-array? [ "not a byte array" throw ] unless ; inline
: check-string ( buf -- buf )
dup string? [ "not a string" throw ] unless ; inline
: check-string ( buf stream -- buf stream )
over string? [ "not a string" throw ] unless ; inline
: (sequence-read-unsafe) ( n buf stream -- count )
[ integer>fixnum ] 2dip dup stream-element-type +byte+ eq?
[ [ check-byte-array ] dip ((sequence-read-unsafe)) ]
[ [ check-string ] dip ((sequence-read-unsafe)) ] if ; inline
[ check-byte-array ((sequence-read-unsafe)) ]
[ check-string ((sequence-read-unsafe)) ] if ; inline
PRIVATE>