FilteringLineStream.st
changeset 473 cb46b0ba9934
parent 400 f61c18fd77be
child 474 61cb199537b5
--- a/FilteringLineStream.st	Fri Jan 10 21:51:24 1997 +0100
+++ b/FilteringLineStream.st	Sat Jan 11 15:22:27 1997 +0100
@@ -1,3 +1,17 @@
+"
+ COPYRIGHT (c) 1996 by Claus Gittinger
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+
+
+
 FilteringStream subclass:#FilteringLineStream
 	instanceVariableNames:'lineBuffer'
 	classVariableNames:''
@@ -5,12 +19,53 @@
 	category:'Streams'
 !
 
-!FilteringLineStream  class methodsFor:'documentation'!
+!FilteringLineStream class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 1996 by Claus Gittinger
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+
+
+!
+
+documentation
+"
+    A FilteringLineStream is much like a FilteringStream, but
+    processes its input line-wise.
+
+    A FilteringLineStream can be connected to some input
+    (from which characters are read via the ReadStream protocol),
+    and/or to some output (to which characters are written via
+    the WriteStream protocol.
+
+    The FilteringLineStream itself performs some filtering/processing
+    on the elements as they arrive, optionally suppressing filtering
+    (i.e. removing) some elements.
+
+
+    [author:]
+        Claus Gittinger
+
+    [See also:]
+        FilteringStream ReadStream WriteStream
+"
+
+
+!
 
 examples
 "
-  filter all comments from a file:
-
+  filter all comments (starting with '#') from a Makefile:
+                                                        [exBegin]
     |in filter|
 
     in := 'Makefile' asFilename readStream.
@@ -22,25 +77,45 @@
     filter outputStream:Transcript.
 
     filter filterUpToEnd
+                                                        [exEnd]
 
 
-  feed a second filter from the first filters output:
+  the inverse - remove all comments from the Makefile:
+                                                        [exBegin]
+    |in filter|
+
+    in := 'Makefile' asFilename readStream.
+
+    filter := FilteringLineStream basicNew.
+    filter inputStream:in.
+    filter filter:[:line | (line startsWith:'#') ifTrue:[nil] ifFalse:[line]].
 
+    filter outputStream:Transcript.
+
+    filter filterUpToEnd
+                                                        [exEnd]
+
+
+  feed a second filter from the first filters output;
+  (the remains are all lines starting with '#' and ending with '-'):
+                                                        [exBegin]
     |in filter1 filter2|
 
     in := 'Makefile' asFilename readStream.
 
     filter1 := FilteringLineStream basicNew.
+
     filter1 inputStream:in.
     filter1 filter:[:line | (line startsWith:'#') ifTrue:[line] ifFalse:[nil]].
 
     filter2 := FilteringLineStream basicNew.
-    filter2 filter:[:line | (line startsWith:'#-') ifTrue:[line] ifFalse:[nil]].
+    filter2 filter:[:line | (line endsWith:'-') ifTrue:[line] ifFalse:[nil]].
 
     filter1 outputStream:filter2.
     filter2 outputStream:Transcript.
 
     filter1 filterUpToEnd
+                                                        [exEnd]
 "
 
 ! !
@@ -89,8 +164,8 @@
     "Modified: 2.7.1996 / 21:03:30 / cg"
 ! !
 
-!FilteringLineStream  class methodsFor:'documentation'!
+!FilteringLineStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/FilteringLineStream.st,v 1.2 1996-07-02 19:27:59 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/FilteringLineStream.st,v 1.3 1997-01-11 14:22:27 cg Exp $'
 ! !