]> gitweb.factorcode.org Git - factor.git/blob - basis/io/streams/string/string.factor
Remove stream-peek and stream-peek1, re-implement dns vocab to not need this abstraction
[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 io.private ;
7 IN: io.streams.string
8
9 ! Readers
10 TUPLE: string-reader { underlying string read-only } { i array-capacity } ;
11
12 M: string-reader stream-element-type drop +character+ ;
13 M: string-reader stream-read-partial stream-read ;
14 M: string-reader stream-read sequence-read ;
15 M: string-reader stream-read1 sequence-read1 ;
16 M: string-reader stream-read-until sequence-read-until ;
17 M: string-reader stream-tell i>> ;
18 M: string-reader stream-seek (stream-seek) ;
19 M: string-reader dispose drop ;
20
21 <PRIVATE
22 SINGLETON: null-encoding
23 M: null-encoding decode-char drop stream-read1 ;
24 PRIVATE>
25
26 : <string-reader> ( str -- stream )
27     0 string-reader boa null-encoding <decoder> ;
28
29 : with-string-reader ( str quot -- )
30     [ <string-reader> ] dip with-input-stream ; inline
31
32 ! Writers
33 M: sbuf stream-element-type drop +character+ ;
34
35 : <string-writer> ( -- stream )
36     512 <sbuf> ;
37
38 : with-string-writer ( quot -- str )
39     <string-writer> [
40         swap with-output-stream*
41     ] keep >string ; inline