138 |
138 |
139 !Stream methodsFor:'accessing'! |
139 !Stream methodsFor:'accessing'! |
140 |
140 |
141 contents |
141 contents |
142 "return the entire contents of the stream |
142 "return the entire contents of the stream |
143 - we do not know here how to do it, it must be redefined in subclass" |
143 - we do not know here how to do it, it must be redefined in subclasses." |
144 |
144 |
145 ^ self subclassResponsibility |
145 ^ self subclassResponsibility |
|
146 |
|
147 "Modified: 15.5.1996 / 17:36:29 / cg" |
146 ! |
148 ! |
147 |
149 |
148 signalAtEnd |
150 signalAtEnd |
149 "return signalAtEnd" |
151 "return the signalAtEnd flag setting. If true, reading past the end |
|
152 will raise an EndOfStream exception. If false, no exception is |
|
153 raised and nil is returned from all reading messages. |
|
154 The default is (currently) to NOT raise a signal." |
150 |
155 |
151 ^ signalAtEnd |
156 ^ signalAtEnd |
152 |
157 |
153 "Created: 5.2.1996 / 18:24:53 / stefan" |
158 "Created: 5.2.1996 / 18:24:53 / stefan" |
154 ! |
159 "Modified: 15.5.1996 / 17:35:55 / cg" |
155 |
160 ! |
156 signalAtEnd:something |
161 |
157 "set signalAtEnd" |
162 signalAtEnd:aBoolean |
158 |
163 "set the signalAtEnd flag setting. If true, reading past the end |
159 signalAtEnd := something. |
164 will raise an EndOfStream exception. If false, no exception is |
|
165 raised and nil is returned from all reading messages. |
|
166 The default is (currently) to NOT raise a signal." |
|
167 |
|
168 signalAtEnd := aBoolean. |
160 |
169 |
161 "Created: 5.2.1996 / 18:24:53 / stefan" |
170 "Created: 5.2.1996 / 18:24:53 / stefan" |
|
171 "Modified: 15.5.1996 / 17:36:12 / cg" |
162 ! ! |
172 ! ! |
163 |
173 |
164 !Stream methodsFor:'closing'! |
174 !Stream methodsFor:'closing'! |
165 |
175 |
166 close |
176 close |
261 ! ! |
271 ! ! |
262 |
272 |
263 !Stream methodsFor:'misc'! |
273 !Stream methodsFor:'misc'! |
264 |
274 |
265 binary |
275 binary |
266 "switch to binary mode. ignored here, but added to make |
276 "switch to binary mode. In binary mode, reading of text streams |
267 internalStreams protocol compatible with externStreams." |
277 returns byte-valued integers instead of characters; writing expects |
268 |
278 byte-valued integers respectively. |
|
279 Ignored here, but added to make internalStreams protocol compatible |
|
280 with externalStreams." |
|
281 |
|
282 "Modified: 15.5.1996 / 17:38:36 / cg" |
269 ! ! |
283 ! ! |
270 |
284 |
271 !Stream methodsFor:'non homogenous reading'! |
285 !Stream methodsFor:'non homogenous reading'! |
|
286 |
|
287 nextAlphaNumericWord |
|
288 "read the next word (i.e. up to non letter-or-digit). |
|
289 Return a string containing those characters. |
|
290 Any leading whitespace is skipped. |
|
291 This method does not advance over any non-alphanumeric characters; |
|
292 i.e. it will stick and continue to continue to return nil in |
|
293 this case. Only call for it in a loop, AFTER you have checked for |
|
294 the next character to really be alphanumeric (using #peek)" |
|
295 |
|
296 |s c| |
|
297 |
|
298 [self atEnd not |
|
299 and:[(c := self peek) isSeparator]] whileTrue:[ |
|
300 self next |
|
301 ]. |
|
302 |
|
303 self atEnd ifTrue:[^ nil]. |
|
304 |
|
305 s := ''. |
|
306 |
|
307 [self atEnd not |
|
308 and:[(c := self peek) isLetterOrDigit]] whileTrue:[ |
|
309 s := s copyWith:c. |
|
310 self next |
|
311 ]. |
|
312 |
|
313 s size == 0 ifTrue:[^ nil]. |
|
314 ^ s. |
|
315 |
|
316 " |
|
317 |s| |
|
318 |
|
319 s := 'hello world 1234 foo1 foo2' readStream. |
|
320 [s atEnd] whileFalse:[ |
|
321 Transcript showCr:(s nextAlphaNumericWord). |
|
322 ]. |
|
323 |
|
324 |
|
325 notice: streams end never reached this way (sticking at the '+'-character: |
|
326 |s| |
|
327 |
|
328 s := 'hello world 1234 foo1+foo2' readStream. |
|
329 10 timesRepeat:[ |
|
330 Transcript showCr:(s nextAlphaNumericWord). |
|
331 ]. |
|
332 " |
|
333 |
|
334 "Modified: 15.5.1996 / 17:50:32 / cg" |
|
335 ! |
272 |
336 |
273 nextLine |
337 nextLine |
274 "return the characters upTo (but excluding) the next cr character. |
338 "return the characters upTo (but excluding) the next cr character. |
275 Added for protocol compatibility with externalStreams." |
339 Added for protocol compatibility with externalStreams." |
276 |
340 |