2005-06-19 18:31:02 -04:00
|
|
|
USING: io kernel math namespaces sequences strings ;
|
|
|
|
|
|
|
|
! String buffers support the stream output protocol.
|
2005-07-17 14:48:55 -04:00
|
|
|
M: sbuf stream-write1 push ;
|
2005-07-21 21:43:37 -04:00
|
|
|
M: sbuf stream-format rot nappend drop ;
|
2005-06-19 18:31:02 -04:00
|
|
|
M: sbuf stream-close drop ;
|
|
|
|
M: sbuf stream-flush drop ;
|
2005-07-21 21:05:17 -04:00
|
|
|
M: sbuf stream-finish drop ;
|
2005-06-19 18:31:02 -04:00
|
|
|
|
|
|
|
: string-out ( quot -- str )
|
|
|
|
[ 512 <sbuf> stdio set call stdio get >string ] with-scope ;
|
|
|
|
|
|
|
|
! Reversed string buffers support the stream input protocol.
|
|
|
|
M: sbuf stream-read1 ( sbuf -- char/f )
|
|
|
|
dup empty? [ drop f ] [ pop ] ifte ;
|
|
|
|
|
|
|
|
M: sbuf stream-read ( count sbuf -- string )
|
|
|
|
dup empty? [
|
|
|
|
2drop f
|
|
|
|
] [
|
|
|
|
swap over length min empty-sbuf
|
|
|
|
[ [ drop dup pop ] nmap drop ] keep
|
|
|
|
] ifte ;
|
|
|
|
|
|
|
|
: <string-reader> ( string -- stream )
|
2005-07-16 22:16:18 -04:00
|
|
|
<reversed> >sbuf <line-reader> ;
|
2005-06-19 18:31:02 -04:00
|
|
|
|
|
|
|
: string-in ( str quot -- )
|
|
|
|
[ swap <string-reader> stdio set call ] with-scope ;
|