1 ! Copyright (C) 2003, 2009 Slava Pestov, Daniel Ehrenberg.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors io kernel math namespaces sequences sbufs
4 strings generic splitting continuations destructors sequences.private
5 io.streams.plain io.encodings math.order growable io.streams.sequence ;
10 SINGLETON: null-encoding
12 M: null-encoding decode-char drop stream-read1 ;
16 M: growable dispose drop ;
18 M: growable stream-write1 push ;
19 M: growable stream-write push-all ;
20 M: growable stream-flush drop ;
22 : <string-writer> ( -- stream )
25 : with-string-writer ( quot -- str )
26 <string-writer> swap [ output-stream get ] compose with-output-stream*
31 TUPLE: string-reader { underlying string read-only } { i array-capacity } ;
33 M: string-reader stream-read-partial stream-read ;
34 M: string-reader stream-read sequence-read ;
35 M: string-reader stream-read1 sequence-read1 ;
36 M: string-reader stream-read-until sequence-read-until ;
37 M: string-reader dispose drop ;
39 : <string-reader> ( str -- stream )
40 0 string-reader boa null-encoding <decoder> ;
42 : with-string-reader ( str quot -- )
43 [ <string-reader> ] dip with-input-stream ; inline
45 INSTANCE: growable plain-writer