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

View File

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