author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sat, 09 Jul 2016 21:10:24 +0100 | |
branch | jv |
changeset 20131 | 4118d61ddba0 |
parent 19892 | d1aecb538df5 |
parent 20101 | 2571117831be |
child 20398 | 8cb53f870d39 |
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 |
||
20101 | 126 |
|
7261 | 127 |
!PositionableStream methodsFor:'Compatibility-Dolphin'! |
6413 | 128 |
|
129 |
endChunk |
|
130 |
self nextPutChunkSeparator |
|
131 |
! ! |
|
132 |
||
9284 | 133 |
!PositionableStream methodsFor:'Compatibility-ST/V'! |
134 |
||
135 |
skipTo:anElement |
|
136 |
"ST/V compatibility: |
|
137 |
skip for the element given by the argument, anElement; |
|
138 |
return nil if not found, self otherwise. |
|
139 |
On a successful match, the next read will return the element after anElement." |
|
140 |
||
141 |
^ self skipThrough:anElement |
|
142 |
||
143 |
" |
|
144 |
|s| |
|
145 |
s := ReadStream on:'12345678901234567890'. |
|
146 |
s skipTo:$5. |
|
147 |
s copyFrom:1 to:(s position). |
|
148 |
s upToEnd |
|
149 |
" |
|
150 |
! ! |
|
151 |
||
16876
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
152 |
!PositionableStream methodsFor:'Compatibility-Squeak'! |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
153 |
|
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
154 |
back |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
155 |
"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
|
156 |
|
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
157 |
self position = 0 ifTrue: [self positionError]. |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
158 |
self skip: -1. |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
159 |
^ self peek |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
160 |
|
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
161 |
"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
|
162 |
! |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
163 |
|
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
164 |
peekBack |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
165 |
"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
|
166 |
|
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
167 |
| element | |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
168 |
element := self back. |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
169 |
self skip: 1. |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
170 |
^ element |
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 |
"Created: / 03-10-2014 / 03:06:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
18260
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
173 |
! |
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
174 |
|
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
175 |
upToAnyOf: aCollection |
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
176 |
"Answer a subcollection from the current access position to the |
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
177 |
occurrence (if any, but not inclusive) of any object in the collection. If |
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
178 |
no matching object is found, answer the entire rest of the receiver." |
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
179 |
^self upToAnyOf: aCollection do: [:matchingObject | ] |
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
180 |
|
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
181 |
"Created: / 21-04-2015 / 17:25:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
182 |
! |
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
183 |
|
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
184 |
upToAnyOf: subcollection do: aBlock |
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
185 |
"Answer a subcollection from the current access position to the occurrence (if any, but not inclusive) of any object in the collection. |
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
186 |
Evaluate aBlock with this occurence as argument. |
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
187 |
If no matching object is found, don't evaluate aBlock and answer the entire rest of the receiver." |
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
188 |
|
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
189 |
^self collection species new: 1000 streamContents: [ :stream | |
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
190 |
| ch | |
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
191 |
[ self atEnd or: [ (subcollection includes: (ch := self next)) and: [aBlock value: ch. true] ] ] |
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
192 |
whileFalse: [ stream nextPut: ch ] ] |
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
193 |
|
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
194 |
"Created: / 21-04-2015 / 17:26:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
16876
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
195 |
! ! |
7e3ad01ca413
Added: #back / #peekBack for Squeak compatibility.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16840
diff
changeset
|
196 |
|
1 | 197 |
!PositionableStream methodsFor:'accessing'! |
198 |
||
7686
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7619
diff
changeset
|
199 |
collection |
19591 | 200 |
"return the underlying collection buffer. |
201 |
Notice, that this buffer may become invalid after being retrieved, |
|
202 |
if more data is written to the stream (because a bigger buffer might be |
|
203 |
allocated). Therefore, it should be only used in special situations, |
|
204 |
where an already filed buffer needs to be backpatched later |
|
205 |
(eg. before being sent out to some external stream or socket)" |
|
206 |
||
7686
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7619
diff
changeset
|
207 |
^ collection |
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7619
diff
changeset
|
208 |
! |
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7619
diff
changeset
|
209 |
|
1 | 210 |
contents |
211 |
"return the entire contents of the stream" |
|
212 |
||
213 |
^ collection |
|
214 |
! |
|
215 |
||
216 |
peek |
|
217 |
"look ahead for and return the next element" |
|
218 |
||
219 |
|peekObject| |
|
220 |
||
221 |
peekObject := self next. |
|
10 | 222 |
self backStep. |
1 | 223 |
^ peekObject |
224 |
! |
|
225 |
||
2432 | 226 |
peekForAll:aCollection |
227 |
"return true and advance if the next elements are the same |
|
228 |
as aCollection. |
|
229 |
otherwise stay and let the position unchanged" |
|
230 |
||
231 |
|oldPos| |
|
232 |
||
233 |
oldPos := self position. |
|
234 |
(self next:(aCollection size)) = aCollection ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6924
diff
changeset
|
235 |
^ true |
2432 | 236 |
]. |
237 |
self position:oldPos. |
|
238 |
^ false |
|
239 |
||
240 |
"Created: 1.3.1997 / 15:11:25 / cg" |
|
241 |
! |
|
242 |
||
3905
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
243 |
readLimit |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
244 |
"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
|
245 |
|
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
246 |
^ readLimit |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
247 |
|
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
248 |
"Created: / 30.10.1998 / 16:47:04 / cg" |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
249 |
! |
682fc38fd339
added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents:
3604
diff
changeset
|
250 |
|
1 | 251 |
readLimit:aNumber |
369 | 252 |
"set the read-limit; thats the position at which EOF is returned" |
1 | 253 |
|
254 |
readLimit := aNumber |
|
369 | 255 |
! |
256 |
||
14934 | 257 |
setCollection:newCollection |
258 |
collection := newCollection |
|
259 |
! |
|
260 |
||
369 | 261 |
writeLimit:aNumber |
262 |
"set the writeLimit; thats the position after which writing is prohibited" |
|
263 |
||
264 |
writeLimit := aNumber |
|
10592 | 265 |
|
266 |
" |
|
267 |
|s| |
|
268 |
s := WriteStream on:String new. |
|
269 |
s nextPutAll:'hello world'. |
|
270 |
s contents. |
|
271 |
||
272 |
|s| |
|
273 |
s := WriteStream on:String new. |
|
274 |
s writeLimit:5. |
|
275 |
s nextPutAll:'hello world'. |
|
276 |
s contents. |
|
277 |
||
278 |
" |
|
279 |
||
280 |
"Modified: / 04-06-2007 / 17:21:55 / cg" |
|
1 | 281 |
! ! |
282 |
||
17611 | 283 |
!PositionableStream methodsFor:'misc functions'! |
284 |
||
19890 | 285 |
copy:numberOfBytes into:aWriteStream |
286 |
"read from the receiver, and write numberOfBytes data to another aWriteStream. |
|
287 |
Return the number of bytes which have been transferred. |
|
288 |
Redefined here to avoid intermediate buffers/garbage." |
|
289 |
||
290 |
|endPosition cnt| |
|
291 |
||
292 |
collection notNil ifTrue:[ |
|
293 |
endPosition := (position+numberOfBytes) min:readLimit. |
|
294 |
aWriteStream nextPutAll:collection startingAt:position+1 to:endPosition. |
|
295 |
cnt := endPosition - position. |
|
296 |
position := endPosition. |
|
297 |
^ cnt. |
|
298 |
]. |
|
299 |
||
300 |
^ super copy:numberOfBytes into:aWriteStream. |
|
301 |
||
302 |
||
303 |
" |
|
304 |
'hello world' readStream copy:5 into:'/tmp/mist' asFilename writeStream. |
|
305 |
'hello world' readStream |
|
306 |
copy:5 into:Transcript; |
|
307 |
copy:20 into:Transcript. |
|
308 |
'hello world' readStream copy:5 into:'' writeStream inspect. |
|
309 |
#[1 2 3 4 5 6 7] readStream copy:2 into:'/tmp/mist' asFilename writeStream binary. |
|
310 |
#[1 2 3 4 5 6 7] readStream copy:3 into:#[] writeStream. |
|
311 |
" |
|
312 |
||
313 |
" |
|
314 |
|rs ws cnt| |
|
315 |
||
316 |
ws := #() writeStream. |
|
317 |
rs := #( 1 2 3 4 a nil true) readWriteStream. |
|
318 |
rs next. |
|
319 |
cnt := rs copyToEndInto:ws bufferSize:0. |
|
320 |
Transcript show:cnt; show:' '; showCR:ws contents. |
|
321 |
" |
|
322 |
! |
|
323 |
||
324 |
copy:numberOfBytes into:aWriteStream bufferSize:bufferSize |
|
325 |
"read from the receiver, and write numberOfBytes data to another aWriteStream. |
|
326 |
Return the number of bytes which have been transferred. |
|
327 |
Redefined here to avoid intermediate buffers/garbage. |
|
328 |
bufferSize does not matter here." |
|
329 |
||
330 |
collection notNil ifTrue:[ |
|
331 |
^ self copy:numberOfBytes into:aWriteStream. |
|
332 |
]. |
|
333 |
^ super copy:numberOfBytes into:aWriteStream bufferSize:bufferSize. |
|
334 |
! |
|
335 |
||
19403 | 336 |
copyToEndInto:aWriteStream |
17611 | 337 |
"read from the receiver, and write all data up to the end to another stream. |
338 |
Return the number of bytes which have been transferred. |
|
19403 | 339 |
Redefined here to avoid intermediate buffers/garbage." |
17611 | 340 |
|
341 |
|cnt| |
|
342 |
||
343 |
collection notNil ifTrue:[ |
|
344 |
aWriteStream nextPutAll:collection startingAt:position+1 to:readLimit. |
|
345 |
cnt := readLimit - position. |
|
346 |
position := readLimit. |
|
347 |
^ cnt. |
|
348 |
]. |
|
19403 | 349 |
^ super copyToEndInto:aWriteStream. |
350 |
||
351 |
" |
|
352 |
|rs ws cnt| |
|
353 |
||
354 |
ws := #() writeStream. |
|
355 |
rs := #( 1 2 3 4 a nil true) readWriteStream. |
|
356 |
rs next. |
|
357 |
cnt := rs copyToEndInto:ws bufferSize:0. |
|
358 |
Transcript show:cnt; show:' '; showCR:ws contents. |
|
359 |
" |
|
360 |
! |
|
361 |
||
362 |
copyToEndInto:aWriteStream bufferSize:bufferSize |
|
363 |
"read from the receiver, and write all data up to the end to another stream. |
|
364 |
Return the number of bytes which have been transferred. |
|
365 |
Redefined here to avoid intermediate buffers/garbage. |
|
366 |
bufferSize does not matter here." |
|
367 |
||
368 |
collection notNil ifTrue:[ |
|
369 |
^ self copyToEndInto:aWriteStream. |
|
370 |
]. |
|
17611 | 371 |
^ super copyToEndInto:aWriteStream bufferSize:bufferSize. |
372 |
||
373 |
" |
|
374 |
|rs ws cnt| |
|
375 |
||
376 |
ws := #() writeStream. |
|
377 |
rs := #( 1 2 3 4 a nil true) readWriteStream. |
|
378 |
rs next. |
|
379 |
cnt := rs copyToEndInto:ws bufferSize:0. |
|
380 |
Transcript show:cnt; show:' '; showCR:ws contents. |
|
381 |
" |
|
382 |
! ! |
|
383 |
||
611 | 384 |
!PositionableStream methodsFor:'positioning'! |
385 |
||
386 |
backStep |
|
387 |
"move backward read position by one" |
|
388 |
||
4405 | 389 |
self position:(self position - 1) |
611 | 390 |
! |
391 |
||
16188 | 392 |
match: subCollection |
393 |
"Set the access position of the receiver to be past the next occurrence of the subCollection. |
|
394 |
Answer whether subCollection is found. |
|
395 |
No wildcards, and case does matter." |
|
396 |
||
397 |
| pattern startMatch | |
|
398 |
||
399 |
pattern := ReadStream on: subCollection. |
|
400 |
startMatch := nil. |
|
401 |
[pattern atEnd] whileFalse: [ |
|
402 |
self atEnd ifTrue: [^ false]. |
|
403 |
(self next) = (pattern next) |
|
404 |
ifTrue: [pattern position = 1 ifTrue: [startMatch := self position]] |
|
405 |
ifFalse: [ |
|
406 |
pattern position: 0. |
|
407 |
startMatch ifNotNil: [ |
|
408 |
self position: startMatch. |
|
409 |
startMatch := nil |
|
410 |
] |
|
411 |
] |
|
412 |
]. |
|
413 |
^ true |
|
414 |
||
415 |
" |
|
416 |
'abc def ghi' readStream match:'def'; upToEnd |
|
417 |
" |
|
418 |
! |
|
419 |
||
611 | 420 |
position |
15615 | 421 |
"return the read position (0-based)" |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
422 |
|
15348 | 423 |
^ position |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
424 |
! |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
425 |
|
15615 | 426 |
position0Based |
427 |
<resource: #obsolete> |
|
428 |
"return the read position 0-based" |
|
429 |
||
430 |
^ self position |
|
431 |
! |
|
432 |
||
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
433 |
position0Based:index0Based |
15615 | 434 |
<resource: #obsolete> |
4405 | 435 |
"set the read (or write) position" |
611 | 436 |
|
15615 | 437 |
self position:index0Based |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
438 |
! |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
439 |
|
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
440 |
position1Based |
15615 | 441 |
<resource: #obsolete> |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
442 |
"return the read position 1-based" |
611 | 443 |
|
15615 | 444 |
^ self position + 1 |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
445 |
! |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
446 |
|
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
447 |
position1Based:index1Based |
15615 | 448 |
<resource: #obsolete> |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
449 |
"set the read (or write) position" |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
450 |
|
15615 | 451 |
self position:(index1Based - 1) |
4405 | 452 |
|
453 |
" |
|
454 |
|s| |
|
455 |
||
456 |
s := '1234567890' readStream. |
|
457 |
s next:5. |
|
458 |
s position:1. |
|
459 |
s next:7. |
|
460 |
" |
|
461 |
||
462 |
" |
|
463 |
|s| |
|
464 |
||
465 |
s := '' writeStream. |
|
466 |
s nextPutAll:'1234567890'. |
|
467 |
s position:5. |
|
468 |
s nextPutAll:'abcdefg'. |
|
469 |
s contents |
|
470 |
" |
|
471 |
||
472 |
" |
|
473 |
|s| |
|
474 |
||
475 |
s := '' writeStream. |
|
476 |
s nextPutAll:'1234567890'. |
|
477 |
s position:0. |
|
478 |
s nextPutAll:'abcdefg'. |
|
479 |
s contents |
|
480 |
" |
|
611 | 481 |
! |
482 |
||
15615 | 483 |
position:index0Based |
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
484 |
"set the read (or write) position" |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
485 |
|
15615 | 486 |
((index0Based > readLimit) or:[index0Based < 0]) ifTrue: [^ self positionError:index0Based]. |
487 |
position := index0Based |
|
6626
f7b08d6bee3f
#positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents:
6538
diff
changeset
|
488 |
! |
f7b08d6bee3f
#positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents:
6538
diff
changeset
|
489 |
|
611 | 490 |
reset |
491 |
"set the read position to the beginning of the collection" |
|
492 |
||
19885 | 493 |
position := 0. |
5308 | 494 |
|
495 |
" |
|
496 |
|s| |
|
497 |
||
498 |
s := 'hello world' readStream. |
|
499 |
Transcript showCR:(s next:5). |
|
500 |
s reset. |
|
501 |
Transcript showCR:(s next:10). |
|
502 |
" |
|
503 |
! |
|
504 |
||
505 |
resetPosition |
|
19885 | 506 |
<resource: #obsolete> |
5308 | 507 |
"set the read position to the beginning of the collection" |
508 |
||
15348 | 509 |
position := 0 |
4405 | 510 |
|
511 |
" |
|
512 |
|s| |
|
513 |
||
514 |
s := 'hello world' readStream. |
|
515 |
Transcript showCR:(s next:5). |
|
516 |
s reset. |
|
517 |
Transcript showCR:(s next:10). |
|
518 |
" |
|
611 | 519 |
! |
520 |
||
521 |
setToEnd |
|
11433 | 522 |
"set the read position to the end of the collection. |
523 |
#next will return EOF, #nextPut: will append to the stream. |
|
524 |
(same Behavior as FileStream." |
|
611 | 525 |
|
15348 | 526 |
position := readLimit |
611 | 527 |
! |
528 |
||
529 |
skip:numberToSkip |
|
530 |
"skip the next numberToSkip elements" |
|
531 |
||
5774 | 532 |
numberToSkip ~~ 0 ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6924
diff
changeset
|
533 |
self position:(self position + numberToSkip) |
5774 | 534 |
] |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
535 |
! |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
536 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
537 |
skipThroughAll:aCollection |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
538 |
"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
|
539 |
return nil if not found, self otherwise. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
540 |
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
|
541 |
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
|
542 |
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
|
543 |
|
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
544 |
|buffer len first idx| |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
545 |
|
16186 | 546 |
self isPositionable ifFalse:[ |
547 |
"/ for non-positionable subclasses |
|
548 |
^ super skipThroughAll:aCollection |
|
549 |
]. |
|
550 |
||
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
551 |
len := aCollection size. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
552 |
first := aCollection at:1. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
553 |
[self atEnd] whileFalse:[ |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
554 |
buffer := self nextAvailable:len. |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
555 |
buffer size == len ifTrue:[ |
16209 | 556 |
buffer = aCollection ifTrue:[ |
557 |
^ self |
|
558 |
]. |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
559 |
"expect more input" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
560 |
idx := buffer indexOf:first startingAt:2. |
16209 | 561 |
idx ~~ 0 ifTrue:[ |
562 |
self skip:(idx - len - 1) |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
563 |
]. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
564 |
]. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
565 |
]. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
566 |
^ nil |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
567 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
568 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
569 |
|s| |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
570 |
s := ReadStream on:'12345678901234567890a'. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
571 |
s skipThroughAll:'90ab'. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
572 |
s upToEnd |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
573 |
" |
2153
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
574 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
575 |
|s| |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
576 |
s := ReadStream on:'12345678901234567890'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
577 |
s skipThroughAll:'1234'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
578 |
s upToEnd |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
579 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
580 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
581 |
|s| |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
582 |
s := ReadStream on:'12345678901234567890'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
583 |
s skipThroughAll:'999'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
584 |
s atEnd |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
585 |
" |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
586 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
587 |
"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
|
588 |
"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
|
589 |
! |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
590 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
591 |
skipToAll:aCollection |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
592 |
"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
|
593 |
return nil if not found, self otherwise. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
594 |
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
|
595 |
|
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
596 |
|oldPos buffer len first idx| |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
597 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
598 |
oldPos := self position. |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
599 |
len := aCollection size. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
600 |
first := aCollection at:1. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
601 |
[self atEnd] whileFalse:[ |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
602 |
buffer := self nextAvailable:len. |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
603 |
buffer = aCollection ifTrue:[ |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
604 |
self position:(self position - len). |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
605 |
^ self |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
606 |
]. |
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
607 |
buffer size == len ifTrue:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
608 |
"more input can be expected" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
609 |
idx := buffer indexOf:first startingAt:2. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
610 |
idx == 0 ifFalse:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
611 |
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
|
612 |
]. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
613 |
]. |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
614 |
]. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
615 |
self position:oldPos. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
616 |
^ nil |
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 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
619 |
|s| |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
620 |
s := ReadStream on:'12345678901234567890'. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
621 |
s skipToAll:'901'. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
622 |
s upToEnd |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
623 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
624 |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
625 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
626 |
|s| |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
627 |
s := ReadStream on:'1234567890'. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
628 |
s skipToAll:'901'. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
629 |
s upToEnd |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
630 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
631 |
|
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 |
|s| |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
634 |
s := 'Makefile' asFilename readStream. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
635 |
[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
636 |
(s skipToAll:'EDIT') notNil ifTrue:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
637 |
s next:100. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
638 |
]. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
639 |
] ensure:[ |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
640 |
s close. |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
641 |
] |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
642 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
643 |
|
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
644 |
"Modified: 26.6.1996 / 09:28:27 / cg" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
645 |
"Created: 26.6.1996 / 09:35:06 / cg" |
44 | 646 |
! ! |
611 | 647 |
|
10357
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
648 |
!PositionableStream methodsFor:'printing & storing'! |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
649 |
|
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
650 |
printOn:aStream |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
651 |
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
|
652 |
|
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
653 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
654 |
'' readStream printString |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
655 |
'' writeStream printString |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
656 |
" |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
657 |
! ! |
66543e405aa4
Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents:
10001
diff
changeset
|
658 |
|
611 | 659 |
!PositionableStream methodsFor:'private'! |
660 |
||
661 |
contentsSpecies |
|
662 |
"return a class of which instances will be returned, when |
|
663 |
parts of the collection are asked for. |
|
15640 | 664 |
(see upTo-kind of methods in Stream)" |
611 | 665 |
|
666 |
^ collection species |
|
667 |
! |
|
668 |
||
669 |
on:aCollection |
|
670 |
"setup for streaming on aCollection" |
|
671 |
||
672 |
collection := aCollection. |
|
673 |
readLimit := aCollection size. |
|
13379 | 674 |
readLimit == 0 ifTrue:[ |
675 |
self assert:(aCollection isCollection) |
|
676 |
]. |
|
15348 | 677 |
position := 0 |
611 | 678 |
! |
679 |
||
680 |
on:aCollection from:first to:last |
|
681 |
"setup for streaming on aCollection from first to last" |
|
682 |
||
683 |
collection := aCollection. |
|
15348 | 684 |
position := first - 1. |
611 | 685 |
readLimit := last |
686 |
! |
|
687 |
||
688 |
positionError |
|
1998 | 689 |
"{ Pragma: +optSpace }" |
690 |
||
2966 | 691 |
"report an error when positioning past the end |
692 |
or before the beginning." |
|
611 | 693 |
|
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
8318
diff
changeset
|
694 |
^ PositionOutOfBoundsError raiseRequestWith:nil |
4452
3d050f505a0a
Raise proceedable signals proceedable.
Stefan Vogel <sv@exept.de>
parents:
4416
diff
changeset
|
695 |
|
3d050f505a0a
Raise proceedable signals proceedable.
Stefan Vogel <sv@exept.de>
parents:
4416
diff
changeset
|
696 |
"Modified: / 26.7.1999 / 10:59:13 / stefan" |
611 | 697 |
! |
698 |
||
6314 | 699 |
positionError:badPostition |
700 |
"{ Pragma: +optSpace }" |
|
701 |
||
702 |
"report an error when positioning past the end |
|
703 |
or before the beginning." |
|
704 |
||
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
8318
diff
changeset
|
705 |
^ PositionOutOfBoundsError raiseRequestWith:badPostition |
6314 | 706 |
! |
707 |
||
611 | 708 |
with:aCollection |
709 |
"setup for streaming to the end of aCollection" |
|
710 |
||
711 |
collection := aCollection. |
|
11434 | 712 |
readLimit := aCollection size. |
611 | 713 |
self setToEnd |
11434 | 714 |
|
715 |
" |
|
716 |
(WriteStream with:#(1 2 3 4 5)) |
|
717 |
nextPut:6; |
|
718 |
contents |
|
719 |
" |
|
611 | 720 |
! ! |
721 |
||
16195 | 722 |
!PositionableStream methodsFor:'queries'! |
723 |
||
16209 | 724 |
endsBeforePositionWith:aSequenceableCollection |
16195 | 725 |
"answer true, if the elements in aSequenceableCollection |
16209 | 726 |
are at the current end of the stream up to position." |
16195 | 727 |
|
16209 | 728 |
|sz pos| |
16195 | 729 |
|
16209 | 730 |
sz := aSequenceableCollection size. |
731 |
pos := self position. |
|
732 |
pos < sz ifTrue:[ |
|
733 |
^ false. |
|
16195 | 734 |
]. |
16209 | 735 |
self contentsSpecies == collection class ifTrue:[ |
736 |
^ collection sameContentsFrom:pos+1-sz to:pos as:aSequenceableCollection startingAt:1. |
|
737 |
]. |
|
738 |
self position:pos-sz. |
|
739 |
^ (self next:sz) = aSequenceableCollection. |
|
16195 | 740 |
|
741 |
" |
|
16209 | 742 |
('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'World' |
743 |
('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'Hello World' |
|
744 |
('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'Hello Worldx' |
|
745 |
('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'Bla' |
|
746 |
('' writeStream) endsBeforePositionWith:'Bla' |
|
747 |
('' writeStream) endsBeforePositionWith:'' |
|
16195 | 748 |
'' endsWith:'' |
749 |
" |
|
750 |
! ! |
|
751 |
||
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
752 |
!PositionableStream methodsFor:'reading'! |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
753 |
|
9003 | 754 |
nextAvailable:count |
17606 | 755 |
collection notNil ifTrue:[ |
756 |
|end result| |
|
9003 | 757 |
|
17606 | 758 |
end := position + count. |
759 |
end >= readLimit ifTrue:[ |
|
760 |
end := readLimit. |
|
761 |
]. |
|
762 |
||
763 |
result := collection copyFrom:position+1 to:end. |
|
764 |
position := end. |
|
765 |
^ result. |
|
9003 | 766 |
]. |
767 |
||
17606 | 768 |
^ super nextAvailable:count. |
9003 | 769 |
|
770 |
" |
|
771 |
'abc' readStream nextAvailable:1. |
|
772 |
'abc' readStream nextAvailable:2. |
|
773 |
'abc' readStream nextAvailable:3. |
|
774 |
'abc' readStream nextAvailable:4. |
|
775 |
||
776 |
'abc' readStream nextAvailable:2; nextAvailable:2. |
|
777 |
'abc' readStream nextAvailable:3; nextAvailable:3. |
|
778 |
" |
|
779 |
! |
|
780 |
||
17611 | 781 |
nextAvailable:count into:aCollection startingAt:initialIndex |
782 |
"return the next count objects from the stream. If the end is |
|
783 |
reached before, only that many objects are copyied into the |
|
784 |
collection. |
|
785 |
Returns the number of objects that have been actually read." |
|
786 |
||
787 |
| max | |
|
788 |
||
789 |
collection notNil ifTrue:[ |
|
790 |
max := (readLimit - position) min: count. |
|
791 |
aCollection |
|
792 |
replaceFrom: initialIndex |
|
793 |
to: initialIndex+max-1 |
|
794 |
with: collection |
|
795 |
startingAt: position+1. |
|
796 |
position := position + max. |
|
797 |
^ max. |
|
798 |
]. |
|
799 |
||
800 |
^ super nextAvailable:count into:aCollection startingAt:initialIndex. |
|
801 |
||
802 |
" |
|
803 |
|s n buffer| |
|
804 |
||
805 |
buffer := ByteArray new:10. |
|
806 |
||
807 |
s := ReadStream on:#[1 2 3 4 5 6 7 8 9]. |
|
808 |
s next:3. |
|
809 |
n := s nextBytes:9 into:buffer startingAt:1. |
|
810 |
Transcript showCR:('n = %1; buffer = <%2>' bindWith:n with:buffer) |
|
811 |
" |
|
812 |
! |
|
813 |
||
814 |
nextBytes:numBytes into:aCollection startingAt:initialIndex |
|
815 |
"return the next numBytes from the stream. If the end is |
|
816 |
reached before, only that many bytes are copyied into the |
|
817 |
collection. |
|
818 |
Returns the number of bytes that have been actually read. |
|
819 |
The receiver must support reading of binary bytes. |
|
820 |
||
821 |
Notice: this method is provided here for protocol completeness |
|
822 |
with externalStreams - it is normally not used with other |
|
823 |
streams." |
|
824 |
||
825 |
|max| |
|
826 |
||
827 |
(collection isByteCollection |
|
828 |
and:[aCollection isByteCollection]) ifTrue:[ |
|
829 |
"do it the fast way" |
|
830 |
max := (readLimit - position) min: numBytes. |
|
831 |
aCollection |
|
832 |
replaceBytesFrom:initialIndex |
|
833 |
to:(initialIndex + max - 1) |
|
834 |
with:collection |
|
835 |
startingAt:position+1. |
|
836 |
position := position + max. |
|
837 |
^ max |
|
838 |
]. |
|
839 |
"do it the hard way" |
|
840 |
^ super nextBytes:numBytes into:aCollection startingAt:initialIndex |
|
841 |
||
842 |
" |
|
843 |
|s n buffer| |
|
844 |
||
845 |
buffer := ByteArray new:10. |
|
846 |
||
847 |
s := ReadStream on:#[1 2 3 4 5 6 7 8 9]. |
|
848 |
s next:3. |
|
849 |
n := s nextBytes:9 into:buffer startingAt:1. |
|
850 |
Transcript showCR:('n = %1; buffer = <%2>' bindWith:n with:buffer) |
|
851 |
" |
|
852 |
! |
|
853 |
||
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
854 |
upToAll:aCollection |
16186 | 855 |
"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
|
856 |
Return everything read excluding the elements in aCollection. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
857 |
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
|
858 |
read operations will return those elements. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
859 |
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
|
860 |
are read and returned. |
6494 | 861 |
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
|
862 |
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
|
863 |
collection. |
6494 | 864 |
See also #upToAllExcluding:, which returns the same, but leaves the |
865 |
read pointer after the matched subcollection. |
|
3184
d99302322139
Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents:
3170
diff
changeset
|
866 |
|
d99302322139
Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents:
3170
diff
changeset
|
867 |
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
|
868 |
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
|
869 |
this way for the sake of ST80-compatibility." |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
870 |
|
17611 | 871 |
"/ in the future, this will have the Squeak semantics, which is upToAllExcluding: |
16189 | 872 |
|
873 |
^ self upToAll_positionBefore:aCollection |
|
874 |
||
875 |
" |
|
876 |
|s| |
|
877 |
s := ReadStream on:'hello world'. |
|
878 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
879 |
Transcript showCR:s atEnd. |
|
880 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
|
881 |
" |
|
882 |
" |
|
883 |
|s| |
|
884 |
s := ReadStream on:'hello world'. |
|
885 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
886 |
Transcript showCR:s atEnd. |
|
887 |
Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
888 |
" |
|
889 |
" |
|
890 |
|s| |
|
891 |
s := ReadStream on:'hello world'. |
|
892 |
Transcript show:'<'; show:(s upToAll:'xx'); showCR:'>'. |
|
893 |
Transcript showCR:s atEnd. |
|
894 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
|
895 |
" |
|
896 |
||
897 |
"Modified: / 12.1.1998 / 22:06:42 / cg" |
|
898 |
"Created: / 12.1.1998 / 22:07:01 / cg" |
|
899 |
! |
|
900 |
||
901 |
upToAll_positionBefore:aCollection |
|
902 |
"read until a subcollection consisisting of the elements in aCollection is encountered. |
|
903 |
Return everything read excluding the elements in aCollection. |
|
904 |
The position is left before the collection; i.e. the next |
|
905 |
read operations will return those elements. |
|
906 |
If no such subcollection is encountered, all elements up to the end |
|
907 |
are read and returned. |
|
908 |
See also #throughAll: which also reads up to some objects |
|
909 |
but positions behind it and DOES include it in the returned |
|
16840 | 910 |
collection." |
16189 | 911 |
|
16209 | 912 |
|answerStream element last| |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
913 |
|
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
914 |
last := aCollection last. |
16209 | 915 |
answerStream := WriteStream on:(self contentsSpecies new:100). |
916 |
[(element := self nextOrNil) notNil] whileTrue:[ |
|
15159
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
917 |
answerStream nextPut:element. |
16209 | 918 |
(element = last and:[answerStream endsBeforePositionWith:aCollection]) ifTrue:[ |
919 |
|backStep| |
|
920 |
backStep := aCollection size negated. |
|
921 |
self skip:backStep. |
|
922 |
answerStream skip:backStep. |
|
923 |
^ answerStream contents |
|
15159
b94bdee97afa
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
14934
diff
changeset
|
924 |
]. |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
925 |
]. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
926 |
^ answerStream contents |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
927 |
|
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
928 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
929 |
|s| |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
930 |
s := ReadStream on:'hello world'. |
16209 | 931 |
Transcript show:'<'; show:(s upToAll_positionBefore:'wo'); showCR:'>'. |
6494 | 932 |
Transcript showCR:s atEnd. |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
933 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
934 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
935 |
" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
936 |
|s| |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
937 |
s := ReadStream on:'hello world'. |
16209 | 938 |
Transcript show:'<'; show:(s upToAll_positionBefore:'wo'); showCR:'>'. |
16186 | 939 |
Transcript showCR:s atEnd. |
16209 | 940 |
Transcript show:'<'; show:(s upToAll_positionBefore:'wo'); showCR:'>'. |
16186 | 941 |
" |
942 |
" |
|
943 |
|s| |
|
944 |
s := ReadStream on:'hello world'. |
|
16209 | 945 |
Transcript show:'<'; show:(s upToAll_positionBefore:'xx'); showCR:'>'. |
3170
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
946 |
Transcript showCR:s atEnd. |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
947 |
Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
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 |
|
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
950 |
"Modified: / 12.1.1998 / 22:06:42 / cg" |
7b299d83c45a
moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents:
3032
diff
changeset
|
951 |
"Created: / 12.1.1998 / 22:07:01 / cg" |
20101 | 952 |
! |
953 |
||
954 |
upToEnd |
|
955 |
collection notNil ifTrue:[ |
|
956 |
|result| |
|
957 |
||
958 |
result := collection copyFrom:position+1 to:readLimit. |
|
959 |
position := readLimit. |
|
960 |
^ result. |
|
961 |
]. |
|
962 |
||
963 |
^ super upToEnd. |
|
964 |
||
965 |
" |
|
966 |
'abc' readStream upToEnd. |
|
967 |
" |
|
3170
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 |
|
611 | 970 |
!PositionableStream methodsFor:'testing'! |
971 |
||
972 |
atEnd |
|
973 |
"return true, if the read-position is at the end" |
|
974 |
||
15357 | 975 |
^ position >= readLimit |
611 | 976 |
! |
977 |
||
978 |
isEmpty |
|
979 |
"return true, if the contents of the stream is empty" |
|
980 |
||
981 |
^ readLimit == 0 |
|
9006 | 982 |
! |
983 |
||
10577 | 984 |
isInternalByteStream |
985 |
"return true, if the stream is an internal stream reading bytes" |
|
986 |
||
987 |
^ collection class isBytes |
|
988 |
||
989 |
"Created: / 30-05-2007 / 16:16:12 / cg" |
|
990 |
! |
|
991 |
||
9006 | 992 |
isPositionable |
993 |
"return true, if the stream supports positioning (this one is)" |
|
994 |
||
995 |
^ true |
|
611 | 996 |
! ! |
997 |
||
1897 | 998 |
!PositionableStream class methodsFor:'documentation'! |
701 | 999 |
|
1000 |
version |
|
19403 | 1001 |
^ '$Header$' |
13379 | 1002 |
! |
1003 |
||
1004 |
version_CVS |
|
19403 | 1005 |
^ '$Header$' |
18260
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
1006 |
! |
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
1007 |
|
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
1008 |
version_HG |
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
1009 |
|
e55af242e134
Added Squeak compatibility methods PositionableStream>>#upToAnyOf: / #upToAnyOf:do:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
1010 |
^ '$Changeset: <not expanded> $' |
701 | 1011 |
! ! |
6777
5efddf5358b2
currentFileInDirectory query
Claus Gittinger <cg@exept.de>
parents:
6707
diff
changeset
|
1012 |
|
14934 | 1013 |
|
611 | 1014 |
PositionableStream initialize! |