factor/basis/io/streams/string/string.factor

46 lines
1.3 KiB
Factor
Raw Normal View History

! Copyright (C) 2003, 2009 Slava Pestov, Daniel Ehrenberg.
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
USING: accessors io kernel math namespaces sequences sbufs
strings generic splitting continuations destructors sequences.private
io.streams.plain io.encodings math.order growable io.streams.sequence ;
2008-03-14 04:09:51 -04:00
IN: io.streams.string
<PRIVATE
SINGLETON: null-encoding
M: null-encoding decode-char drop stream-read1 ;
PRIVATE>
2008-02-15 22:49:53 -05:00
M: growable dispose drop ;
2007-09-20 18:09:08 -04:00
2008-02-15 22:49:53 -05:00
M: growable stream-write1 push ;
M: growable stream-write push-all ;
M: growable stream-flush drop ;
2007-09-20 18:09:08 -04:00
: <string-writer> ( -- stream )
2008-02-21 16:22:49 -05:00
512 <sbuf> ;
2007-09-20 18:09:08 -04:00
: with-string-writer ( quot -- str )
<string-writer> swap [ output-stream get ] compose with-output-stream*
2008-02-15 22:49:53 -05:00
>string ; inline
! New implementation
2007-09-20 18:09:08 -04:00
TUPLE: string-reader { underlying string read-only } { i array-capacity } ;
2007-09-20 18:09:08 -04:00
M: string-reader stream-read-partial stream-read ;
M: string-reader stream-read sequence-read ;
M: string-reader stream-read1 sequence-read1 ;
M: string-reader stream-read-until sequence-read-until ;
M: string-reader dispose drop ;
2007-09-20 18:09:08 -04:00
: <string-reader> ( str -- stream )
0 string-reader boa null-encoding <decoder> ;
2007-09-20 18:09:08 -04:00
: with-string-reader ( str quot -- )
[ <string-reader> ] dip with-input-stream ; inline
2008-02-21 16:22:49 -05:00
INSTANCE: growable plain-writer