author | Stefan Vogel <sv@exept.de> |
Tue, 04 Mar 2014 13:36:39 +0100 | |
changeset 16195 | 2bed37c6f731 |
parent 16189 | d7b9978c07bb |
child 16209 | f2d1d7b2d649 |
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 |
||
16186 | 119 |
|
7261 | 120 |
!PositionableStream methodsFor:'Compatibility-Dolphin'! |
6413 | 121 |
|
122 |
endChunk |
|
123 |
self nextPutChunkSeparator |
|
124 |
! ! |
|
125 |
||
9284 | 126 |
!PositionableStream methodsFor:'Compatibility-ST/V'! |
127 |
||
128 |
skipTo:anElement |
|
129 |
"ST/V compatibility: |
|
130 |
skip for the element given by the argument, anElement; |
|
131 |
return nil if not found, self otherwise. |
|
132 |
On a successful match, the next read will return the element after anElement." |
|
133 |
||
134 |
^ self skipThrough:anElement |
|
135 |
||
136 |
" |
|
137 |
|s| |
|
138 |
s := ReadStream on:'12345678901234567890'. |
|
139 |
s skipTo:$5. |
|
140 |
s copyFrom:1 to:(s position). |
|
141 |
s upToEnd |
|
142 |
" |
|
143 |
! ! |
|
144 |
||
1 | 145 |
!PositionableStream methodsFor:'accessing'! |
146 |
||
7686
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 |
^ collection |
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7619
diff
changeset
|
149 |
! |
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7619
diff
changeset
|
150 |
|
1 | 151 |
contents |
152 |
"return the entire contents of the stream" |
|
153 |
||
154 |
^ collection |
|
155 |
! |
|
156 |
||
157 |
peek |
|
158 |
"look ahead for and return the next element" |
|
159 |
||
160 |
|peekObject| |
|
161 |
||
162 |
peekObject := self next. |
|
10 | 163 |
self backStep. |
1 | 164 |
^ peekObject |
165 |
! |
|
166 |
||
2432 | 167 |
peekForAll:aCollection |
168 |
"return true and advance if the next elements are the same |
|
169 |
as aCollection. |
|
170 |
otherwise stay and let the position unchanged" |
|
171 |
||
172 |
|oldPos| |
|
173 |
||
174 |
oldPos := self position. |
|
175 |
(self next:(aCollection size)) = aCollection ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6924
diff
changeset
|
176 |
^ true |
2432 | 177 |
]. |
178 |
self position:oldPos. |
|
179 |
^ false |
|
180 |
||
181 |
"Created: 1.3.1997 / 15:11:25 / cg" |
|
182 |
! |
|
183 |
||
3905
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
184 |
readLimit |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
185 |
"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
|
186 |
|
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
187 |
^ readLimit |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
188 |
|
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
189 |
"Created: / 30.10.1998 / 16:47:04 / cg" |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
190 |
! |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
191 |
|
1 | 192 |
readLimit:aNumber |
369 | 193 |
"set the read-limit; thats the position at which EOF is returned" |
1 | 194 |
|
195 |
readLimit := aNumber |
|
369 | 196 |
! |
197 |
||
14934 | 198 |
setCollection:newCollection |
199 |
collection := newCollection |
|
200 |
! |
|
201 |
||
369 | 202 |
writeLimit:aNumber |
203 |
"set the writeLimit; thats the position after which writing is prohibited" |
|
204 |
||
205 |
writeLimit := aNumber |
|
10592 | 206 |
|
207 |
" |
|
208 |
|s| |
|
209 |
s := WriteStream on:String new. |
|
210 |
s nextPutAll:'hello world'. |
|
211 |
s contents. |
|
212 |
||
213 |
|s| |
|
214 |
s := WriteStream on:String new. |
|
215 |
s writeLimit:5. |
|
216 |
s nextPutAll:'hello world'. |
|
217 |
s contents. |
|
218 |
||
219 |
" |
|
220 |
||
221 |
"Modified: / 04-06-2007 / 17:21:55 / cg" |
|
1 | 222 |
! ! |
223 |
||
611 | 224 |
!PositionableStream methodsFor:'positioning'! |
225 |
||
226 |
backStep |
|
227 |
"move backward read position by one" |
|
228 |
||
4405 | 229 |
self position:(self position - 1) |
611 | 230 |
! |
231 |
||
16188 | 232 |
match: subCollection |
233 |
"Set the access position of the receiver to be past the next occurrence of the subCollection. |
|
234 |
Answer whether subCollection is found. |
|
235 |
No wildcards, and case does matter." |
|
236 |
||
237 |
| pattern startMatch | |
|
238 |
||
239 |
pattern := ReadStream on: subCollection. |
|
240 |
startMatch := nil. |
|
241 |
[pattern atEnd] whileFalse: [ |
|
242 |
self atEnd ifTrue: [^ false]. |
|
243 |
(self next) = (pattern next) |
|
244 |
ifTrue: [pattern position = 1 ifTrue: [startMatch := self position]] |
|
245 |
ifFalse: [ |
|
246 |
pattern position: 0. |
|
247 |
startMatch ifNotNil: [ |
|
248 |
self position: startMatch. |
|
249 |
startMatch := nil |
|
250 |
] |
|
251 |
] |
|
252 |
]. |
|
253 |
^ true |
|
254 |
||
255 |
" |
|
256 |
'abc def ghi' readStream match:'def'; upToEnd |
|
257 |
" |
|
258 |
! |
|
259 |
||
611 | 260 |
position |
15615 | 261 |
"return the read position (0-based)" |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
262 |
|
15348 | 263 |
^ position |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
264 |
! |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
265 |
|
15615 | 266 |
position0Based |
267 |
<resource: #obsolete> |
|
268 |
"return the read position 0-based" |
|
269 |
||
270 |
^ self position |
|
271 |
! |
|
272 |
||
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
273 |
position0Based:index0Based |
15615 | 274 |
<resource: #obsolete> |
4405 | 275 |
"set the read (or write) position" |
611 | 276 |
|
15615 | 277 |
self position:index0Based |
7052
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 |
|
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
280 |
position1Based |
15615 | 281 |
<resource: #obsolete> |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
282 |
"return the read position 1-based" |
611 | 283 |
|
15615 | 284 |
^ self position + 1 |
7052
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 |
|
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
287 |
position1Based:index1Based |
15615 | 288 |
<resource: #obsolete> |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
289 |
"set the read (or write) position" |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
290 |
|
15615 | 291 |
self position:(index1Based - 1) |
4405 | 292 |
|
293 |
" |
|
294 |
|s| |
|
295 |
||
296 |
s := '1234567890' readStream. |
|
297 |
s next:5. |
|
298 |
s position:1. |
|
299 |
s next:7. |
|
300 |
" |
|
301 |
||
302 |
" |
|
303 |
|s| |
|
304 |
||
305 |
s := '' writeStream. |
|
306 |
s nextPutAll:'1234567890'. |
|
307 |
s position:5. |
|
308 |
s nextPutAll:'abcdefg'. |
|
309 |
s contents |
|
310 |
" |
|
311 |
||
312 |
" |
|
313 |
|s| |
|
314 |
||
315 |
s := '' writeStream. |
|
316 |
s nextPutAll:'1234567890'. |
|
317 |
s position:0. |
|
318 |
s nextPutAll:'abcdefg'. |
|
319 |
s contents |
|
320 |
" |
|
611 | 321 |
! |
322 |
||
15615 | 323 |
position:index0Based |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
324 |
"set the read (or write) position" |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
325 |
|
15615 | 326 |
((index0Based > readLimit) or:[index0Based < 0]) ifTrue: [^ self positionError:index0Based]. |
327 |
position := index0Based |
|
6626
f7b08d6bee3f
#positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents:
6538
diff
changeset
|
328 |
! |
f7b08d6bee3f
#positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents:
6538
diff
changeset
|
329 |
|
611 | 330 |
reset |
331 |
"set the read position to the beginning of the collection" |
|
332 |
||
5308 | 333 |
self resetPosition |
334 |
||
335 |
" |
|
336 |
|s| |
|
337 |
||
338 |
s := 'hello world' readStream. |
|
339 |
Transcript showCR:(s next:5). |
|
340 |
s reset. |
|
341 |
Transcript showCR:(s next:10). |
|
342 |
" |
|
343 |
! |
|
344 |
||
345 |
resetPosition |
|
346 |
"set the read position to the beginning of the collection" |
|
347 |
||
15348 | 348 |
position := 0 |
4405 | 349 |
|
350 |
" |
|
351 |
|s| |
|
352 |
||
353 |
s := 'hello world' readStream. |
|
354 |
Transcript showCR:(s next:5). |
|
355 |
s reset. |
|
356 |
Transcript showCR:(s next:10). |
|
357 |
" |
|
611 | 358 |
! |
359 |
||
360 |
setToEnd |
|
11433 | 361 |
"set the read position to the end of the collection. |
362 |
#next will return EOF, #nextPut: will append to the stream. |
|
363 |
(same Behavior as FileStream." |
|
611 | 364 |
|
15348 | 365 |
position := readLimit |
611 | 366 |
! |
367 |
||
368 |
skip:numberToSkip |
|
369 |
"skip the next numberToSkip elements" |
|
370 |
||
5774 | 371 |
numberToSkip ~~ 0 ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6924
diff
changeset
|
372 |
self position:(self position + numberToSkip) |
5774 | 373 |
] |
1489
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 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
376 |
skipThroughAll:aCollection |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
377 |
"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
|
378 |
return nil if not found, self otherwise. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
379 |
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
|
380 |
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
|
381 |
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
|
382 |
|
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
383 |
|buffer len first idx| |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
384 |
|
16186 | 385 |
self isPositionable ifFalse:[ |
386 |
"/ for non-positionable subclasses |
|
387 |
^ super skipThroughAll:aCollection |
|
388 |
]. |
|
389 |
||
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
390 |
len := aCollection size. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
391 |
first := aCollection at:1. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
392 |
[self atEnd] whileFalse:[ |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
393 |
buffer := self nextAvailable:len. |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
394 |
buffer = aCollection ifTrue:[ |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
395 |
^ self |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
396 |
]. |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
397 |
buffer size == len ifTrue:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
398 |
"expect more input" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
399 |
idx := buffer indexOf:first startingAt:2. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
400 |
idx == 0 ifFalse:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
401 |
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
|
402 |
]. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
403 |
]. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
404 |
]. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
405 |
^ nil |
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 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
408 |
|s| |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
409 |
s := ReadStream on:'12345678901234567890a'. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
410 |
s skipThroughAll:'90ab'. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
411 |
s upToEnd |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
412 |
" |
2153
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
413 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
414 |
|s| |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
415 |
s := ReadStream on:'12345678901234567890'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
416 |
s skipThroughAll:'1234'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
417 |
s upToEnd |
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 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
420 |
|s| |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
421 |
s := ReadStream on:'12345678901234567890'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
422 |
s skipThroughAll:'999'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
423 |
s atEnd |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
424 |
" |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
425 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
426 |
"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
|
427 |
"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
|
428 |
! |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
429 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
430 |
skipToAll:aCollection |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
431 |
"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
|
432 |
return nil if not found, self otherwise. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
433 |
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
|
434 |
|
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
435 |
|oldPos buffer len first idx| |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
436 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
437 |
oldPos := self position. |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
438 |
len := aCollection size. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
439 |
first := aCollection at:1. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
440 |
[self atEnd] whileFalse:[ |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
441 |
buffer := self nextAvailable:len. |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
442 |
buffer = aCollection ifTrue:[ |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
443 |
self position:(self position - len). |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
444 |
^ self |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
445 |
]. |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
446 |
buffer size == len ifTrue:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
447 |
"more input can be expected" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
448 |
idx := buffer indexOf:first startingAt:2. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
449 |
idx == 0 ifFalse:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
450 |
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
|
451 |
]. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
452 |
]. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
453 |
]. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
454 |
self position:oldPos. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
455 |
^ nil |
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 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
458 |
|s| |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
459 |
s := ReadStream on:'12345678901234567890'. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
460 |
s skipToAll:'901'. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
461 |
s upToEnd |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
462 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
463 |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
464 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
465 |
|s| |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
466 |
s := ReadStream on:'1234567890'. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
467 |
s skipToAll:'901'. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
468 |
s upToEnd |
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 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
472 |
|s| |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
473 |
s := 'Makefile' asFilename readStream. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
474 |
[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
475 |
(s skipToAll:'EDIT') notNil ifTrue:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
476 |
s next:100. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
477 |
]. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
478 |
] ensure:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
479 |
s close. |
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 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
482 |
|
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
483 |
"Modified: 26.6.1996 / 09:28:27 / cg" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
484 |
"Created: 26.6.1996 / 09:35:06 / cg" |
44 | 485 |
! ! |
611 | 486 |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
487 |
!PositionableStream methodsFor:'printing & storing'! |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
488 |
|
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
489 |
printOn:aStream |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
490 |
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
|
491 |
|
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
492 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
493 |
'' readStream printString |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
494 |
'' writeStream printString |
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 |
! ! |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
497 |
|
611 | 498 |
!PositionableStream methodsFor:'private'! |
499 |
||
500 |
contentsSpecies |
|
501 |
"return a class of which instances will be returned, when |
|
502 |
parts of the collection are asked for. |
|
15640 | 503 |
(see upTo-kind of methods in Stream)" |
611 | 504 |
|
505 |
^ collection species |
|
506 |
! |
|
507 |
||
508 |
on:aCollection |
|
509 |
"setup for streaming on aCollection" |
|
510 |
||
511 |
collection := aCollection. |
|
512 |
readLimit := aCollection size. |
|
13379 | 513 |
readLimit == 0 ifTrue:[ |
514 |
self assert:(aCollection isCollection) |
|
515 |
]. |
|
15348 | 516 |
position := 0 |
611 | 517 |
! |
518 |
||
519 |
on:aCollection from:first to:last |
|
520 |
"setup for streaming on aCollection from first to last" |
|
521 |
||
522 |
collection := aCollection. |
|
15348 | 523 |
position := first - 1. |
611 | 524 |
readLimit := last |
525 |
! |
|
526 |
||
527 |
positionError |
|
1998 | 528 |
"{ Pragma: +optSpace }" |
529 |
||
2966 | 530 |
"report an error when positioning past the end |
531 |
or before the beginning." |
|
611 | 532 |
|
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
8318
diff
changeset
|
533 |
^ PositionOutOfBoundsError raiseRequestWith:nil |
4452
3d050f505a0a
Raise proceedable signals proceedable.
Stefan Vogel <sv@exept.de>
parents:
4416
diff
changeset
|
534 |
|
3d050f505a0a
Raise proceedable signals proceedable.
Stefan Vogel <sv@exept.de>
parents:
4416
diff
changeset
|
535 |
"Modified: / 26.7.1999 / 10:59:13 / stefan" |
611 | 536 |
! |
537 |
||
6314 | 538 |
positionError:badPostition |
539 |
"{ Pragma: +optSpace }" |
|
540 |
||
541 |
"report an error when positioning past the end |
|
542 |
or before the beginning." |
|
543 |
||
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
8318
diff
changeset
|
544 |
^ PositionOutOfBoundsError raiseRequestWith:badPostition |
6314 | 545 |
! |
546 |
||
611 | 547 |
with:aCollection |
548 |
"setup for streaming to the end of aCollection" |
|
549 |
||
550 |
collection := aCollection. |
|
11434 | 551 |
readLimit := aCollection size. |
611 | 552 |
self setToEnd |
11434 | 553 |
|
554 |
" |
|
555 |
(WriteStream with:#(1 2 3 4 5)) |
|
556 |
nextPut:6; |
|
557 |
contents |
|
558 |
" |
|
611 | 559 |
! ! |
560 |
||
16195 | 561 |
!PositionableStream methodsFor:'queries'! |
562 |
||
563 |
endsWith:aSequenceableCollection |
|
564 |
"answer true, if the elements in aSequenceableCollection |
|
565 |
form the end of the stream." |
|
566 |
||
567 |
self contentsSpecies == collection class ifTrue:[ |
|
568 |
|sz| |
|
569 |
||
570 |
sz := aSequenceableCollection size. |
|
571 |
position < sz ifTrue:[ |
|
572 |
^ false. |
|
573 |
]. |
|
574 |
^ collection sameContentsFrom:position+1-sz to:position as:aSequenceableCollection startingAt:1. |
|
575 |
]. |
|
576 |
^ self contents endsWith:aSequenceableCollection |
|
577 |
||
578 |
" |
|
579 |
('' writeStream nextPutAll:'Hello World') endsWith:'World' |
|
580 |
('' writeStream nextPutAll:'Hello World') endsWith:'Hello World' |
|
581 |
('' writeStream nextPutAll:'Hello World') endsWith:'xHello World' |
|
582 |
('' writeStream nextPutAll:'Hello World') endsWith:'Bla' |
|
583 |
('' writeStream) endsWith:'Bla' |
|
584 |
('' writeStream) endsWith:'' |
|
585 |
'' endsWith:'' |
|
586 |
" |
|
587 |
! ! |
|
588 |
||
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
589 |
!PositionableStream methodsFor:'reading'! |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
590 |
|
9003 | 591 |
nextAvailable:count |
592 |
|end result| |
|
593 |
||
594 |
end := position + count. |
|
15357 | 595 |
end >= readLimit ifTrue:[ |
9003 | 596 |
end := readLimit. |
597 |
]. |
|
598 |
||
15348 | 599 |
result := collection copyFrom:position+1 to:end. |
9003 | 600 |
position := end. |
601 |
^ result. |
|
602 |
||
603 |
" |
|
604 |
'abc' readStream nextAvailable:1. |
|
605 |
'abc' readStream nextAvailable:2. |
|
606 |
'abc' readStream nextAvailable:3. |
|
607 |
'abc' readStream nextAvailable:4. |
|
608 |
||
609 |
'abc' readStream nextAvailable:2; nextAvailable:2. |
|
610 |
'abc' readStream nextAvailable:3; nextAvailable:3. |
|
611 |
" |
|
612 |
! |
|
613 |
||
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
614 |
upToAll:aCollection |
16186 | 615 |
"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
|
616 |
Return everything read excluding the elements in aCollection. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
617 |
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
|
618 |
read operations will return those elements. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
619 |
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
|
620 |
are read and returned. |
6494 | 621 |
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
|
622 |
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
|
623 |
collection. |
6494 | 624 |
See also #upToAllExcluding:, which returns the same, but leaves the |
625 |
read pointer after the matched subcollection. |
|
3184
d99302322139
Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents:
3170
diff
changeset
|
626 |
|
d99302322139
Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents:
3170
diff
changeset
|
627 |
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
|
628 |
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
|
629 |
this way for the sake of ST80-compatibility." |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
630 |
|
16189 | 631 |
"/ in the future, this wil have the Squeak semantics, which is upToAllExcluding: |
632 |
||
633 |
^ self upToAll_positionBefore:aCollection |
|
634 |
||
635 |
" |
|
636 |
|s| |
|
637 |
s := ReadStream on:'hello world'. |
|
638 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
639 |
Transcript showCR:s atEnd. |
|
640 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
|
641 |
" |
|
642 |
" |
|
643 |
|s| |
|
644 |
s := ReadStream on:'hello world'. |
|
645 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
646 |
Transcript showCR:s atEnd. |
|
647 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
648 |
" |
|
649 |
" |
|
650 |
|s| |
|
651 |
s := ReadStream on:'hello world'. |
|
652 |
Transcript show:'<'; show:(s upToAll:'xx'); showCR:'>'. |
|
653 |
Transcript showCR:s atEnd. |
|
654 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
|
655 |
" |
|
656 |
||
657 |
"Modified: / 12.1.1998 / 22:06:42 / cg" |
|
658 |
"Created: / 12.1.1998 / 22:07:01 / cg" |
|
659 |
! |
|
660 |
||
661 |
upToAll_positionBefore:aCollection |
|
662 |
"read until a subcollection consisisting of the elements in aCollection is encountered. |
|
663 |
Return everything read excluding the elements in aCollection. |
|
664 |
The position is left before the collection; i.e. the next |
|
665 |
read operations will return those elements. |
|
666 |
If no such subcollection is encountered, all elements up to the end |
|
667 |
are read and returned. |
|
668 |
See also #throughAll: which also reads up to some objects |
|
669 |
but positions behind it and DOES include it in the returned |
|
670 |
collection. |
|
671 |
See also #upToAllExcluding:, which returns the same, but leaves the |
|
672 |
read pointer after the matched subcollection. |
|
673 |
||
674 |
Note: this behavior is inconsistent with the other upTo.. methods, |
|
675 |
which position after the found item. We implement the method |
|
676 |
this way for the sake of ST80-compatibility." |
|
677 |
||
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
678 |
|answerStream element last rslt| |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
679 |
|
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
680 |
last := aCollection last. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
681 |
answerStream := WriteStream on:(self contentsSpecies new). |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
682 |
[self atEnd] whileFalse:[ |
15159
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
683 |
element := self next. |
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
684 |
answerStream nextPut:element. |
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
685 |
element == last ifTrue:[ |
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
686 |
((rslt := answerStream contents) endsWith:aCollection) ifTrue:[ |
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
687 |
self position:(self position - aCollection size). |
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
688 |
^ rslt copyButLast:aCollection size |
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
689 |
] |
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
690 |
]. |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
691 |
]. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
692 |
^ answerStream contents |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
693 |
|
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
694 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
695 |
|s| |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
696 |
s := ReadStream on:'hello world'. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
697 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
6494 | 698 |
Transcript showCR:s atEnd. |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
699 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
700 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
701 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
702 |
|s| |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
703 |
s := ReadStream on:'hello world'. |
16186 | 704 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
705 |
Transcript showCR:s atEnd. |
|
706 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
707 |
" |
|
708 |
" |
|
709 |
|s| |
|
710 |
s := ReadStream on:'hello world'. |
|
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
711 |
Transcript show:'<'; show:(s upToAll:'xx'); showCR:'>'. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
712 |
Transcript showCR:s atEnd. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
713 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
714 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
715 |
|
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
716 |
"Modified: / 12.1.1998 / 22:06:42 / cg" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
717 |
"Created: / 12.1.1998 / 22:07:01 / cg" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
718 |
! ! |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
719 |
|
611 | 720 |
!PositionableStream methodsFor:'testing'! |
721 |
||
722 |
atEnd |
|
723 |
"return true, if the read-position is at the end" |
|
724 |
||
15357 | 725 |
^ position >= readLimit |
611 | 726 |
! |
727 |
||
728 |
isEmpty |
|
729 |
"return true, if the contents of the stream is empty" |
|
730 |
||
731 |
^ readLimit == 0 |
|
9006 | 732 |
! |
733 |
||
10577 | 734 |
isInternalByteStream |
735 |
"return true, if the stream is an internal stream reading bytes" |
|
736 |
||
737 |
^ collection class isBytes |
|
738 |
||
739 |
"Created: / 30-05-2007 / 16:16:12 / cg" |
|
740 |
! |
|
741 |
||
9006 | 742 |
isPositionable |
743 |
"return true, if the stream supports positioning (this one is)" |
|
744 |
||
745 |
^ true |
|
611 | 746 |
! ! |
747 |
||
1897 | 748 |
!PositionableStream class methodsFor:'documentation'! |
701 | 749 |
|
750 |
version |
|
16195 | 751 |
^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.165 2014-03-04 12:36:39 stefan Exp $' |
13379 | 752 |
! |
753 |
||
754 |
version_CVS |
|
16195 | 755 |
^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.165 2014-03-04 12:36:39 stefan Exp $' |
701 | 756 |
! ! |
6777
5efddf5358b2
currentFileInDirectory query
Claus Gittinger <cg@exept.de>
parents:
6707
diff
changeset
|
757 |
|
14934 | 758 |
|
611 | 759 |
PositionableStream initialize! |