author | Claus Gittinger <cg@exept.de> |
Tue, 15 May 2018 13:08:48 +0200 | |
changeset 22929 | fda0476a0fbd |
parent 22514 | e7e21b6d5ea6 |
child 23895 | d49a46365ed5 |
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 |
|
17559 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
57 | 16 |
PeekableStream subclass:#PositionableStream |
973 | 17 |
instanceVariableNames:'collection position readLimit writeLimit' |
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8363
diff
changeset
|
18 |
classVariableNames:'ZeroPosition InvalidPositionErrorSignal' |
973 | 19 |
poolDictionaries:'' |
20 |
category:'Streams' |
|
1 | 21 |
! |
22 |
||
1897 | 23 |
!PositionableStream class methodsFor:'documentation'! |
88 | 24 |
|
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
159 | 28 |
All Rights Reserved |
1 | 29 |
|
88 | 30 |
This software is furnished under a license and may be used |
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
10 | 38 |
|
88 | 39 |
documentation |
40 |
" |
|
41 |
Instances of PositionableStream allow positioning the read pointer. |
|
42 |
The PositionableStream class also adds methods for source-chunk reading |
|
43 |
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
|
44 |
|
88 | 45 |
This is an abstract class. |
1295 | 46 |
|
4405 | 47 |
Compatibility Notice: |
9434 | 48 |
In previous versions of ST/X, streams started with a 1-position (i.e. as in collections), |
49 |
while ST-80 has always been using 0-based postions for streams and 1-based positions for collections. |
|
4405 | 50 |
|
17559 | 51 |
THIS CERTAINLY IS BAD. |
52 |
||
53 |
Although this is confusing ST/X has been changed to now also uses 0-based stream positioning. |
|
9434 | 54 |
|
17559 | 55 |
[caveat:] |
56 |
Basing capabilities like readability/writability/positionability/peekability on inheritance makes |
|
57 |
the class hierarchy ugly and leads to strange and hard to teach redefinitions (aka. NonPositionableStream |
|
58 |
below PositionableStream or ExternalReadStream under WriteStream) |
|
4405 | 59 |
|
1295 | 60 |
[author:] |
9434 | 61 |
Claus Gittinger |
88 | 62 |
" |
63 |
! ! |
|
1 | 64 |
|
1897 | 65 |
!PositionableStream class methodsFor:'initialization'! |
1 | 66 |
|
10 | 67 |
initialize |
15353 | 68 |
ZeroPosition := 0. "/ changed with stx rel5.1; |
69 |
"/ rel6.2: no longer used (i.e. 0 has now ben hardcoded) |
|
70 |
"/ class variable to be eliminated. |
|
7363 | 71 |
|
8443
7bc4348c059e
fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents:
8363
diff
changeset
|
72 |
InvalidPositionErrorSignal isNil ifTrue:[ |
7092
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7054
diff
changeset
|
73 |
InvalidPositionErrorSignal := PositionOutOfBoundsError. |
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7054
diff
changeset
|
74 |
InvalidPositionErrorSignal notifierString:'position out of bounds: '. |
10 | 75 |
] |
76 |
! ! |
|
1 | 77 |
|
1897 | 78 |
!PositionableStream class methodsFor:'instance creation'! |
1 | 79 |
|
80 |
on:aCollection |
|
81 |
"return a new PositionableStream streaming on aCollection" |
|
82 |
||
83 |
^ (self basicNew) on:aCollection |
|
84 |
! |
|
85 |
||
86 |
on:aCollection from:first to:last |
|
87 |
"return a new PositionableStream streaming on aCollection |
|
88 |
from first to last" |
|
89 |
||
369 | 90 |
^ (self basicNew) on:aCollection from:first to:last |
57 | 91 |
! |
92 |
||
93 |
with:aCollection |
|
94 |
"return a new PositionableStream streaming on aCollection, |
|
95 |
the stream is positioned to the end of the collection." |
|
96 |
||
362 | 97 |
^ (self basicNew) with:aCollection |
1 | 98 |
! ! |
99 |
||
3032
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
100 |
!PositionableStream class methodsFor:'Signal constants'! |
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 |
invalidPositionErrorSignal |
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
103 |
"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
|
104 |
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
|
105 |
the end)" |
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
106 |
|
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
8318
diff
changeset
|
107 |
^ PositionOutOfBoundsError |
3032
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
108 |
! ! |
d267a0b1b48d
handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents:
2966
diff
changeset
|
109 |
|
1897 | 110 |
!PositionableStream class methodsFor:'constants'! |
1 | 111 |
|
4405 | 112 |
zeroPosition |
113 |
"return the number, which marks the initial position. |
|
114 |
Compatibility Notice: |
|
9434 | 115 |
In previous versions of ST/X, streams started with a 1-position (i.e. as in collections), |
116 |
while ST-80 has always been using 0-based postions for streams and 1-based positions for collections. |
|
4405 | 117 |
|
9434 | 118 |
Although this is confusing ST/X has been changed to now also use 0-based stream positioning. |
119 |
" |
|
4405 | 120 |
|
15353 | 121 |
^ 0 |
9434 | 122 |
|
123 |
"Modified: / 13-07-2006 / 20:36:54 / cg" |
|
360 | 124 |
! ! |
125 |
||
21034 | 126 |
!PositionableStream class methodsFor:'testing'! |
127 |
||
128 |
isAbstract |
|
129 |
^ self == PositionableStream |
|
130 |
! ! |
|
131 |
||
7261 | 132 |
!PositionableStream methodsFor:'Compatibility-Dolphin'! |
6413 | 133 |
|
134 |
endChunk |
|
135 |
self nextPutChunkSeparator |
|
136 |
! ! |
|
137 |
||
9284 | 138 |
!PositionableStream methodsFor:'Compatibility-ST/V'! |
139 |
||
140 |
skipTo:anElement |
|
141 |
"ST/V compatibility: |
|
142 |
skip for the element given by the argument, anElement; |
|
143 |
return nil if not found, self otherwise. |
|
144 |
On a successful match, the next read will return the element after anElement." |
|
145 |
||
146 |
^ self skipThrough:anElement |
|
147 |
||
148 |
" |
|
149 |
|s| |
|
150 |
s := ReadStream on:'12345678901234567890'. |
|
151 |
s skipTo:$5. |
|
152 |
s copyFrom:1 to:(s position). |
|
153 |
s upToEnd |
|
154 |
" |
|
155 |
! ! |
|
156 |
||
16876
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
157 |
!PositionableStream methodsFor:'Compatibility-Squeak'! |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
158 |
|
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
159 |
back |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
160 |
"Go back one element and return it." |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
161 |
|
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
162 |
self position = 0 ifTrue: [self positionError]. |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
163 |
self skip: -1. |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
164 |
^ self peek |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
165 |
|
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
166 |
"Created: / 03-10-2014 / 03:06:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
167 |
! |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
168 |
|
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
169 |
peekBack |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
170 |
"Return the element at the previous position, without changing position. Use indirect messages in case self is a StandardFileStream." |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
171 |
|
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
172 |
| element | |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
173 |
element := self back. |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
174 |
self skip: 1. |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
175 |
^ element |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
176 |
|
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
177 |
"Created: / 03-10-2014 / 03:06:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
178 |
! ! |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
179 |
|
1 | 180 |
!PositionableStream methodsFor:'accessing'! |
181 |
||
7686
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7619
diff
changeset
|
182 |
collection |
19591 | 183 |
"return the underlying collection buffer. |
184 |
Notice, that this buffer may become invalid after being retrieved, |
|
185 |
if more data is written to the stream (because a bigger buffer might be |
|
186 |
allocated). Therefore, it should be only used in special situations, |
|
22404 | 187 |
where an already filled buffer needs to be backpatched later |
19591 | 188 |
(eg. before being sent out to some external stream or socket)" |
189 |
||
7686
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7619
diff
changeset
|
190 |
^ collection |
22404 | 191 |
|
192 |
"Modified (comment): / 02-01-2018 / 19:54:37 / stefan" |
|
7686
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7619
diff
changeset
|
193 |
! |
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7619
diff
changeset
|
194 |
|
1 | 195 |
contents |
196 |
"return the entire contents of the stream" |
|
197 |
||
198 |
^ collection |
|
199 |
! |
|
200 |
||
2432 | 201 |
peekForAll:aCollection |
202 |
"return true and advance if the next elements are the same |
|
203 |
as aCollection. |
|
204 |
otherwise stay and let the position unchanged" |
|
205 |
||
206 |
|oldPos| |
|
207 |
||
208 |
oldPos := self position. |
|
209 |
(self next:(aCollection size)) = aCollection ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6924
diff
changeset
|
210 |
^ true |
2432 | 211 |
]. |
212 |
self position:oldPos. |
|
213 |
^ false |
|
214 |
||
215 |
"Created: 1.3.1997 / 15:11:25 / cg" |
|
216 |
! |
|
217 |
||
3905
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
218 |
readLimit |
20423 | 219 |
"return the read-limit; that's the position at which EOF is returned" |
3905
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
220 |
|
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
221 |
^ readLimit |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
222 |
|
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
223 |
"Created: / 30.10.1998 / 16:47:04 / cg" |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
224 |
! |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
225 |
|
1 | 226 |
readLimit:aNumber |
20423 | 227 |
"set the read-limit; that's the position at which EOF is returned" |
1 | 228 |
|
229 |
readLimit := aNumber |
|
369 | 230 |
! |
231 |
||
14934 | 232 |
setCollection:newCollection |
233 |
collection := newCollection |
|
234 |
! |
|
235 |
||
369 | 236 |
writeLimit:aNumber |
20423 | 237 |
"set the writeLimit; that's the position after which writing is prohibited" |
369 | 238 |
|
239 |
writeLimit := aNumber |
|
10592 | 240 |
|
241 |
" |
|
242 |
|s| |
|
243 |
s := WriteStream on:String new. |
|
244 |
s nextPutAll:'hello world'. |
|
245 |
s contents. |
|
246 |
||
247 |
|s| |
|
248 |
s := WriteStream on:String new. |
|
249 |
s writeLimit:5. |
|
250 |
s nextPutAll:'hello world'. |
|
251 |
s contents. |
|
252 |
||
253 |
" |
|
254 |
||
255 |
"Modified: / 04-06-2007 / 17:21:55 / cg" |
|
1 | 256 |
! ! |
257 |
||
17611 | 258 |
!PositionableStream methodsFor:'misc functions'! |
259 |
||
19890 | 260 |
copy:numberOfBytes into:aWriteStream |
261 |
"read from the receiver, and write numberOfBytes data to another aWriteStream. |
|
262 |
Return the number of bytes which have been transferred. |
|
263 |
Redefined here to avoid intermediate buffers/garbage." |
|
264 |
||
265 |
|endPosition cnt| |
|
266 |
||
267 |
collection notNil ifTrue:[ |
|
268 |
endPosition := (position+numberOfBytes) min:readLimit. |
|
269 |
aWriteStream nextPutAll:collection startingAt:position+1 to:endPosition. |
|
270 |
cnt := endPosition - position. |
|
271 |
position := endPosition. |
|
272 |
^ cnt. |
|
273 |
]. |
|
274 |
||
275 |
^ super copy:numberOfBytes into:aWriteStream. |
|
276 |
||
277 |
||
278 |
" |
|
279 |
'hello world' readStream copy:5 into:'/tmp/mist' asFilename writeStream. |
|
280 |
'hello world' readStream |
|
281 |
copy:5 into:Transcript; |
|
282 |
copy:20 into:Transcript. |
|
283 |
'hello world' readStream copy:5 into:'' writeStream inspect. |
|
284 |
#[1 2 3 4 5 6 7] readStream copy:2 into:'/tmp/mist' asFilename writeStream binary. |
|
285 |
#[1 2 3 4 5 6 7] readStream copy:3 into:#[] writeStream. |
|
286 |
" |
|
287 |
||
288 |
" |
|
289 |
|rs ws cnt| |
|
290 |
||
291 |
ws := #() writeStream. |
|
292 |
rs := #( 1 2 3 4 a nil true) readWriteStream. |
|
293 |
rs next. |
|
294 |
cnt := rs copyToEndInto:ws bufferSize:0. |
|
295 |
Transcript show:cnt; show:' '; showCR:ws contents. |
|
296 |
" |
|
297 |
! |
|
298 |
||
299 |
copy:numberOfBytes into:aWriteStream bufferSize:bufferSize |
|
300 |
"read from the receiver, and write numberOfBytes data to another aWriteStream. |
|
301 |
Return the number of bytes which have been transferred. |
|
302 |
Redefined here to avoid intermediate buffers/garbage. |
|
303 |
bufferSize does not matter here." |
|
304 |
||
305 |
collection notNil ifTrue:[ |
|
306 |
^ self copy:numberOfBytes into:aWriteStream. |
|
307 |
]. |
|
308 |
^ super copy:numberOfBytes into:aWriteStream bufferSize:bufferSize. |
|
309 |
! |
|
310 |
||
19403 | 311 |
copyToEndInto:aWriteStream |
17611 | 312 |
"read from the receiver, and write all data up to the end to another stream. |
313 |
Return the number of bytes which have been transferred. |
|
19403 | 314 |
Redefined here to avoid intermediate buffers/garbage." |
17611 | 315 |
|
316 |
|cnt| |
|
317 |
||
318 |
collection notNil ifTrue:[ |
|
319 |
aWriteStream nextPutAll:collection startingAt:position+1 to:readLimit. |
|
320 |
cnt := readLimit - position. |
|
321 |
position := readLimit. |
|
322 |
^ cnt. |
|
323 |
]. |
|
19403 | 324 |
^ super copyToEndInto:aWriteStream. |
325 |
||
326 |
" |
|
327 |
|rs ws cnt| |
|
328 |
||
329 |
ws := #() writeStream. |
|
330 |
rs := #( 1 2 3 4 a nil true) readWriteStream. |
|
331 |
rs next. |
|
332 |
cnt := rs copyToEndInto:ws bufferSize:0. |
|
333 |
Transcript show:cnt; show:' '; showCR:ws contents. |
|
334 |
" |
|
335 |
! |
|
336 |
||
337 |
copyToEndInto:aWriteStream bufferSize:bufferSize |
|
338 |
"read from the receiver, and write all data up to the end to another stream. |
|
339 |
Return the number of bytes which have been transferred. |
|
340 |
Redefined here to avoid intermediate buffers/garbage. |
|
341 |
bufferSize does not matter here." |
|
342 |
||
343 |
collection notNil ifTrue:[ |
|
344 |
^ self copyToEndInto:aWriteStream. |
|
345 |
]. |
|
17611 | 346 |
^ super copyToEndInto:aWriteStream bufferSize:bufferSize. |
347 |
||
348 |
" |
|
349 |
|rs ws cnt| |
|
350 |
||
351 |
ws := #() writeStream. |
|
352 |
rs := #( 1 2 3 4 a nil true) readWriteStream. |
|
353 |
rs next. |
|
354 |
cnt := rs copyToEndInto:ws bufferSize:0. |
|
355 |
Transcript show:cnt; show:' '; showCR:ws contents. |
|
356 |
" |
|
357 |
! ! |
|
358 |
||
21136 | 359 |
!PositionableStream methodsFor:'non homogenous reading'! |
360 |
||
361 |
nextBytes:numBytes into:aCollection startingAt:initialIndex |
|
362 |
"return the next numBytes from the stream. If the end is |
|
22514 | 363 |
reached before, only that many bytes are copied into the |
21136 | 364 |
collection. |
365 |
Returns the number of bytes that have been actually read. |
|
366 |
The receiver must support reading of binary bytes. |
|
367 |
||
368 |
Notice: this method is provided here for protocol completeness |
|
369 |
with externalStreams - it is normally not used with other |
|
370 |
streams." |
|
371 |
||
372 |
|max| |
|
373 |
||
22514 | 374 |
(collection isSingleByteCollection |
22235 | 375 |
and:[aCollection class == collection class or:[aCollection isSingleByteCollection]] |
376 |
) ifTrue:[ |
|
21136 | 377 |
"do it the fast way" |
378 |
max := (readLimit - position) min: numBytes. |
|
379 |
aCollection |
|
22514 | 380 |
replaceBytesFrom:initialIndex |
21136 | 381 |
to:(initialIndex + max - 1) |
22514 | 382 |
with:collection |
21136 | 383 |
startingAt:position+1. |
384 |
position := position + max. |
|
385 |
^ max |
|
386 |
]. |
|
387 |
"do it the hard way" |
|
388 |
^ super nextBytes:numBytes into:aCollection startingAt:initialIndex |
|
389 |
||
390 |
" |
|
391 |
|s n buffer| |
|
392 |
||
393 |
buffer := ByteArray new:10. |
|
394 |
||
395 |
s := ReadStream on:#[1 2 3 4 5 6 7 8 9]. |
|
396 |
s next:3. |
|
397 |
n := s nextBytes:9 into:buffer startingAt:1. |
|
398 |
Transcript showCR:('n = %1; buffer = <%2>' bindWith:n with:buffer) |
|
399 |
" |
|
22514 | 400 |
|
401 |
"Modified (comment): / 29-01-2018 / 14:44:20 / mawalch" |
|
21136 | 402 |
! ! |
403 |
||
611 | 404 |
!PositionableStream methodsFor:'positioning'! |
405 |
||
406 |
backStep |
|
407 |
"move backward read position by one" |
|
408 |
||
4405 | 409 |
self position:(self position - 1) |
611 | 410 |
! |
411 |
||
16188 | 412 |
match: subCollection |
413 |
"Set the access position of the receiver to be past the next occurrence of the subCollection. |
|
414 |
Answer whether subCollection is found. |
|
415 |
No wildcards, and case does matter." |
|
416 |
||
417 |
| pattern startMatch | |
|
418 |
||
419 |
pattern := ReadStream on: subCollection. |
|
420 |
startMatch := nil. |
|
421 |
[pattern atEnd] whileFalse: [ |
|
422 |
self atEnd ifTrue: [^ false]. |
|
423 |
(self next) = (pattern next) |
|
424 |
ifTrue: [pattern position = 1 ifTrue: [startMatch := self position]] |
|
425 |
ifFalse: [ |
|
426 |
pattern position: 0. |
|
427 |
startMatch ifNotNil: [ |
|
428 |
self position: startMatch. |
|
429 |
startMatch := nil |
|
430 |
] |
|
431 |
] |
|
432 |
]. |
|
433 |
^ true |
|
434 |
||
435 |
" |
|
436 |
'abc def ghi' readStream match:'def'; upToEnd |
|
437 |
" |
|
438 |
! |
|
439 |
||
611 | 440 |
position |
15615 | 441 |
"return the read position (0-based)" |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
442 |
|
15348 | 443 |
^ position |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
444 |
! |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
445 |
|
15615 | 446 |
position0Based |
447 |
<resource: #obsolete> |
|
448 |
"return the read position 0-based" |
|
449 |
||
450 |
^ self position |
|
451 |
! |
|
452 |
||
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
453 |
position0Based:index0Based |
15615 | 454 |
<resource: #obsolete> |
4405 | 455 |
"set the read (or write) position" |
611 | 456 |
|
15615 | 457 |
self position:index0Based |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
458 |
! |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
459 |
|
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
460 |
position1Based |
15615 | 461 |
<resource: #obsolete> |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
462 |
"return the read position 1-based" |
611 | 463 |
|
15615 | 464 |
^ self position + 1 |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
465 |
! |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
466 |
|
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
467 |
position1Based:index1Based |
15615 | 468 |
<resource: #obsolete> |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
469 |
"set the read (or write) position" |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
470 |
|
15615 | 471 |
self position:(index1Based - 1) |
4405 | 472 |
|
473 |
" |
|
474 |
|s| |
|
475 |
||
476 |
s := '1234567890' readStream. |
|
477 |
s next:5. |
|
478 |
s position:1. |
|
479 |
s next:7. |
|
480 |
" |
|
481 |
||
482 |
" |
|
483 |
|s| |
|
484 |
||
485 |
s := '' writeStream. |
|
486 |
s nextPutAll:'1234567890'. |
|
487 |
s position:5. |
|
488 |
s nextPutAll:'abcdefg'. |
|
489 |
s contents |
|
490 |
" |
|
491 |
||
492 |
" |
|
493 |
|s| |
|
494 |
||
495 |
s := '' writeStream. |
|
496 |
s nextPutAll:'1234567890'. |
|
497 |
s position:0. |
|
498 |
s nextPutAll:'abcdefg'. |
|
499 |
s contents |
|
500 |
" |
|
611 | 501 |
! |
502 |
||
15615 | 503 |
position:index0Based |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
504 |
"set the read (or write) position" |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
505 |
|
15615 | 506 |
((index0Based > readLimit) or:[index0Based < 0]) ifTrue: [^ self positionError:index0Based]. |
507 |
position := index0Based |
|
6626
f7b08d6bee3f
#positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents:
6538
diff
changeset
|
508 |
! |
f7b08d6bee3f
#positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents:
6538
diff
changeset
|
509 |
|
611 | 510 |
reset |
511 |
"set the read position to the beginning of the collection" |
|
512 |
||
19885 | 513 |
position := 0. |
5308 | 514 |
|
515 |
" |
|
516 |
|s| |
|
517 |
||
518 |
s := 'hello world' readStream. |
|
519 |
Transcript showCR:(s next:5). |
|
520 |
s reset. |
|
521 |
Transcript showCR:(s next:10). |
|
522 |
" |
|
523 |
! |
|
524 |
||
525 |
resetPosition |
|
19885 | 526 |
<resource: #obsolete> |
5308 | 527 |
"set the read position to the beginning of the collection" |
528 |
||
15348 | 529 |
position := 0 |
4405 | 530 |
|
531 |
" |
|
532 |
|s| |
|
533 |
||
534 |
s := 'hello world' readStream. |
|
535 |
Transcript showCR:(s next:5). |
|
536 |
s reset. |
|
537 |
Transcript showCR:(s next:10). |
|
538 |
" |
|
611 | 539 |
! |
540 |
||
541 |
setToEnd |
|
11433 | 542 |
"set the read position to the end of the collection. |
543 |
#next will return EOF, #nextPut: will append to the stream. |
|
544 |
(same Behavior as FileStream." |
|
611 | 545 |
|
15348 | 546 |
position := readLimit |
611 | 547 |
! |
548 |
||
549 |
skip:numberToSkip |
|
550 |
"skip the next numberToSkip elements" |
|
551 |
||
5774 | 552 |
numberToSkip ~~ 0 ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6924
diff
changeset
|
553 |
self position:(self position + numberToSkip) |
5774 | 554 |
] |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
555 |
! |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
556 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
557 |
skipThroughAll:aCollection |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
558 |
"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
|
559 |
return nil if not found, self otherwise. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
560 |
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
|
561 |
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
|
562 |
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
|
563 |
|
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
564 |
|buffer len first idx| |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
565 |
|
16186 | 566 |
self isPositionable ifFalse:[ |
567 |
"/ for non-positionable subclasses |
|
568 |
^ super skipThroughAll:aCollection |
|
569 |
]. |
|
570 |
||
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
571 |
len := aCollection size. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
572 |
first := aCollection at:1. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
573 |
[self atEnd] whileFalse:[ |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
574 |
buffer := self nextAvailable:len. |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
575 |
buffer size == len ifTrue:[ |
16209 | 576 |
buffer = aCollection ifTrue:[ |
577 |
^ self |
|
578 |
]. |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
579 |
"expect more input" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
580 |
idx := buffer indexOf:first startingAt:2. |
16209 | 581 |
idx ~~ 0 ifTrue:[ |
582 |
self skip:(idx - len - 1) |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
583 |
]. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
584 |
]. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
585 |
]. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
586 |
^ nil |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
587 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
588 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
589 |
|s| |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
590 |
s := ReadStream on:'12345678901234567890a'. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
591 |
s skipThroughAll:'90ab'. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
592 |
s upToEnd |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
593 |
" |
2153
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
594 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
595 |
|s| |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
596 |
s := ReadStream on:'12345678901234567890'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
597 |
s skipThroughAll:'1234'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
598 |
s upToEnd |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
599 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
600 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
601 |
|s| |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
602 |
s := ReadStream on:'12345678901234567890'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
603 |
s skipThroughAll:'999'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
604 |
s atEnd |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
605 |
" |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
606 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
607 |
"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
|
608 |
"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
|
609 |
! |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
610 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
611 |
skipToAll:aCollection |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
612 |
"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
|
613 |
return nil if not found, self otherwise. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
614 |
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
|
615 |
|
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
616 |
|oldPos buffer len first idx| |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
617 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
618 |
oldPos := self position. |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
619 |
len := aCollection size. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
620 |
first := aCollection at:1. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
621 |
[self atEnd] whileFalse:[ |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
622 |
buffer := self nextAvailable:len. |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
623 |
buffer = aCollection ifTrue:[ |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
624 |
self position:(self position - len). |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
625 |
^ self |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
626 |
]. |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
627 |
buffer size == len ifTrue:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
628 |
"more input can be expected" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
629 |
idx := buffer indexOf:first startingAt:2. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
630 |
idx == 0 ifFalse:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
631 |
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
|
632 |
]. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
633 |
]. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
634 |
]. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
635 |
self position:oldPos. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
636 |
^ nil |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
637 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
638 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
639 |
|s| |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
640 |
s := ReadStream on:'12345678901234567890'. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
641 |
s skipToAll:'901'. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
642 |
s upToEnd |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
643 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
644 |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
645 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
646 |
|s| |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
647 |
s := ReadStream on:'1234567890'. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
648 |
s skipToAll:'901'. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
649 |
s upToEnd |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
650 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
651 |
|
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
652 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
653 |
|s| |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
654 |
s := 'Makefile' asFilename readStream. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
655 |
[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
656 |
(s skipToAll:'EDIT') notNil ifTrue:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
657 |
s next:100. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
658 |
]. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
659 |
] ensure:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
660 |
s close. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
661 |
] |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
662 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
663 |
|
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
664 |
"Modified: 26.6.1996 / 09:28:27 / cg" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
665 |
"Created: 26.6.1996 / 09:35:06 / cg" |
44 | 666 |
! ! |
611 | 667 |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
668 |
!PositionableStream methodsFor:'printing & storing'! |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
669 |
|
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
670 |
printOn:aStream |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
671 |
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
|
672 |
|
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
673 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
674 |
'' readStream printString |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
675 |
'' writeStream printString |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
676 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
677 |
! ! |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
678 |
|
611 | 679 |
!PositionableStream methodsFor:'private'! |
680 |
||
681 |
contentsSpecies |
|
682 |
"return a class of which instances will be returned, when |
|
683 |
parts of the collection are asked for. |
|
15640 | 684 |
(see upTo-kind of methods in Stream)" |
611 | 685 |
|
686 |
^ collection species |
|
687 |
! |
|
688 |
||
689 |
on:aCollection |
|
690 |
"setup for streaming on aCollection" |
|
691 |
||
692 |
collection := aCollection. |
|
693 |
readLimit := aCollection size. |
|
13379 | 694 |
readLimit == 0 ifTrue:[ |
695 |
self assert:(aCollection isCollection) |
|
696 |
]. |
|
15348 | 697 |
position := 0 |
611 | 698 |
! |
699 |
||
700 |
on:aCollection from:first to:last |
|
701 |
"setup for streaming on aCollection from first to last" |
|
702 |
||
703 |
collection := aCollection. |
|
15348 | 704 |
position := first - 1. |
611 | 705 |
readLimit := last |
706 |
! |
|
707 |
||
708 |
positionError |
|
1998 | 709 |
"{ Pragma: +optSpace }" |
710 |
||
2966 | 711 |
"report an error when positioning past the end |
712 |
or before the beginning." |
|
611 | 713 |
|
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
8318
diff
changeset
|
714 |
^ PositionOutOfBoundsError raiseRequestWith:nil |
4452
3d050f505a0a
Raise proceedable signals proceedable.
Stefan Vogel <sv@exept.de>
parents:
4416
diff
changeset
|
715 |
|
3d050f505a0a
Raise proceedable signals proceedable.
Stefan Vogel <sv@exept.de>
parents:
4416
diff
changeset
|
716 |
"Modified: / 26.7.1999 / 10:59:13 / stefan" |
611 | 717 |
! |
718 |
||
6314 | 719 |
positionError:badPostition |
720 |
"{ Pragma: +optSpace }" |
|
721 |
||
722 |
"report an error when positioning past the end |
|
723 |
or before the beginning." |
|
724 |
||
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
8318
diff
changeset
|
725 |
^ PositionOutOfBoundsError raiseRequestWith:badPostition |
6314 | 726 |
! |
727 |
||
611 | 728 |
with:aCollection |
729 |
"setup for streaming to the end of aCollection" |
|
730 |
||
731 |
collection := aCollection. |
|
11434 | 732 |
readLimit := aCollection size. |
611 | 733 |
self setToEnd |
11434 | 734 |
|
735 |
" |
|
736 |
(WriteStream with:#(1 2 3 4 5)) |
|
737 |
nextPut:6; |
|
738 |
contents |
|
739 |
" |
|
611 | 740 |
! ! |
741 |
||
16195 | 742 |
!PositionableStream methodsFor:'queries'! |
743 |
||
16209 | 744 |
endsBeforePositionWith:aSequenceableCollection |
16195 | 745 |
"answer true, if the elements in aSequenceableCollection |
16209 | 746 |
are at the current end of the stream up to position." |
16195 | 747 |
|
16209 | 748 |
|sz pos| |
16195 | 749 |
|
16209 | 750 |
sz := aSequenceableCollection size. |
751 |
pos := self position. |
|
752 |
pos < sz ifTrue:[ |
|
753 |
^ false. |
|
16195 | 754 |
]. |
16209 | 755 |
self contentsSpecies == collection class ifTrue:[ |
756 |
^ collection sameContentsFrom:pos+1-sz to:pos as:aSequenceableCollection startingAt:1. |
|
757 |
]. |
|
758 |
self position:pos-sz. |
|
759 |
^ (self next:sz) = aSequenceableCollection. |
|
16195 | 760 |
|
761 |
" |
|
16209 | 762 |
('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'World' |
763 |
('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'Hello World' |
|
764 |
('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'Hello Worldx' |
|
765 |
('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'Bla' |
|
766 |
('' writeStream) endsBeforePositionWith:'Bla' |
|
767 |
('' writeStream) endsBeforePositionWith:'' |
|
16195 | 768 |
'' endsWith:'' |
769 |
" |
|
770 |
! ! |
|
771 |
||
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
772 |
!PositionableStream methodsFor:'reading'! |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
773 |
|
9003 | 774 |
nextAvailable:count |
22204 | 775 |
"return the next count elements of the stream as aCollection. |
776 |
If the stream reaches the end before count elements have been read, |
|
777 |
return what is available. (i.e. a shorter collection)." |
|
778 |
||
17606 | 779 |
collection notNil ifTrue:[ |
780 |
|end result| |
|
9003 | 781 |
|
17606 | 782 |
end := position + count. |
783 |
end >= readLimit ifTrue:[ |
|
784 |
end := readLimit. |
|
785 |
]. |
|
786 |
||
787 |
result := collection copyFrom:position+1 to:end. |
|
788 |
position := end. |
|
789 |
^ result. |
|
9003 | 790 |
]. |
791 |
||
17606 | 792 |
^ super nextAvailable:count. |
9003 | 793 |
|
794 |
" |
|
795 |
'abc' readStream nextAvailable:1. |
|
796 |
'abc' readStream nextAvailable:2. |
|
797 |
'abc' readStream nextAvailable:3. |
|
798 |
'abc' readStream nextAvailable:4. |
|
799 |
||
800 |
'abc' readStream nextAvailable:2; nextAvailable:2. |
|
801 |
'abc' readStream nextAvailable:3; nextAvailable:3. |
|
802 |
" |
|
22204 | 803 |
|
804 |
"Modified (format): / 22-08-2017 / 20:25:54 / cg" |
|
9003 | 805 |
! |
806 |
||
17611 | 807 |
nextAvailable:count into:aCollection startingAt:initialIndex |
808 |
"return the next count objects from the stream. If the end is |
|
22514 | 809 |
reached before, only that many objects are copied into the |
17611 | 810 |
collection. |
811 |
Returns the number of objects that have been actually read." |
|
812 |
||
813 |
| max | |
|
814 |
||
815 |
collection notNil ifTrue:[ |
|
816 |
max := (readLimit - position) min: count. |
|
817 |
aCollection |
|
818 |
replaceFrom: initialIndex |
|
819 |
to: initialIndex+max-1 |
|
820 |
with: collection |
|
821 |
startingAt: position+1. |
|
822 |
position := position + max. |
|
823 |
^ max. |
|
824 |
]. |
|
825 |
||
826 |
^ super nextAvailable:count into:aCollection startingAt:initialIndex. |
|
827 |
||
828 |
" |
|
829 |
|s n buffer| |
|
830 |
||
831 |
buffer := ByteArray new:10. |
|
832 |
||
833 |
s := ReadStream on:#[1 2 3 4 5 6 7 8 9]. |
|
834 |
s next:3. |
|
835 |
n := s nextBytes:9 into:buffer startingAt:1. |
|
836 |
Transcript showCR:('n = %1; buffer = <%2>' bindWith:n with:buffer) |
|
837 |
" |
|
22514 | 838 |
|
839 |
"Modified (comment): / 29-01-2018 / 14:43:56 / mawalch" |
|
17611 | 840 |
! |
841 |
||
21136 | 842 |
peek |
843 |
"look ahead for and return the next element" |
|
17611 | 844 |
|
21136 | 845 |
|peekObject| |
20691 | 846 |
|
21136 | 847 |
peekObject := self next. |
848 |
self backStep. |
|
849 |
^ peekObject |
|
20691 | 850 |
! |
851 |
||
22003 | 852 |
peek:n |
853 |
"look ahead n elements and return them after positioning pack to the |
|
854 |
position we had before" |
|
855 |
||
856 |
|posBefore peekObjects| |
|
857 |
||
858 |
posBefore := self position. |
|
859 |
peekObjects := self next:n. |
|
860 |
self position:posBefore. |
|
861 |
^ peekObjects |
|
862 |
||
863 |
" |
|
864 |
|s| |
|
865 |
||
866 |
s := '1234567890' readStream. |
|
867 |
s peek:4. |
|
868 |
s next:5. |
|
869 |
" |
|
870 |
||
871 |
"Created: / 13-07-2017 / 12:32:03 / cg" |
|
872 |
! |
|
873 |
||
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
874 |
upToAll:aCollection |
16186 | 875 |
"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
|
876 |
Return everything read excluding the elements in aCollection. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
877 |
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
|
878 |
read operations will return those elements. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
879 |
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
|
880 |
are read and returned. |
6494 | 881 |
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
|
882 |
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
|
883 |
collection. |
6494 | 884 |
See also #upToAllExcluding:, which returns the same, but leaves the |
885 |
read pointer after the matched subcollection. |
|
3184
d99302322139
Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents:
3170
diff
changeset
|
886 |
|
d99302322139
Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents:
3170
diff
changeset
|
887 |
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
|
888 |
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
|
889 |
this way for the sake of ST80-compatibility." |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
890 |
|
17611 | 891 |
"/ in the future, this will have the Squeak semantics, which is upToAllExcluding: |
16189 | 892 |
|
893 |
^ self upToAll_positionBefore:aCollection |
|
894 |
||
895 |
" |
|
896 |
|s| |
|
897 |
s := ReadStream on:'hello world'. |
|
898 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
899 |
Transcript showCR:s atEnd. |
|
900 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
|
901 |
" |
|
902 |
" |
|
903 |
|s| |
|
904 |
s := ReadStream on:'hello world'. |
|
905 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
906 |
Transcript showCR:s atEnd. |
|
907 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
908 |
" |
|
909 |
" |
|
910 |
|s| |
|
911 |
s := ReadStream on:'hello world'. |
|
912 |
Transcript show:'<'; show:(s upToAll:'xx'); showCR:'>'. |
|
913 |
Transcript showCR:s atEnd. |
|
914 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
|
915 |
" |
|
916 |
||
917 |
"Modified: / 12.1.1998 / 22:06:42 / cg" |
|
918 |
"Created: / 12.1.1998 / 22:07:01 / cg" |
|
919 |
! |
|
920 |
||
921 |
upToAll_positionBefore:aCollection |
|
922 |
"read until a subcollection consisisting of the elements in aCollection is encountered. |
|
923 |
Return everything read excluding the elements in aCollection. |
|
924 |
The position is left before the collection; i.e. the next |
|
925 |
read operations will return those elements. |
|
926 |
If no such subcollection is encountered, all elements up to the end |
|
927 |
are read and returned. |
|
928 |
See also #throughAll: which also reads up to some objects |
|
929 |
but positions behind it and DOES include it in the returned |
|
16840 | 930 |
collection." |
16189 | 931 |
|
16209 | 932 |
|answerStream element last| |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
933 |
|
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
934 |
last := aCollection last. |
22410 | 935 |
answerStream := self contentsSpecies writeStream. |
16209 | 936 |
[(element := self nextOrNil) notNil] whileTrue:[ |
15159
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
937 |
answerStream nextPut:element. |
16209 | 938 |
(element = last and:[answerStream endsBeforePositionWith:aCollection]) ifTrue:[ |
939 |
|backStep| |
|
940 |
backStep := aCollection size negated. |
|
941 |
self skip:backStep. |
|
942 |
answerStream skip:backStep. |
|
943 |
^ answerStream contents |
|
15159
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
944 |
]. |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
945 |
]. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
946 |
^ answerStream contents |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
947 |
|
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
948 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
949 |
|s| |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
950 |
s := ReadStream on:'hello world'. |
16209 | 951 |
Transcript show:'<'; show:(s upToAll_positionBefore:'wo'); showCR:'>'. |
6494 | 952 |
Transcript showCR:s atEnd. |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
953 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
954 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
955 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
956 |
|s| |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
957 |
s := ReadStream on:'hello world'. |
16209 | 958 |
Transcript show:'<'; show:(s upToAll_positionBefore:'wo'); showCR:'>'. |
16186 | 959 |
Transcript showCR:s atEnd. |
16209 | 960 |
Transcript show:'<'; show:(s upToAll_positionBefore:'wo'); showCR:'>'. |
16186 | 961 |
" |
962 |
" |
|
963 |
|s| |
|
964 |
s := ReadStream on:'hello world'. |
|
16209 | 965 |
Transcript show:'<'; show:(s upToAll_positionBefore:'xx'); showCR:'>'. |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
966 |
Transcript showCR:s atEnd. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
967 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
968 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
969 |
|
22410 | 970 |
"Created: / 12-01-1998 / 22:07:01 / cg" |
971 |
"Modified: / 10-01-2018 / 18:30:07 / stefan" |
|
20101 | 972 |
! |
973 |
||
974 |
upToEnd |
|
975 |
collection notNil ifTrue:[ |
|
976 |
|result| |
|
977 |
||
978 |
result := collection copyFrom:position+1 to:readLimit. |
|
979 |
position := readLimit. |
|
980 |
^ result. |
|
981 |
]. |
|
982 |
||
983 |
^ super upToEnd. |
|
984 |
||
985 |
" |
|
986 |
'abc' readStream upToEnd. |
|
987 |
" |
|
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
988 |
! ! |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
989 |
|
21136 | 990 |
!PositionableStream methodsFor:'reading-strings'! |
991 |
||
992 |
nextLine |
|
993 |
"return the characters upTo (but excluding) the next cr (carriage return) |
|
994 |
character (i.e. read a single line of text). |
|
995 |
If the previous-to-last character is a cr, this is also removed, |
|
996 |
so it's possible to read alien (i.e. ms-dos) text as well. |
|
997 |
Added for protocol compatibility with externalStreams." |
|
998 |
||
999 |
|start "{ Class:SmallInteger }" |
|
1000 |
end "{ Class:SmallInteger }"| |
|
1001 |
||
1002 |
collection isString ifTrue:[ |
|
1003 |
position == readLimit ifTrue:[ |
|
1004 |
^ self pastEndRead |
|
1005 |
]. |
|
1006 |
start := position+1. |
|
1007 |
end := collection indexOf:Character cr startingAt:start. |
|
1008 |
||
1009 |
(end == 0 or:[end > readLimit]) ifTrue:[ |
|
1010 |
end := position := readLimit. |
|
1011 |
] ifFalse:[ |
|
1012 |
position := end. |
|
1013 |
end := end - 1. "skip lf" |
|
1014 |
]. |
|
1015 |
start > end ifTrue:[ |
|
1016 |
^ ''. |
|
1017 |
]. |
|
1018 |
(collection at:end) == Character return ifTrue:[ |
|
1019 |
end := end - 1. "skip return" |
|
1020 |
]. |
|
1021 |
^ collection copyFrom:start to:end. |
|
1022 |
]. |
|
1023 |
^ super nextLine. |
|
1024 |
||
1025 |
" |
|
1026 |
'12345678' readStream nextLine |
|
1027 |
'12345678' allBold readStream nextLine |
|
1028 |
'12\34\56\78' withCRs readStream nextLine |
|
1029 |
'12\34\56\78' withCRs readStream nextLine; nextLine |
|
1030 |
(ReadStream on:('12\34\56\78' withCRs) from:1 to:4) nextLine; nextLine |
|
1031 |
('12\' withCRs, Character return, '34') readStream nextLine; nextLine |
|
1032 |
Character cr asString readStream nextLine |
|
1033 |
Character return asString readStream nextLine |
|
1034 |
(Character return, Character cr) asString readStream nextLine |
|
1035 |
Character return asString readStream nextLine; nextLine |
|
1036 |
" |
|
1037 |
! ! |
|
1038 |
||
611 | 1039 |
!PositionableStream methodsFor:'testing'! |
1040 |
||
1041 |
atEnd |
|
1042 |
"return true, if the read-position is at the end" |
|
1043 |
||
15357 | 1044 |
^ position >= readLimit |
611 | 1045 |
! |
1046 |
||
1047 |
isEmpty |
|
1048 |
"return true, if the contents of the stream is empty" |
|
1049 |
||
1050 |
^ readLimit == 0 |
|
9006 | 1051 |
! |
1052 |
||
10577 | 1053 |
isInternalByteStream |
1054 |
"return true, if the stream is an internal stream reading bytes" |
|
1055 |
||
1056 |
^ collection class isBytes |
|
1057 |
||
1058 |
"Created: / 30-05-2007 / 16:16:12 / cg" |
|
1059 |
! |
|
1060 |
||
9006 | 1061 |
isPositionable |
1062 |
"return true, if the stream supports positioning (this one is)" |
|
1063 |
||
1064 |
^ true |
|
611 | 1065 |
! ! |
1066 |
||
1897 | 1067 |
!PositionableStream class methodsFor:'documentation'! |
701 | 1068 |
|
1069 |
version |
|
19403 | 1070 |
^ '$Header$' |
13379 | 1071 |
! |
1072 |
||
1073 |
version_CVS |
|
19403 | 1074 |
^ '$Header$' |
701 | 1075 |
! ! |
6777
5efddf5358b2
currentFileInDirectory query
Claus Gittinger <cg@exept.de>
parents:
6707
diff
changeset
|
1076 |
|
14934 | 1077 |
|
611 | 1078 |
PositionableStream initialize! |