--- a/FilteringLineStream.st Thu Nov 08 16:31:12 2001 +0100
+++ b/FilteringLineStream.st Thu Nov 08 16:34:27 2001 +0100
@@ -1,5 +1,3 @@
-"{ Package: 'stx:goodies' }"
-
"
COPYRIGHT (c) 1996 by Claus Gittinger
All Rights Reserved
@@ -14,6 +12,8 @@
+"{ Package: 'stx:goodies' }"
+
FilteringStream subclass:#FilteringLineStream
instanceVariableNames:'lineBuffer lineFilter'
classVariableNames:''
@@ -69,17 +69,32 @@
pushing the contents of a stream onto another stream
(here, the Transcript) without a need to read everyting into a
buffer or to reinvent the read-loop:
- [exBegin]
+ [exBegin]
|in pusher|
in := 'Makefile' asFilename readStream.
pusher := FilteringLineStream readingFrom:in writingTo:Transcript.
pusher filterUpToEnd
- [exEnd]
+ [exEnd]
+
+
+ filter through an ActorStream:
+ [exBegin]
+ |lineNr in pusher actorPerLine|
+
+ lineNr := 0.
+
+ actorPerLine := ActorStream new.
+ actorPerLine nextPutLineBlock:[:line | lineNr := lineNr + 1. Transcript show:lineNr; showCR:line].
+
+ in := 'Makefile' asFilename readStream.
+ pusher := FilteringLineStream readingFrom:in writingTo:actorPerLine.
+ pusher filterUpToEnd
+ [exEnd]
filter all comments (starting with '#') from a Makefile:
- [exBegin]
+ [exBegin]
|in filter|
in := 'Makefile' asFilename readStream.
@@ -90,11 +105,11 @@
filter outputStream:Transcript.
filter filterUpToEnd
- [exEnd]
+ [exEnd]
the inverse - remove all comments from the Makefile:
- [exBegin]
+ [exBegin]
|in filter|
in := 'Makefile' asFilename readStream.
@@ -105,12 +120,12 @@
filter outputStream:Transcript.
filter filterUpToEnd
- [exEnd]
+ [exEnd]
feed a second filter from the first filters output;
(the remains are all lines starting with '#' and ending with '-'):
- [exBegin]
+ [exBegin]
|in filter1 filter2|
in := 'Makefile' asFilename readStream.
@@ -124,9 +139,8 @@
filter2 outputStream:Transcript.
filter2 filterUpToEnd
- [exEnd]
+ [exEnd]
"
-
! !
!FilteringLineStream methodsFor:'access - pull-reading'!
@@ -150,18 +164,14 @@
|output|
lineFilter isNil ifTrue:[
- lineBuffer notNil ifTrue:[
- outputStream nextPutAll:lineBuffer
- ].
- outputStream cr
+ outputStream nextPutLine:(lineBuffer ? '')
] ifFalse:[
- lineBuffer isNil ifTrue:[lineBuffer := ''].
+ lineBuffer isNil ifTrue:[lineBuffer := ''].
- output := lineFilter value:lineBuffer.
- output notNil ifTrue:[
- outputStream nextPutAll:output.
- outputStream cr.
- ]
+ output := lineFilter value:lineBuffer.
+ output notNil ifTrue:[
+ outputStream nextPutLine:output.
+ ]
].
lineBuffer := ''.
@@ -215,5 +225,5 @@
!FilteringLineStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/FilteringLineStream.st,v 1.5 2000-03-02 14:15:07 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/FilteringLineStream.st,v 1.6 2001-11-08 15:34:27 md Exp $'
! !