diff --git a/core/io/streams/string/string.factor b/core/io/streams/string/string.factor index b2b75509e9..184b5e1c15 100644 --- a/core/io/streams/string/string.factor +++ b/core/io/streams/string/string.factor @@ -5,6 +5,33 @@ strings generic splitting continuations destructors io.streams.plain io.encodings math.order growable ; IN: io.streams.string +> 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 [ zero? ] r> compose 2map ; inline + +: format-table ( table -- seq ) + flip [ format-column ] map-last + flip [ " " join ] map ; + +PRIVATE> + M: growable dispose drop ; M: growable stream-write1 push ; @@ -20,12 +47,6 @@ M: growable stream-flush drop ; 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 ) swap [ memq? ] curry find-last drop ; @@ -50,30 +71,14 @@ M: growable stream-read M: growable stream-read-partial stream-read ; -SINGLETON: null -M: null decode-char drop stream-read1 ; - : ( str -- stream ) - >sbuf dup reverse-here null ; + >sbuf dup reverse-here null-encoding ; : with-string-reader ( str quot -- ) >r r> with-input-stream ; inline 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 [ zero? ] r> compose 2map ; inline - -: format-table ( table -- seq ) - flip [ format-column ] map-last - flip [ " " join ] map ; - M: plain-writer stream-write-table [ drop format-table [ print ] each ] with-output-stream* ;