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 ;
9 TUPLE: string-reader { underlying string read-only } { i array-capacity } ;
11 M: string-reader stream-element-type drop +character+ ;
12 M: string-reader stream-read-partial stream-read ;
13 M: string-reader stream-read sequence-read ;
14 M: string-reader stream-read1 sequence-read1 ;
15 M: string-reader stream-read-until sequence-read-until ;
16 M: string-reader dispose drop ;
19 SINGLETON: null-encoding
20 M: null-encoding decode-char drop stream-read1 ;
23 : <string-reader> ( str -- stream )
24 0 string-reader boa null-encoding <decoder> ;
26 : with-string-reader ( str quot -- )
27 [ <string-reader> ] dip with-input-stream ; inline
30 M: sbuf stream-element-type drop +character+ ;
32 : <string-writer> ( -- stream )
35 : with-string-writer ( quot -- str )
37 swap with-output-stream*
38 ] keep >string ; inline