author | Stefan Vogel <sv@exept.de> |
Tue, 16 Sep 2014 13:11:38 +0200 | |
changeset 16840 | 48075991f9d9 |
parent 16209 | f2d1d7b2d649 |
child 16876 | 7e3ad01ca413 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
5393
7e2230bd4bad
moved some stuff to superclass
Claus Gittinger <cg@exept.de>
parents:
5308
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
7e2230bd4bad
moved some stuff to superclass
Claus Gittinger <cg@exept.de>
parents:
5308
diff
changeset
|
13 |
|
57 | 14 |
PeekableStream subclass:#PositionableStream |
973 | 15 |
instanceVariableNames:'collection position readLimit writeLimit' |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8363
diff
changeset
|
16 |
classVariableNames:'ZeroPosition InvalidPositionErrorSignal' |
973 | 17 |
poolDictionaries:'' |
18 |
category:'Streams' |
|
1 | 19 |
! |
20 |
||
1897 | 21 |
!PositionableStream class methodsFor:'documentation'! |
88 | 22 |
|
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
159 | 26 |
All Rights Reserved |
1 | 27 |
|
88 | 28 |
This software is furnished under a license and may be used |
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
10 | 36 |
|
88 | 37 |
documentation |
38 |
" |
|
39 |
Instances of PositionableStream allow positioning the read pointer. |
|
40 |
The PositionableStream class also adds methods for source-chunk reading |
|
41 |
and writing, and for filing-in/out of source code. |
|
3249
8401c3e42165
checkin to force re-checkout.
Claus Gittinger <cg@exept.de>
parents:
3184
diff
changeset
|
42 |
|
88 | 43 |
This is an abstract class. |
1295 | 44 |
|
4405 | 45 |
Compatibility Notice: |
9434 | 46 |
In previous versions of ST/X, streams started with a 1-position (i.e. as in collections), |
47 |
while ST-80 has always been using 0-based postions for streams and 1-based positions for collections. |
|
4405 | 48 |
|
49 |
THIS CERTAINLY IS BAD. |
|
9434 | 50 |
|
51 |
Although this is confusing ST/X has been changed to now also use 0-based stream positioning. |
|
4405 | 52 |
|
1295 | 53 |
[author:] |
9434 | 54 |
Claus Gittinger |
88 | 55 |
" |
56 |
! ! |
|
1 | 57 |
|
1897 | 58 |
!PositionableStream class methodsFor:'initialization'! |
1 | 59 |
|
10 | 60 |
initialize |
15353 | 61 |
ZeroPosition := 0. "/ changed with stx rel5.1; |
62 |
"/ rel6.2: no longer used (i.e. 0 has now ben hardcoded) |
|
63 |
"/ class variable to be eliminated. |
|
7363 | 64 |
|
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8363
diff
changeset
|
65 |
InvalidPositionErrorSignal isNil ifTrue:[ |
7092
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7054
diff
changeset
|
66 |
InvalidPositionErrorSignal := PositionOutOfBoundsError. |
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7054
diff
changeset
|
67 |
InvalidPositionErrorSignal notifierString:'position out of bounds: '. |
10 | 68 |
] |
69 |
! ! |
|
1 | 70 |
|
1897 | 71 |
!PositionableStream class methodsFor:'instance creation'! |
1 | 72 |
|
73 |
on:aCollection |
|
74 |
"return a new PositionableStream streaming on aCollection" |
|
75 |
||
76 |
^ (self basicNew) on:aCollection |
|
77 |
! |
|
78 |
||
79 |
on:aCollection from:first to:last |
|
80 |
"return a new PositionableStream streaming on aCollection |
|
81 |
from first to last" |
|
82 |
||
369 | 83 |
^ (self basicNew) on:aCollection from:first to:last |
57 | 84 |
! |
85 |
||
86 |
with:aCollection |
|
87 |
"return a new PositionableStream streaming on aCollection, |
|
88 |
the stream is positioned to the end of the collection." |
|
89 |
||
362 | 90 |
^ (self basicNew) with:aCollection |
1 | 91 |
! ! |
92 |
||
3032
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
93 |
!PositionableStream class methodsFor:'Signal constants'! |
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
94 |
|
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
95 |
invalidPositionErrorSignal |
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
96 |
"return the signal raised if positioning is attempted to an |
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
97 |
invalid position (i.e. before the begin of the stream or after |
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
98 |
the end)" |
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
99 |
|
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
8318
diff
changeset
|
100 |
^ PositionOutOfBoundsError |
3032
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
101 |
! ! |
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
102 |
|
1897 | 103 |
!PositionableStream class methodsFor:'constants'! |
1 | 104 |
|
4405 | 105 |
zeroPosition |
106 |
"return the number, which marks the initial position. |
|
107 |
Compatibility Notice: |
|
9434 | 108 |
In previous versions of ST/X, streams started with a 1-position (i.e. as in collections), |
109 |
while ST-80 has always been using 0-based postions for streams and 1-based positions for collections. |
|
4405 | 110 |
|
9434 | 111 |
Although this is confusing ST/X has been changed to now also use 0-based stream positioning. |
112 |
" |
|
4405 | 113 |
|
15353 | 114 |
^ 0 |
9434 | 115 |
|
116 |
"Modified: / 13-07-2006 / 20:36:54 / cg" |
|
360 | 117 |
! ! |
118 |
||
7261 | 119 |
!PositionableStream methodsFor:'Compatibility-Dolphin'! |
6413 | 120 |
|
121 |
endChunk |
|
122 |
self nextPutChunkSeparator |
|
123 |
! ! |
|
124 |
||
9284 | 125 |
!PositionableStream methodsFor:'Compatibility-ST/V'! |
126 |
||
127 |
skipTo:anElement |
|
128 |
"ST/V compatibility: |
|
129 |
skip for the element given by the argument, anElement; |
|
130 |
return nil if not found, self otherwise. |
|
131 |
On a successful match, the next read will return the element after anElement." |
|
132 |
||
133 |
^ self skipThrough:anElement |
|
134 |
||
135 |
" |
|
136 |
|s| |
|
137 |
s := ReadStream on:'12345678901234567890'. |
|
138 |
s skipTo:$5. |
|
139 |
s copyFrom:1 to:(s position). |
|
140 |
s upToEnd |
|
141 |
" |
|
142 |
! ! |
|
143 |
||
1 | 144 |
!PositionableStream methodsFor:'accessing'! |
145 |
||
7686
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7619
diff
changeset
|
146 |
collection |
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7619
diff
changeset
|
147 |
^ collection |
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7619
diff
changeset
|
148 |
! |
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7619
diff
changeset
|
149 |
|
1 | 150 |
contents |
151 |
"return the entire contents of the stream" |
|
152 |
||
153 |
^ collection |
|
154 |
! |
|
155 |
||
156 |
peek |
|
157 |
"look ahead for and return the next element" |
|
158 |
||
159 |
|peekObject| |
|
160 |
||
161 |
peekObject := self next. |
|
10 | 162 |
self backStep. |
1 | 163 |
^ peekObject |
164 |
! |
|
165 |
||
2432 | 166 |
peekForAll:aCollection |
167 |
"return true and advance if the next elements are the same |
|
168 |
as aCollection. |
|
169 |
otherwise stay and let the position unchanged" |
|
170 |
||
171 |
|oldPos| |
|
172 |
||
173 |
oldPos := self position. |
|
174 |
(self next:(aCollection size)) = aCollection ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6924
diff
changeset
|
175 |
^ true |
2432 | 176 |
]. |
177 |
self position:oldPos. |
|
178 |
^ false |
|
179 |
||
180 |
"Created: 1.3.1997 / 15:11:25 / cg" |
|
181 |
! |
|
182 |
||
3905
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
183 |
readLimit |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
184 |
"return the read-limit; thats the position at which EOF is returned" |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
185 |
|
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
186 |
^ readLimit |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
187 |
|
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
188 |
"Created: / 30.10.1998 / 16:47:04 / cg" |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
189 |
! |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
190 |
|
1 | 191 |
readLimit:aNumber |
369 | 192 |
"set the read-limit; thats the position at which EOF is returned" |
1 | 193 |
|
194 |
readLimit := aNumber |
|
369 | 195 |
! |
196 |
||
14934 | 197 |
setCollection:newCollection |
198 |
collection := newCollection |
|
199 |
! |
|
200 |
||
369 | 201 |
writeLimit:aNumber |
202 |
"set the writeLimit; thats the position after which writing is prohibited" |
|
203 |
||
204 |
writeLimit := aNumber |
|
10592 | 205 |
|
206 |
" |
|
207 |
|s| |
|
208 |
s := WriteStream on:String new. |
|
209 |
s nextPutAll:'hello world'. |
|
210 |
s contents. |
|
211 |
||
212 |
|s| |
|
213 |
s := WriteStream on:String new. |
|
214 |
s writeLimit:5. |
|
215 |
s nextPutAll:'hello world'. |
|
216 |
s contents. |
|
217 |
||
218 |
" |
|
219 |
||
220 |
"Modified: / 04-06-2007 / 17:21:55 / cg" |
|
1 | 221 |
! ! |
222 |
||
611 | 223 |
!PositionableStream methodsFor:'positioning'! |
224 |
||
225 |
backStep |
|
226 |
"move backward read position by one" |
|
227 |
||
4405 | 228 |
self position:(self position - 1) |
611 | 229 |
! |
230 |
||
16188 | 231 |
match: subCollection |
232 |
"Set the access position of the receiver to be past the next occurrence of the subCollection. |
|
233 |
Answer whether subCollection is found. |
|
234 |
No wildcards, and case does matter." |
|
235 |
||
236 |
| pattern startMatch | |
|
237 |
||
238 |
pattern := ReadStream on: subCollection. |
|
239 |
startMatch := nil. |
|
240 |
[pattern atEnd] whileFalse: [ |
|
241 |
self atEnd ifTrue: [^ false]. |
|
242 |
(self next) = (pattern next) |
|
243 |
ifTrue: [pattern position = 1 ifTrue: [startMatch := self position]] |
|
244 |
ifFalse: [ |
|
245 |
pattern position: 0. |
|
246 |
startMatch ifNotNil: [ |
|
247 |
self position: startMatch. |
|
248 |
startMatch := nil |
|
249 |
] |
|
250 |
] |
|
251 |
]. |
|
252 |
^ true |
|
253 |
||
254 |
" |
|
255 |
'abc def ghi' readStream match:'def'; upToEnd |
|
256 |
" |
|
257 |
! |
|
258 |
||
611 | 259 |
position |
15615 | 260 |
"return the read position (0-based)" |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
261 |
|
15348 | 262 |
^ position |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
263 |
! |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
264 |
|
15615 | 265 |
position0Based |
266 |
<resource: #obsolete> |
|
267 |
"return the read position 0-based" |
|
268 |
||
269 |
^ self position |
|
270 |
! |
|
271 |
||
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
272 |
position0Based:index0Based |
15615 | 273 |
<resource: #obsolete> |
4405 | 274 |
"set the read (or write) position" |
611 | 275 |
|
15615 | 276 |
self position:index0Based |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
277 |
! |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
278 |
|
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
279 |
position1Based |
15615 | 280 |
<resource: #obsolete> |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
281 |
"return the read position 1-based" |
611 | 282 |
|
15615 | 283 |
^ self position + 1 |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
284 |
! |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
285 |
|
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
286 |
position1Based:index1Based |
15615 | 287 |
<resource: #obsolete> |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
288 |
"set the read (or write) position" |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
289 |
|
15615 | 290 |
self position:(index1Based - 1) |
4405 | 291 |
|
292 |
" |
|
293 |
|s| |
|
294 |
||
295 |
s := '1234567890' readStream. |
|
296 |
s next:5. |
|
297 |
s position:1. |
|
298 |
s next:7. |
|
299 |
" |
|
300 |
||
301 |
" |
|
302 |
|s| |
|
303 |
||
304 |
s := '' writeStream. |
|
305 |
s nextPutAll:'1234567890'. |
|
306 |
s position:5. |
|
307 |
s nextPutAll:'abcdefg'. |
|
308 |
s contents |
|
309 |
" |
|
310 |
||
311 |
" |
|
312 |
|s| |
|
313 |
||
314 |
s := '' writeStream. |
|
315 |
s nextPutAll:'1234567890'. |
|
316 |
s position:0. |
|
317 |
s nextPutAll:'abcdefg'. |
|
318 |
s contents |
|
319 |
" |
|
611 | 320 |
! |
321 |
||
15615 | 322 |
position:index0Based |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
323 |
"set the read (or write) position" |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
324 |
|
15615 | 325 |
((index0Based > readLimit) or:[index0Based < 0]) ifTrue: [^ self positionError:index0Based]. |
326 |
position := index0Based |
|
6626
f7b08d6bee3f
#positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents:
6538
diff
changeset
|
327 |
! |
f7b08d6bee3f
#positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents:
6538
diff
changeset
|
328 |
|
611 | 329 |
reset |
330 |
"set the read position to the beginning of the collection" |
|
331 |
||
5308 | 332 |
self resetPosition |
333 |
||
334 |
" |
|
335 |
|s| |
|
336 |
||
337 |
s := 'hello world' readStream. |
|
338 |
Transcript showCR:(s next:5). |
|
339 |
s reset. |
|
340 |
Transcript showCR:(s next:10). |
|
341 |
" |
|
342 |
! |
|
343 |
||
344 |
resetPosition |
|
345 |
"set the read position to the beginning of the collection" |
|
346 |
||
15348 | 347 |
position := 0 |
4405 | 348 |
|
349 |
" |
|
350 |
|s| |
|
351 |
||
352 |
s := 'hello world' readStream. |
|
353 |
Transcript showCR:(s next:5). |
|
354 |
s reset. |
|
355 |
Transcript showCR:(s next:10). |
|
356 |
" |
|
611 | 357 |
! |
358 |
||
359 |
setToEnd |
|
11433 | 360 |
"set the read position to the end of the collection. |
361 |
#next will return EOF, #nextPut: will append to the stream. |
|
362 |
(same Behavior as FileStream." |
|
611 | 363 |
|
15348 | 364 |
position := readLimit |
611 | 365 |
! |
366 |
||
367 |
skip:numberToSkip |
|
368 |
"skip the next numberToSkip elements" |
|
369 |
||
5774 | 370 |
numberToSkip ~~ 0 ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6924
diff
changeset
|
371 |
self position:(self position + numberToSkip) |
5774 | 372 |
] |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
373 |
! |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
374 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
375 |
skipThroughAll:aCollection |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
376 |
"skip for and through the sequence given by the argument, aCollection; |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
377 |
return nil if not found, self otherwise. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
378 |
On a successful match, the next read will return elements after aCollection; |
2153
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
379 |
if no match was found, the receiver will be positioned at the end. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
380 |
This is redefined here, to make use of positioning." |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
381 |
|
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
382 |
|buffer len first idx| |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
383 |
|
16186 | 384 |
self isPositionable ifFalse:[ |
385 |
"/ for non-positionable subclasses |
|
386 |
^ super skipThroughAll:aCollection |
|
387 |
]. |
|
388 |
||
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
389 |
len := aCollection size. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
390 |
first := aCollection at:1. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
391 |
[self atEnd] whileFalse:[ |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
392 |
buffer := self nextAvailable:len. |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
393 |
buffer size == len ifTrue:[ |
16209 | 394 |
buffer = aCollection ifTrue:[ |
395 |
^ self |
|
396 |
]. |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
397 |
"expect more input" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
398 |
idx := buffer indexOf:first startingAt:2. |
16209 | 399 |
idx ~~ 0 ifTrue:[ |
400 |
self skip:(idx - len - 1) |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
401 |
]. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
402 |
]. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
403 |
]. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
404 |
^ nil |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
405 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
406 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
407 |
|s| |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
408 |
s := ReadStream on:'12345678901234567890a'. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
409 |
s skipThroughAll:'90ab'. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
410 |
s upToEnd |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
411 |
" |
2153
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
412 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
413 |
|s| |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
414 |
s := ReadStream on:'12345678901234567890'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
415 |
s skipThroughAll:'1234'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
416 |
s upToEnd |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
417 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
418 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
419 |
|s| |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
420 |
s := ReadStream on:'12345678901234567890'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
421 |
s skipThroughAll:'999'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
422 |
s atEnd |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
423 |
" |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
424 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
425 |
"Created: 26.6.1996 / 09:35:35 / cg" |
2154
89e96599e1e2
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2153
diff
changeset
|
426 |
"Modified: 11.1.1997 / 19:16:38 / cg" |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
427 |
! |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
428 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
429 |
skipToAll:aCollection |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
430 |
"skip for the sequence given by the argument, aCollection; |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
431 |
return nil if not found, self otherwise. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
432 |
On a successful match, the next read will return elements of aCollection." |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
433 |
|
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
434 |
|oldPos buffer len first idx| |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
435 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
436 |
oldPos := self position. |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
437 |
len := aCollection size. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
438 |
first := aCollection at:1. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
439 |
[self atEnd] whileFalse:[ |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
440 |
buffer := self nextAvailable:len. |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
441 |
buffer = aCollection ifTrue:[ |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
442 |
self position:(self position - len). |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
443 |
^ self |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
444 |
]. |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
445 |
buffer size == len ifTrue:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
446 |
"more input can be expected" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
447 |
idx := buffer indexOf:first startingAt:2. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
448 |
idx == 0 ifFalse:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
449 |
self position:(self position - len + idx - 1) |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
450 |
]. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
451 |
]. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
452 |
]. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
453 |
self position:oldPos. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
454 |
^ nil |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
455 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
456 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
457 |
|s| |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
458 |
s := ReadStream on:'12345678901234567890'. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
459 |
s skipToAll:'901'. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
460 |
s upToEnd |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
461 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
462 |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
463 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
464 |
|s| |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
465 |
s := ReadStream on:'1234567890'. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
466 |
s skipToAll:'901'. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
467 |
s upToEnd |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
468 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
469 |
|
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
470 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
471 |
|s| |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
472 |
s := 'Makefile' asFilename readStream. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
473 |
[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
474 |
(s skipToAll:'EDIT') notNil ifTrue:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
475 |
s next:100. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
476 |
]. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
477 |
] ensure:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
478 |
s close. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
479 |
] |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
480 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
481 |
|
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
482 |
"Modified: 26.6.1996 / 09:28:27 / cg" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
483 |
"Created: 26.6.1996 / 09:35:06 / cg" |
44 | 484 |
! ! |
611 | 485 |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
486 |
!PositionableStream methodsFor:'printing & storing'! |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
487 |
|
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
488 |
printOn:aStream |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
489 |
aStream nextPutAll:self className; nextPutAll:'(on:'; nextPutAll:collection classNameWithArticle; nextPut:$) |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
490 |
|
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
491 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
492 |
'' readStream printString |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
493 |
'' writeStream printString |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
494 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
495 |
! ! |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
496 |
|
611 | 497 |
!PositionableStream methodsFor:'private'! |
498 |
||
499 |
contentsSpecies |
|
500 |
"return a class of which instances will be returned, when |
|
501 |
parts of the collection are asked for. |
|
15640 | 502 |
(see upTo-kind of methods in Stream)" |
611 | 503 |
|
504 |
^ collection species |
|
505 |
! |
|
506 |
||
507 |
on:aCollection |
|
508 |
"setup for streaming on aCollection" |
|
509 |
||
510 |
collection := aCollection. |
|
511 |
readLimit := aCollection size. |
|
13379 | 512 |
readLimit == 0 ifTrue:[ |
513 |
self assert:(aCollection isCollection) |
|
514 |
]. |
|
15348 | 515 |
position := 0 |
611 | 516 |
! |
517 |
||
518 |
on:aCollection from:first to:last |
|
519 |
"setup for streaming on aCollection from first to last" |
|
520 |
||
521 |
collection := aCollection. |
|
15348 | 522 |
position := first - 1. |
611 | 523 |
readLimit := last |
524 |
! |
|
525 |
||
526 |
positionError |
|
1998 | 527 |
"{ Pragma: +optSpace }" |
528 |
||
2966 | 529 |
"report an error when positioning past the end |
530 |
or before the beginning." |
|
611 | 531 |
|
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
8318
diff
changeset
|
532 |
^ PositionOutOfBoundsError raiseRequestWith:nil |
4452
3d050f505a0a
Raise proceedable signals proceedable.
Stefan Vogel <sv@exept.de>
parents:
4416
diff
changeset
|
533 |
|
3d050f505a0a
Raise proceedable signals proceedable.
Stefan Vogel <sv@exept.de>
parents:
4416
diff
changeset
|
534 |
"Modified: / 26.7.1999 / 10:59:13 / stefan" |
611 | 535 |
! |
536 |
||
6314 | 537 |
positionError:badPostition |
538 |
"{ Pragma: +optSpace }" |
|
539 |
||
540 |
"report an error when positioning past the end |
|
541 |
or before the beginning." |
|
542 |
||
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
8318
diff
changeset
|
543 |
^ PositionOutOfBoundsError raiseRequestWith:badPostition |
6314 | 544 |
! |
545 |
||
611 | 546 |
with:aCollection |
547 |
"setup for streaming to the end of aCollection" |
|
548 |
||
549 |
collection := aCollection. |
|
11434 | 550 |
readLimit := aCollection size. |
611 | 551 |
self setToEnd |
11434 | 552 |
|
553 |
" |
|
554 |
(WriteStream with:#(1 2 3 4 5)) |
|
555 |
nextPut:6; |
|
556 |
contents |
|
557 |
" |
|
611 | 558 |
! ! |
559 |
||
16195 | 560 |
!PositionableStream methodsFor:'queries'! |
561 |
||
16209 | 562 |
endsBeforePositionWith:aSequenceableCollection |
16195 | 563 |
"answer true, if the elements in aSequenceableCollection |
16209 | 564 |
are at the current end of the stream up to position." |
16195 | 565 |
|
16209 | 566 |
|sz pos| |
16195 | 567 |
|
16209 | 568 |
sz := aSequenceableCollection size. |
569 |
pos := self position. |
|
570 |
pos < sz ifTrue:[ |
|
571 |
^ false. |
|
16195 | 572 |
]. |
16209 | 573 |
self contentsSpecies == collection class ifTrue:[ |
574 |
^ collection sameContentsFrom:pos+1-sz to:pos as:aSequenceableCollection startingAt:1. |
|
575 |
]. |
|
576 |
self position:pos-sz. |
|
577 |
^ (self next:sz) = aSequenceableCollection. |
|
16195 | 578 |
|
579 |
" |
|
16209 | 580 |
('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'World' |
581 |
('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'Hello World' |
|
582 |
('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'Hello Worldx' |
|
583 |
('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'Bla' |
|
584 |
('' writeStream) endsBeforePositionWith:'Bla' |
|
585 |
('' writeStream) endsBeforePositionWith:'' |
|
16195 | 586 |
'' endsWith:'' |
587 |
" |
|
588 |
! ! |
|
589 |
||
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
590 |
!PositionableStream methodsFor:'reading'! |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
591 |
|
9003 | 592 |
nextAvailable:count |
593 |
|end result| |
|
594 |
||
595 |
end := position + count. |
|
15357 | 596 |
end >= readLimit ifTrue:[ |
9003 | 597 |
end := readLimit. |
598 |
]. |
|
599 |
||
15348 | 600 |
result := collection copyFrom:position+1 to:end. |
9003 | 601 |
position := end. |
602 |
^ result. |
|
603 |
||
604 |
" |
|
605 |
'abc' readStream nextAvailable:1. |
|
606 |
'abc' readStream nextAvailable:2. |
|
607 |
'abc' readStream nextAvailable:3. |
|
608 |
'abc' readStream nextAvailable:4. |
|
609 |
||
610 |
'abc' readStream nextAvailable:2; nextAvailable:2. |
|
611 |
'abc' readStream nextAvailable:3; nextAvailable:3. |
|
612 |
" |
|
613 |
! |
|
614 |
||
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
615 |
upToAll:aCollection |
16186 | 616 |
"read until a subcollection consisisting of the elements in aCollection is encountered. |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
617 |
Return everything read excluding the elements in aCollection. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
618 |
The position is left before the collection; i.e. the next |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
619 |
read operations will return those elements. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
620 |
If no such subcollection is encountered, all elements up to the end |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
621 |
are read and returned. |
6494 | 622 |
See also #throughAll: which also reads up to some objects |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
623 |
but positions behind it and DOES include it in the returned |
3184
d99302322139
Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents:
3170
diff
changeset
|
624 |
collection. |
6494 | 625 |
See also #upToAllExcluding:, which returns the same, but leaves the |
626 |
read pointer after the matched subcollection. |
|
3184
d99302322139
Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents:
3170
diff
changeset
|
627 |
|
d99302322139
Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents:
3170
diff
changeset
|
628 |
Note: this behavior is inconsistent with the other upTo.. methods, |
15159
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
629 |
which position after the found item. We implement the method |
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
630 |
this way for the sake of ST80-compatibility." |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
631 |
|
16189 | 632 |
"/ in the future, this wil have the Squeak semantics, which is upToAllExcluding: |
633 |
||
634 |
^ self upToAll_positionBefore:aCollection |
|
635 |
||
636 |
" |
|
637 |
|s| |
|
638 |
s := ReadStream on:'hello world'. |
|
639 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
640 |
Transcript showCR:s atEnd. |
|
641 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
|
642 |
" |
|
643 |
" |
|
644 |
|s| |
|
645 |
s := ReadStream on:'hello world'. |
|
646 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
647 |
Transcript showCR:s atEnd. |
|
648 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
649 |
" |
|
650 |
" |
|
651 |
|s| |
|
652 |
s := ReadStream on:'hello world'. |
|
653 |
Transcript show:'<'; show:(s upToAll:'xx'); showCR:'>'. |
|
654 |
Transcript showCR:s atEnd. |
|
655 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
|
656 |
" |
|
657 |
||
658 |
"Modified: / 12.1.1998 / 22:06:42 / cg" |
|
659 |
"Created: / 12.1.1998 / 22:07:01 / cg" |
|
660 |
! |
|
661 |
||
662 |
upToAll_positionBefore:aCollection |
|
663 |
"read until a subcollection consisisting of the elements in aCollection is encountered. |
|
664 |
Return everything read excluding the elements in aCollection. |
|
665 |
The position is left before the collection; i.e. the next |
|
666 |
read operations will return those elements. |
|
667 |
If no such subcollection is encountered, all elements up to the end |
|
668 |
are read and returned. |
|
669 |
See also #throughAll: which also reads up to some objects |
|
670 |
but positions behind it and DOES include it in the returned |
|
16840 | 671 |
collection." |
16189 | 672 |
|
16209 | 673 |
|answerStream element last| |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
674 |
|
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
675 |
last := aCollection last. |
16209 | 676 |
answerStream := WriteStream on:(self contentsSpecies new:100). |
677 |
[(element := self nextOrNil) notNil] whileTrue:[ |
|
15159
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
678 |
answerStream nextPut:element. |
16209 | 679 |
(element = last and:[answerStream endsBeforePositionWith:aCollection]) ifTrue:[ |
680 |
|backStep| |
|
681 |
backStep := aCollection size negated. |
|
682 |
self skip:backStep. |
|
683 |
answerStream skip:backStep. |
|
684 |
^ answerStream contents |
|
15159
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
685 |
]. |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
686 |
]. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
687 |
^ answerStream contents |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
688 |
|
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
689 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
690 |
|s| |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
691 |
s := ReadStream on:'hello world'. |
16209 | 692 |
Transcript show:'<'; show:(s upToAll_positionBefore:'wo'); showCR:'>'. |
6494 | 693 |
Transcript showCR:s atEnd. |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
694 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
695 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
696 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
697 |
|s| |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
698 |
s := ReadStream on:'hello world'. |
16209 | 699 |
Transcript show:'<'; show:(s upToAll_positionBefore:'wo'); showCR:'>'. |
16186 | 700 |
Transcript showCR:s atEnd. |
16209 | 701 |
Transcript show:'<'; show:(s upToAll_positionBefore:'wo'); showCR:'>'. |
16186 | 702 |
" |
703 |
" |
|
704 |
|s| |
|
705 |
s := ReadStream on:'hello world'. |
|
16209 | 706 |
Transcript show:'<'; show:(s upToAll_positionBefore:'xx'); showCR:'>'. |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
707 |
Transcript showCR:s atEnd. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
708 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
709 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
710 |
|
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
711 |
"Modified: / 12.1.1998 / 22:06:42 / cg" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
712 |
"Created: / 12.1.1998 / 22:07:01 / cg" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
713 |
! ! |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
714 |
|
611 | 715 |
!PositionableStream methodsFor:'testing'! |
716 |
||
717 |
atEnd |
|
718 |
"return true, if the read-position is at the end" |
|
719 |
||
15357 | 720 |
^ position >= readLimit |
611 | 721 |
! |
722 |
||
723 |
isEmpty |
|
724 |
"return true, if the contents of the stream is empty" |
|
725 |
||
726 |
^ readLimit == 0 |
|
9006 | 727 |
! |
728 |
||
10577 | 729 |
isInternalByteStream |
730 |
"return true, if the stream is an internal stream reading bytes" |
|
731 |
||
732 |
^ collection class isBytes |
|
733 |
||
734 |
"Created: / 30-05-2007 / 16:16:12 / cg" |
|
735 |
! |
|
736 |
||
9006 | 737 |
isPositionable |
738 |
"return true, if the stream supports positioning (this one is)" |
|
739 |
||
740 |
^ true |
|
611 | 741 |
! ! |
742 |
||
1897 | 743 |
!PositionableStream class methodsFor:'documentation'! |
701 | 744 |
|
745 |
version |
|
16840 | 746 |
^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.167 2014-09-16 11:11:38 stefan Exp $' |
13379 | 747 |
! |
748 |
||
749 |
version_CVS |
|
16840 | 750 |
^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.167 2014-09-16 11:11:38 stefan Exp $' |
701 | 751 |
! ! |
6777
5efddf5358b2
currentFileInDirectory query
Claus Gittinger <cg@exept.de>
parents:
6707
diff
changeset
|
752 |
|
14934 | 753 |
|
611 | 754 |
PositionableStream initialize! |