]> gitweb.factorcode.org Git - factor.git/blob - basis/io/streams/string/string.factor
Merge OneEyed's patch
[factor.git] / basis / io / streams / string / string.factor
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 ;
6 IN: io.streams.string
7
8 <PRIVATE
9
10 SINGLETON: null-encoding
11
12 M: null-encoding decode-char drop stream-read1 ;
13
14 PRIVATE>
15
16 M: growable dispose drop ;
17
18 M: growable stream-write1 push ;
19 M: growable stream-write push-all ;
20 M: growable stream-flush drop ;
21
22 : <string-writer> ( -- stream )
23     512 <sbuf> ;
24
25 : with-string-writer ( quot -- str )
26     <string-writer> swap [ output-stream get ] compose with-output-stream*
27     >string ; inline
28
29 ! New implementation
30
31 TUPLE: string-reader { underlying string read-only } { i array-capacity } ;
32
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 ;
38
39 : <string-reader> ( str -- stream )
40     0 string-reader boa null-encoding <decoder> ;
41
42 : with-string-reader ( str quot -- )
43     [ <string-reader> ] dip with-input-stream ; inline
44
45 INSTANCE: growable plain-writer