Rename io.streams.string:null to null-encoding

db4
Slava Pestov 2008-11-16 05:59:38 -06:00
parent 9c84ad8944
commit 99fd539b01
1 changed files with 28 additions and 23 deletions

View File

@ -5,6 +5,33 @@ strings generic splitting continuations destructors
io.streams.plain io.encodings math.order growable ; io.streams.plain io.encodings math.order growable ;
IN: io.streams.string IN: io.streams.string
<PRIVATE
: harden-as ( seq growble-exemplar -- newseq )
underlying>> like ;
: growable-read-until ( growable n -- str )
>fixnum dupd tail-slice swap harden-as dup reverse-here ;
SINGLETON: null-encoding
M: null-encoding decode-char drop stream-read1 ;
: format-column ( seq ? -- seq )
[
[ 0 [ length max ] reduce ] keep
swap [ CHAR: \s pad-right ] curry map
] unless ;
: map-last ( seq quot -- seq )
>r dup length <reversed> [ zero? ] r> compose 2map ; inline
: format-table ( table -- seq )
flip [ format-column ] map-last
flip [ " " join ] map ;
PRIVATE>
M: growable dispose drop ; M: growable dispose drop ;
M: growable stream-write1 push ; M: growable stream-write1 push ;
@ -20,12 +47,6 @@ M: growable stream-flush drop ;
M: growable stream-read1 [ f ] [ pop ] if-empty ; M: growable stream-read1 [ f ] [ pop ] if-empty ;
: harden-as ( seq growble-exemplar -- newseq )
underlying>> like ;
: growable-read-until ( growable n -- str )
>fixnum dupd tail-slice swap harden-as dup reverse-here ;
: find-last-sep ( seq seps -- n ) : find-last-sep ( seq seps -- n )
swap [ memq? ] curry find-last drop ; swap [ memq? ] curry find-last drop ;
@ -50,30 +71,14 @@ M: growable stream-read
M: growable stream-read-partial M: growable stream-read-partial
stream-read ; stream-read ;
SINGLETON: null
M: null decode-char drop stream-read1 ;
: <string-reader> ( str -- stream ) : <string-reader> ( str -- stream )
>sbuf dup reverse-here null <decoder> ; >sbuf dup reverse-here null-encoding <decoder> ;
: with-string-reader ( str quot -- ) : with-string-reader ( str quot -- )
>r <string-reader> r> with-input-stream ; inline >r <string-reader> r> with-input-stream ; inline
INSTANCE: growable plain-writer INSTANCE: growable plain-writer
: format-column ( seq ? -- seq )
[
[ 0 [ length max ] reduce ] keep
swap [ CHAR: \s pad-right ] curry map
] unless ;
: map-last ( seq quot -- seq )
>r dup length <reversed> [ zero? ] r> compose 2map ; inline
: format-table ( table -- seq )
flip [ format-column ] map-last
flip [ " " join ] map ;
M: plain-writer stream-write-table M: plain-writer stream-write-table
[ drop format-table [ print ] each ] with-output-stream* ; [ drop format-table [ print ] each ] with-output-stream* ;