399
|
1 |
Stream subclass:#FilteringLineStream
|
|
2 |
instanceVariableNames:'lineBuffer inputStream outputStream filter'
|
|
3 |
classVariableNames:''
|
|
4 |
poolDictionaries:''
|
|
5 |
category:'Streams'
|
|
6 |
!
|
|
7 |
|
|
8 |
!FilteringLineStream class methodsFor:'documentation'!
|
|
9 |
|
|
10 |
examples
|
|
11 |
"
|
|
12 |
|in filter1 filter2|
|
|
13 |
|
|
14 |
in := 'Makefile' asFilename readStream.
|
|
15 |
|
|
16 |
filter1 := FilteringLineStream basicNew.
|
|
17 |
filter1 inputStream:in.
|
|
18 |
filter1 filter:[:line | (line startsWith:'#') ifTrue:[line] ifFalse:[nil]].
|
|
19 |
|
|
20 |
filter2 := FilteringLineStream basicNew.
|
|
21 |
filter2 filter:[:line | (line startsWith:'#-') ifTrue:[line] ifFalse:[nil]].
|
|
22 |
|
|
23 |
filter1 outputStream:filter2.
|
|
24 |
filter2 outputStream:Transcript.
|
|
25 |
|
|
26 |
filter1 filterUpToEnd
|
|
27 |
"
|
|
28 |
|
|
29 |
! !
|
|
30 |
|
|
31 |
!FilteringLineStream methodsFor:'access - pull-reading'!
|
|
32 |
|
|
33 |
filterUpToEnd
|
|
34 |
"pull input from inputStream up to the end,
|
|
35 |
push it filtered into the outputStream"
|
|
36 |
|
|
37 |
[inputStream atEnd] whileFalse:[
|
|
38 |
self nextPut:(inputStream next)
|
|
39 |
].
|
|
40 |
|
|
41 |
"Created: 2.7.1996 / 20:58:24 / cg"
|
|
42 |
"Modified: 2.7.1996 / 21:02:49 / cg"
|
|
43 |
! !
|
|
44 |
|
|
45 |
!FilteringLineStream methodsFor:'access - push-writing'!
|
|
46 |
|
|
47 |
cr
|
|
48 |
"finish a line, push it filtered into the outputStream"
|
|
49 |
|
|
50 |
|output|
|
|
51 |
|
|
52 |
lineBuffer isNil ifTrue:[lineBuffer := ''].
|
|
53 |
|
|
54 |
output := filter value:lineBuffer.
|
|
55 |
output notNil ifTrue:[
|
|
56 |
outputStream nextPutAll:output.
|
|
57 |
outputStream cr.
|
|
58 |
].
|
|
59 |
lineBuffer := ''.
|
|
60 |
|
|
61 |
"Created: 2.7.1996 / 20:55:53 / cg"
|
|
62 |
"Modified: 2.7.1996 / 21:03:07 / cg"
|
|
63 |
!
|
|
64 |
|
|
65 |
nextPut:something
|
|
66 |
"collect a line and push it when a cr arrives"
|
|
67 |
|
|
68 |
something == Character cr ifTrue:[
|
|
69 |
self cr
|
|
70 |
] ifFalse:[
|
|
71 |
lineBuffer isNil ifTrue:[lineBuffer := ''].
|
|
72 |
lineBuffer := lineBuffer copyWith:something.
|
|
73 |
]
|
|
74 |
|
|
75 |
"Created: 2.7.1996 / 20:54:38 / cg"
|
|
76 |
"Modified: 2.7.1996 / 21:03:26 / cg"
|
|
77 |
!
|
|
78 |
|
|
79 |
nextPutAll:something
|
|
80 |
"collect a line and push it when a cr arrives"
|
|
81 |
|
|
82 |
lineBuffer isNil ifTrue:[lineBuffer := ''].
|
|
83 |
lineBuffer := lineBuffer , something.
|
|
84 |
|
|
85 |
"Created: 2.7.1996 / 20:54:45 / cg"
|
|
86 |
"Modified: 2.7.1996 / 21:03:30 / cg"
|
|
87 |
! !
|
|
88 |
|
|
89 |
!FilteringLineStream methodsFor:'accessing'!
|
|
90 |
|
|
91 |
filter
|
|
92 |
"return the filter"
|
|
93 |
|
|
94 |
^ filter
|
|
95 |
|
|
96 |
"Created: 2.7.1996 / 20:56:55 / cg"
|
|
97 |
"Modified: 2.7.1996 / 21:03:36 / cg"
|
|
98 |
!
|
|
99 |
|
|
100 |
filter:something
|
|
101 |
"set the filter"
|
|
102 |
|
|
103 |
filter := something.
|
|
104 |
|
|
105 |
"Created: 2.7.1996 / 20:56:55 / cg"
|
|
106 |
"Modified: 2.7.1996 / 21:03:40 / cg"
|
|
107 |
!
|
|
108 |
|
|
109 |
inputStream
|
|
110 |
"return the inputStream"
|
|
111 |
|
|
112 |
^ inputStream
|
|
113 |
|
|
114 |
"Created: 2.7.1996 / 20:56:50 / cg"
|
|
115 |
"Modified: 2.7.1996 / 21:03:43 / cg"
|
|
116 |
!
|
|
117 |
|
|
118 |
inputStream:something
|
|
119 |
"set the inputStream"
|
|
120 |
|
|
121 |
inputStream := something.
|
|
122 |
|
|
123 |
"Created: 2.7.1996 / 20:56:50 / cg"
|
|
124 |
"Modified: 2.7.1996 / 21:03:46 / cg"
|
|
125 |
!
|
|
126 |
|
|
127 |
outputStream
|
|
128 |
"return the outputStream"
|
|
129 |
|
|
130 |
^ outputStream
|
|
131 |
|
|
132 |
"Created: 2.7.1996 / 20:56:53 / cg"
|
|
133 |
"Modified: 2.7.1996 / 21:03:49 / cg"
|
|
134 |
!
|
|
135 |
|
|
136 |
outputStream:something
|
|
137 |
"set the outputStream"
|
|
138 |
|
|
139 |
outputStream := something.
|
|
140 |
|
|
141 |
"Created: 2.7.1996 / 20:56:53 / cg"
|
|
142 |
"Modified: 2.7.1996 / 21:03:52 / cg"
|
|
143 |
! !
|
|
144 |
|
|
145 |
!FilteringLineStream class methodsFor:'documentation'!
|
|
146 |
|
|
147 |
version
|
|
148 |
^ '$Header: /cvs/stx/stx/libbasic2/FilteringLineStream.st,v 1.1 1996-07-02 19:04:45 cg Exp $'
|
|
149 |
! !
|