author | Claus Gittinger <cg@exept.de> |
Sat, 01 Mar 2014 23:09:26 +0100 | |
changeset 16186 | dae8e43ccc46 |
parent 15640 | d5a8c24894e2 |
child 16188 | 4df8b9b15db4 |
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 |
||
232 |
position |
|
15615 | 233 |
"return the read position (0-based)" |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
234 |
|
15348 | 235 |
^ position |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
236 |
! |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
237 |
|
15615 | 238 |
position0Based |
239 |
<resource: #obsolete> |
|
240 |
"return the read position 0-based" |
|
241 |
||
242 |
^ self position |
|
243 |
! |
|
244 |
||
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
245 |
position0Based:index0Based |
15615 | 246 |
<resource: #obsolete> |
4405 | 247 |
"set the read (or write) position" |
611 | 248 |
|
15615 | 249 |
self position:index0Based |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
250 |
! |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
251 |
|
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
252 |
position1Based |
15615 | 253 |
<resource: #obsolete> |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
254 |
"return the read position 1-based" |
611 | 255 |
|
15615 | 256 |
^ self position + 1 |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
257 |
! |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
258 |
|
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
259 |
position1Based:index1Based |
15615 | 260 |
<resource: #obsolete> |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
261 |
"set the read (or write) position" |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
262 |
|
15615 | 263 |
self position:(index1Based - 1) |
4405 | 264 |
|
265 |
" |
|
266 |
|s| |
|
267 |
||
268 |
s := '1234567890' readStream. |
|
269 |
s next:5. |
|
270 |
s position:1. |
|
271 |
s next:7. |
|
272 |
" |
|
273 |
||
274 |
" |
|
275 |
|s| |
|
276 |
||
277 |
s := '' writeStream. |
|
278 |
s nextPutAll:'1234567890'. |
|
279 |
s position:5. |
|
280 |
s nextPutAll:'abcdefg'. |
|
281 |
s contents |
|
282 |
" |
|
283 |
||
284 |
" |
|
285 |
|s| |
|
286 |
||
287 |
s := '' writeStream. |
|
288 |
s nextPutAll:'1234567890'. |
|
289 |
s position:0. |
|
290 |
s nextPutAll:'abcdefg'. |
|
291 |
s contents |
|
292 |
" |
|
611 | 293 |
! |
294 |
||
15615 | 295 |
position:index0Based |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
296 |
"set the read (or write) position" |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
297 |
|
15615 | 298 |
((index0Based > readLimit) or:[index0Based < 0]) ifTrue: [^ self positionError:index0Based]. |
299 |
position := index0Based |
|
6626
f7b08d6bee3f
#positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents:
6538
diff
changeset
|
300 |
! |
f7b08d6bee3f
#positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents:
6538
diff
changeset
|
301 |
|
611 | 302 |
reset |
303 |
"set the read position to the beginning of the collection" |
|
304 |
||
5308 | 305 |
self resetPosition |
306 |
||
307 |
" |
|
308 |
|s| |
|
309 |
||
310 |
s := 'hello world' readStream. |
|
311 |
Transcript showCR:(s next:5). |
|
312 |
s reset. |
|
313 |
Transcript showCR:(s next:10). |
|
314 |
" |
|
315 |
! |
|
316 |
||
317 |
resetPosition |
|
318 |
"set the read position to the beginning of the collection" |
|
319 |
||
15348 | 320 |
position := 0 |
4405 | 321 |
|
322 |
" |
|
323 |
|s| |
|
324 |
||
325 |
s := 'hello world' readStream. |
|
326 |
Transcript showCR:(s next:5). |
|
327 |
s reset. |
|
328 |
Transcript showCR:(s next:10). |
|
329 |
" |
|
611 | 330 |
! |
331 |
||
332 |
setToEnd |
|
11433 | 333 |
"set the read position to the end of the collection. |
334 |
#next will return EOF, #nextPut: will append to the stream. |
|
335 |
(same Behavior as FileStream." |
|
611 | 336 |
|
15348 | 337 |
position := readLimit |
611 | 338 |
! |
339 |
||
340 |
skip:numberToSkip |
|
341 |
"skip the next numberToSkip elements" |
|
342 |
||
5774 | 343 |
numberToSkip ~~ 0 ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6924
diff
changeset
|
344 |
self position:(self position + numberToSkip) |
5774 | 345 |
] |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
346 |
! |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
347 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
348 |
skipThroughAll:aCollection |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
349 |
"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
|
350 |
return nil if not found, self otherwise. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
351 |
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
|
352 |
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
|
353 |
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
|
354 |
|
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
355 |
|buffer len first idx| |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
356 |
|
16186 | 357 |
self isPositionable ifFalse:[ |
358 |
"/ for non-positionable subclasses |
|
359 |
^ super skipThroughAll:aCollection |
|
360 |
]. |
|
361 |
||
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
362 |
len := aCollection size. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
363 |
first := aCollection at:1. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
364 |
[self atEnd] whileFalse:[ |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
365 |
buffer := self nextAvailable:len. |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
366 |
buffer = aCollection ifTrue:[ |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
367 |
^ self |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
368 |
]. |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
369 |
buffer size == len ifTrue:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
370 |
"expect more input" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
371 |
idx := buffer indexOf:first startingAt:2. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
372 |
idx == 0 ifFalse:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
373 |
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
|
374 |
]. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
375 |
]. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
376 |
]. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
377 |
^ nil |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
378 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
379 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
380 |
|s| |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
381 |
s := ReadStream on:'12345678901234567890a'. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
382 |
s skipThroughAll:'90ab'. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
383 |
s upToEnd |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
384 |
" |
2153
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
385 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
386 |
|s| |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
387 |
s := ReadStream on:'12345678901234567890'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
388 |
s skipThroughAll:'1234'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
389 |
s upToEnd |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
390 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
391 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
392 |
|s| |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
393 |
s := ReadStream on:'12345678901234567890'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
394 |
s skipThroughAll:'999'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
395 |
s atEnd |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
396 |
" |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
397 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
398 |
"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
|
399 |
"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
|
400 |
! |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
401 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
402 |
skipToAll:aCollection |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
403 |
"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
|
404 |
return nil if not found, self otherwise. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
405 |
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
|
406 |
|
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
407 |
|oldPos buffer len first idx| |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
408 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
409 |
oldPos := self position. |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
410 |
len := aCollection size. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
411 |
first := aCollection at:1. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
412 |
[self atEnd] whileFalse:[ |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
413 |
buffer := self nextAvailable:len. |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
414 |
buffer = aCollection ifTrue:[ |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
415 |
self position:(self position - len). |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
416 |
^ self |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
417 |
]. |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
418 |
buffer size == len ifTrue:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
419 |
"more input can be expected" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
420 |
idx := buffer indexOf:first startingAt:2. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
421 |
idx == 0 ifFalse:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
422 |
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
|
423 |
]. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
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 |
self position:oldPos. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
427 |
^ nil |
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 |
|s| |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
431 |
s := ReadStream on:'12345678901234567890'. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
432 |
s skipToAll:'901'. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
433 |
s upToEnd |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
434 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
435 |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
436 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
437 |
|s| |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
438 |
s := ReadStream on:'1234567890'. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
439 |
s skipToAll:'901'. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
440 |
s upToEnd |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
441 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
442 |
|
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
443 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
444 |
|s| |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
445 |
s := 'Makefile' asFilename readStream. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
446 |
[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
447 |
(s skipToAll:'EDIT') notNil ifTrue:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
448 |
s next:100. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
449 |
]. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
450 |
] ensure:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
451 |
s close. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
452 |
] |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
453 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
454 |
|
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
455 |
"Modified: 26.6.1996 / 09:28:27 / cg" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
456 |
"Created: 26.6.1996 / 09:35:06 / cg" |
44 | 457 |
! ! |
611 | 458 |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
459 |
!PositionableStream methodsFor:'printing & storing'! |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
460 |
|
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
461 |
printOn:aStream |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
462 |
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
|
463 |
|
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 |
'' readStream printString |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
466 |
'' writeStream printString |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
467 |
" |
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 |
|
611 | 470 |
!PositionableStream methodsFor:'private'! |
471 |
||
472 |
contentsSpecies |
|
473 |
"return a class of which instances will be returned, when |
|
474 |
parts of the collection are asked for. |
|
15640 | 475 |
(see upTo-kind of methods in Stream)" |
611 | 476 |
|
477 |
^ collection species |
|
478 |
! |
|
479 |
||
480 |
on:aCollection |
|
481 |
"setup for streaming on aCollection" |
|
482 |
||
483 |
collection := aCollection. |
|
484 |
readLimit := aCollection size. |
|
13379 | 485 |
readLimit == 0 ifTrue:[ |
486 |
self assert:(aCollection isCollection) |
|
487 |
]. |
|
15348 | 488 |
position := 0 |
611 | 489 |
! |
490 |
||
491 |
on:aCollection from:first to:last |
|
492 |
"setup for streaming on aCollection from first to last" |
|
493 |
||
494 |
collection := aCollection. |
|
15348 | 495 |
position := first - 1. |
611 | 496 |
readLimit := last |
497 |
! |
|
498 |
||
499 |
positionError |
|
1998 | 500 |
"{ Pragma: +optSpace }" |
501 |
||
2966 | 502 |
"report an error when positioning past the end |
503 |
or before the beginning." |
|
611 | 504 |
|
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
8318
diff
changeset
|
505 |
^ PositionOutOfBoundsError raiseRequestWith:nil |
4452
3d050f505a0a
Raise proceedable signals proceedable.
Stefan Vogel <sv@exept.de>
parents:
4416
diff
changeset
|
506 |
|
3d050f505a0a
Raise proceedable signals proceedable.
Stefan Vogel <sv@exept.de>
parents:
4416
diff
changeset
|
507 |
"Modified: / 26.7.1999 / 10:59:13 / stefan" |
611 | 508 |
! |
509 |
||
6314 | 510 |
positionError:badPostition |
511 |
"{ Pragma: +optSpace }" |
|
512 |
||
513 |
"report an error when positioning past the end |
|
514 |
or before the beginning." |
|
515 |
||
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
8318
diff
changeset
|
516 |
^ PositionOutOfBoundsError raiseRequestWith:badPostition |
6314 | 517 |
! |
518 |
||
611 | 519 |
with:aCollection |
520 |
"setup for streaming to the end of aCollection" |
|
521 |
||
522 |
collection := aCollection. |
|
11434 | 523 |
readLimit := aCollection size. |
611 | 524 |
self setToEnd |
11434 | 525 |
|
526 |
" |
|
527 |
(WriteStream with:#(1 2 3 4 5)) |
|
528 |
nextPut:6; |
|
529 |
contents |
|
530 |
" |
|
611 | 531 |
! ! |
532 |
||
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
533 |
!PositionableStream methodsFor:'reading'! |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
534 |
|
9003 | 535 |
nextAvailable:count |
536 |
|end result| |
|
537 |
||
538 |
end := position + count. |
|
15357 | 539 |
end >= readLimit ifTrue:[ |
9003 | 540 |
end := readLimit. |
541 |
]. |
|
542 |
||
15348 | 543 |
result := collection copyFrom:position+1 to:end. |
9003 | 544 |
position := end. |
545 |
^ result. |
|
546 |
||
547 |
" |
|
548 |
'abc' readStream nextAvailable:1. |
|
549 |
'abc' readStream nextAvailable:2. |
|
550 |
'abc' readStream nextAvailable:3. |
|
551 |
'abc' readStream nextAvailable:4. |
|
552 |
||
553 |
'abc' readStream nextAvailable:2; nextAvailable:2. |
|
554 |
'abc' readStream nextAvailable:3; nextAvailable:3. |
|
555 |
" |
|
556 |
! |
|
557 |
||
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
558 |
upToAll:aCollection |
16186 | 559 |
"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
|
560 |
Return everything read excluding the elements in aCollection. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
561 |
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
|
562 |
read operations will return those elements. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
563 |
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
|
564 |
are read and returned. |
6494 | 565 |
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
|
566 |
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
|
567 |
collection. |
6494 | 568 |
See also #upToAllExcluding:, which returns the same, but leaves the |
569 |
read pointer after the matched subcollection. |
|
3184
d99302322139
Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents:
3170
diff
changeset
|
570 |
|
d99302322139
Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents:
3170
diff
changeset
|
571 |
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
|
572 |
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
|
573 |
this way for the sake of ST80-compatibility." |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
574 |
|
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
575 |
|answerStream element last rslt| |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
576 |
|
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
577 |
last := aCollection last. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
578 |
answerStream := WriteStream on:(self contentsSpecies new). |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
579 |
[self atEnd] whileFalse:[ |
15159
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
580 |
element := self next. |
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
581 |
answerStream nextPut:element. |
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
582 |
element == last ifTrue:[ |
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
583 |
((rslt := answerStream contents) endsWith:aCollection) ifTrue:[ |
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
584 |
self position:(self position - aCollection size). |
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
585 |
^ rslt copyButLast:aCollection size |
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
586 |
] |
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
587 |
]. |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
588 |
]. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
589 |
^ answerStream contents |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
590 |
|
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
591 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
592 |
|s| |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
593 |
s := ReadStream on:'hello world'. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
594 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
6494 | 595 |
Transcript showCR:s atEnd. |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
596 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
597 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
598 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
599 |
|s| |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
600 |
s := ReadStream on:'hello world'. |
16186 | 601 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
602 |
Transcript showCR:s atEnd. |
|
603 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
604 |
" |
|
605 |
" |
|
606 |
|s| |
|
607 |
s := ReadStream on:'hello world'. |
|
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
608 |
Transcript show:'<'; show:(s upToAll:'xx'); showCR:'>'. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
609 |
Transcript showCR:s atEnd. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
610 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
611 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
612 |
|
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
613 |
"Modified: / 12.1.1998 / 22:06:42 / cg" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
614 |
"Created: / 12.1.1998 / 22:07:01 / cg" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
615 |
! ! |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
616 |
|
611 | 617 |
!PositionableStream methodsFor:'testing'! |
618 |
||
619 |
atEnd |
|
620 |
"return true, if the read-position is at the end" |
|
621 |
||
15357 | 622 |
^ position >= readLimit |
611 | 623 |
! |
624 |
||
625 |
isEmpty |
|
626 |
"return true, if the contents of the stream is empty" |
|
627 |
||
628 |
^ readLimit == 0 |
|
9006 | 629 |
! |
630 |
||
10577 | 631 |
isInternalByteStream |
632 |
"return true, if the stream is an internal stream reading bytes" |
|
633 |
||
634 |
^ collection class isBytes |
|
635 |
||
636 |
"Created: / 30-05-2007 / 16:16:12 / cg" |
|
637 |
! |
|
638 |
||
9006 | 639 |
isPositionable |
640 |
"return true, if the stream supports positioning (this one is)" |
|
641 |
||
642 |
^ true |
|
611 | 643 |
! ! |
644 |
||
1897 | 645 |
!PositionableStream class methodsFor:'documentation'! |
701 | 646 |
|
647 |
version |
|
16186 | 648 |
^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.162 2014-03-01 22:09:26 cg Exp $' |
13379 | 649 |
! |
650 |
||
651 |
version_CVS |
|
16186 | 652 |
^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.162 2014-03-01 22:09:26 cg Exp $' |
701 | 653 |
! ! |
6777
5efddf5358b2
currentFileInDirectory query
Claus Gittinger <cg@exept.de>
parents:
6707
diff
changeset
|
654 |
|
14934 | 655 |
|
611 | 656 |
PositionableStream initialize! |