| 
									
										
										
										
											2009-02-27 01:53:05 -05:00
										 |  |  | ! 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. | 
					
						
							| 
									
										
										
										
											2008-06-28 03:36:20 -04:00
										 |  |  | USING: accessors io kernel math namespaces sequences sbufs | 
					
						
							| 
									
										
										
										
											2009-02-27 01:53:05 -05:00
										 |  |  | 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 | 
					
						
							| 
									
										
										
										
											2008-01-31 01:52:06 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-15 18:11:18 -04:00
										 |  |  | ! Readers | 
					
						
							| 
									
										
										
										
											2009-02-27 01:53:05 -05:00
										 |  |  | TUPLE: string-reader { underlying string read-only } { i array-capacity } ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-15 18:11:18 -04:00
										 |  |  | M: string-reader stream-element-type drop +character+ ;
 | 
					
						
							| 
									
										
										
										
											2009-02-27 01:53:05 -05: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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-15 18:11:18 -04:00
										 |  |  | <PRIVATE
 | 
					
						
							|  |  |  | SINGLETON: null-encoding | 
					
						
							|  |  |  | M: null-encoding decode-char drop stream-read1 ;
 | 
					
						
							|  |  |  | PRIVATE>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : <string-reader> ( str -- stream )
 | 
					
						
							| 
									
										
										
										
											2009-02-27 01:53:05 -05:00
										 |  |  |     0 string-reader boa null-encoding <decoder> ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-15 23:20:31 -05:00
										 |  |  | : with-string-reader ( str quot -- )
 | 
					
						
							| 
									
										
										
										
											2008-11-23 03:44:56 -05:00
										 |  |  |     [ <string-reader> ] dip with-input-stream ; inline
 | 
					
						
							| 
									
										
										
										
											2008-02-21 16:22:49 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-15 18:11:18 -04:00
										 |  |  | ! Writers | 
					
						
							|  |  |  | M: sbuf stream-element-type drop +character+ ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : <string-writer> ( -- stream )
 | 
					
						
							|  |  |  |     512 <sbuf> ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : with-string-writer ( quot -- str )
 | 
					
						
							| 
									
										
										
										
											2009-04-20 21:05:17 -04:00
										 |  |  |     <string-writer> [ | 
					
						
							|  |  |  |         swap with-output-stream*
 | 
					
						
							|  |  |  |     ] keep >string ; inline
 |