author | Claus Gittinger <cg@exept.de> |
Fri, 01 Oct 2004 09:37:47 +0200 | |
changeset 8615 | df60f835f2e0 |
parent 8437 | 727346e22474 |
child 8868 | 12ac754138b2 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
252 | 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 |
" |
|
12 |
||
5556 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
1 | 15 |
PositionableStream subclass:#WriteStream |
1295 | 16 |
instanceVariableNames:'' |
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Streams' |
|
1 | 20 |
! |
21 |
||
1965 | 22 |
!WriteStream class methodsFor:'documentation'! |
1 | 23 |
|
88 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
252 | 27 |
All Rights Reserved |
88 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
68 | 38 |
documentation |
39 |
" |
|
2883 | 40 |
Streams for writing into. |
41 |
WriteStreams are especially useful, if big strings are to be constructed |
|
42 |
from pieces - create a writeStream, add the pieces (with #nextPut or |
|
43 |
#nextPutAll) and finally fetch the concatenated string via #contents. |
|
44 |
This is much better than constructing the big string by concatenating via |
|
45 |
the comma (,) operator, since less intermediate garbage objects are created. |
|
46 |
||
47 |
This implementation currently DOES change the |
|
261 | 48 |
identity if the streamed-upon collection IF it cannot grow easily. |
49 |
Collections which cannot grow easily are for example: Array, ByteArray and String. |
|
88 | 50 |
Thus it is slightly incompatible to ST-80 since 'aStream contents' does |
51 |
not always return the original collection. This may change. |
|
1295 | 52 |
|
53 |
[author:] |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
54 |
Claus Gittinger |
68 | 55 |
" |
2883 | 56 |
! |
57 |
||
58 |
examples |
|
59 |
" |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
60 |
[exBegin] |
2883 | 61 |
|s| |
62 |
||
63 |
s := WriteStream on:''. |
|
64 |
s nextPutAll:'hello'; |
|
65 |
space; |
|
66 |
nextPutAll:'world'. |
|
67 |
||
68 |
s contents inspect |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
69 |
[exEnd] |
2883 | 70 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
71 |
[exBegin] |
2883 | 72 |
|s| |
73 |
||
74 |
s := WriteStream on:''. |
|
75 |
s nextPutAll:'hello'; |
|
76 |
space; |
|
77 |
nextPutAll:'world'. |
|
78 |
||
79 |
Transcript nextPutLine:(s contents) |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
80 |
[exEnd] |
2883 | 81 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
82 |
[exBegin] |
2883 | 83 |
|s| |
84 |
||
85 |
s := '' writeStream. |
|
86 |
s nextPutAll:'hello'; |
|
87 |
space; |
|
88 |
nextPutAll:'world'. |
|
89 |
||
90 |
Transcript nextPutLine:(s contents) |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
91 |
[exEnd] |
2883 | 92 |
" |
93 |
||
345 | 94 |
! ! |
95 |
||
7261 | 96 |
!WriteStream methodsFor:'Compatibility-Dolphin'! |
6325 | 97 |
|
98 |
display:someObject |
|
6871
1c4a799a048c
display: use printOn instead of printString.
Claus Gittinger <cg@exept.de>
parents:
6326
diff
changeset
|
99 |
someObject printOn:self. |
6325 | 100 |
! ! |
101 |
||
1 | 102 |
!WriteStream methodsFor:'accessing'! |
103 |
||
104 |
contents |
|
345 | 105 |
"return the current contents (a collection) of the stream. |
106 |
Currently, this returns the actual collection if possible |
|
107 |
(and reset is implemented to create a new one) in contrast to |
|
108 |
ST80, where contents returns a copy and reset only sets the writePointer. |
|
109 |
The ST/X behavior creates less temporary garbage in the normal case |
|
2410 | 110 |
(where things are written for the contents only) but may be incompatible |
345 | 111 |
with some applications. Time will show, if this is to be changed." |
1 | 112 |
|
260 | 113 |
|lastIndex| |
114 |
||
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
115 |
lastIndex := position - ZeroPosition. |
260 | 116 |
collection size == lastIndex ifFalse:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
117 |
collection isFixedSize ifTrue:[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
118 |
" |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
119 |
grow is expensive - return a copy. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
120 |
(is this what users of writeStream expect ?) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
121 |
" |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
122 |
collection := collection copyFrom:1 to:lastIndex |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
123 |
] ifFalse:[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
124 |
collection grow:lastIndex |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
125 |
] |
1 | 126 |
]. |
127 |
^ collection |
|
2410 | 128 |
|
3087 | 129 |
"Modified: / 19.2.1997 / 08:57:28 / stefan" |
130 |
"Modified: / 30.10.1997 / 16:21:23 / cg" |
|
1 | 131 |
! |
132 |
||
5888 | 133 |
last |
134 |
"return the last element - report an error if the stream is empty" |
|
135 |
||
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
136 |
|position1Based| |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
137 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
138 |
position1Based := position - ZeroPosition + 1. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
139 |
^ collection at:(position1Based - 1). |
5888 | 140 |
|
141 |
" |
|
142 |
|s| |
|
143 |
||
144 |
s := '' writeStream. |
|
145 |
s nextPut:$a. |
|
146 |
s last. |
|
147 |
s nextPut:$b. |
|
148 |
s last. |
|
149 |
s nextPut:$c. |
|
150 |
s last. |
|
151 |
" |
|
152 |
! |
|
153 |
||
154 |
last:n |
|
155 |
"return the last n elements as species of the underlying collection; |
|
156 |
Report an error if the stream is empty" |
|
157 |
||
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
158 |
|position1Based| |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
159 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
160 |
position1Based := position - ZeroPosition + 1. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
161 |
^ collection copyFrom:(position1Based - n) to:(position1Based - 1). |
5888 | 162 |
|
163 |
" |
|
164 |
|s| |
|
165 |
||
166 |
s := '' writeStream. |
|
167 |
s nextPut:$a. |
|
168 |
s last:1. |
|
169 |
s nextPut:$b. |
|
170 |
s last:1. |
|
171 |
s last:2. |
|
172 |
s nextPut:$c. |
|
173 |
s last:1. |
|
174 |
s last:2. |
|
175 |
s last:3. |
|
176 |
" |
|
177 |
! |
|
178 |
||
329 | 179 |
reset |
345 | 180 |
"reset the stream; write anew. |
2410 | 181 |
See the comment in WriteStream>>contents" |
329 | 182 |
|
183 |
collection := collection species new:(collection size). |
|
184 |
super reset |
|
2410 | 185 |
|
186 |
"Modified: 19.2.1997 / 08:57:00 / stefan" |
|
1 | 187 |
! ! |
188 |
||
611 | 189 |
!WriteStream methodsFor:'positioning'! |
190 |
||
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
191 |
position0Based:index0Based |
611 | 192 |
"redefined to allow positioning past the readLimit" |
193 |
||
7052
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
194 |
((index0Based > collection size) or:[index0Based < 0]) ifTrue: [^ self positionError]. |
207cc9c62982
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
195 |
position := index0Based + ZeroPosition |
611 | 196 |
! ! |
197 |
||
198 |
!WriteStream methodsFor:'private'! |
|
199 |
||
200 |
growCollection |
|
2863
aec08a0c2c2e
no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents:
2410
diff
changeset
|
201 |
"grow the streamed collection to at least 10 elements" |
aec08a0c2c2e
no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents:
2410
diff
changeset
|
202 |
|
611 | 203 |
self growCollection:10 |
2863
aec08a0c2c2e
no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents:
2410
diff
changeset
|
204 |
|
aec08a0c2c2e
no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents:
2410
diff
changeset
|
205 |
"Modified: 19.8.1997 / 17:53:28 / cg" |
611 | 206 |
! |
207 |
||
208 |
growCollection:minNewSize |
|
209 |
"grow the streamed collection to at least minNewSize" |
|
210 |
||
211 |
|oldSize newSize newColl| |
|
212 |
||
213 |
oldSize := collection size. |
|
214 |
(oldSize == 0) ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
215 |
newSize := minNewSize |
611 | 216 |
] ifFalse:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
217 |
newSize := oldSize * 2. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
218 |
(newSize < minNewSize) ifTrue:[newSize := minNewSize]. |
611 | 219 |
]. |
220 |
collection isFixedSize ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
221 |
newColl := collection species new:newSize. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
222 |
newColl replaceFrom:1 to:oldSize with:collection startingAt:1. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
223 |
collection := newColl |
611 | 224 |
] ifFalse:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
225 |
collection grow:newSize |
611 | 226 |
]. |
2863
aec08a0c2c2e
no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents:
2410
diff
changeset
|
227 |
|
aec08a0c2c2e
no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents:
2410
diff
changeset
|
228 |
"Modified: 19.8.1997 / 17:53:11 / cg" |
611 | 229 |
! ! |
230 |
||
7260 | 231 |
!WriteStream methodsFor:'private-accessing'! |
611 | 232 |
|
233 |
on:aCollection from:start to:last |
|
234 |
"create and return a new stream for writing onto aCollection, where |
|
235 |
writing is limited to the elements in the range start to last." |
|
236 |
||
237 |
super on:aCollection from:start to:last. |
|
238 |
writeLimit := last. |
|
239 |
! ! |
|
240 |
||
241 |
!WriteStream methodsFor:'queries'! |
|
242 |
||
3098
4203b0d13fc8
added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3087
diff
changeset
|
243 |
isReadable |
4203b0d13fc8
added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3087
diff
changeset
|
244 |
"return true if the receiver supports reading - thats not true" |
4203b0d13fc8
added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3087
diff
changeset
|
245 |
|
4203b0d13fc8
added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3087
diff
changeset
|
246 |
^ false |
4203b0d13fc8
added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3087
diff
changeset
|
247 |
|
4203b0d13fc8
added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3087
diff
changeset
|
248 |
"Created: / 8.11.1997 / 14:06:07 / cg" |
4203b0d13fc8
added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3087
diff
changeset
|
249 |
! |
4203b0d13fc8
added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3087
diff
changeset
|
250 |
|
611 | 251 |
isWritable |
1405 | 252 |
"return true, if writing is supported by the recevier. |
253 |
Always return true here" |
|
254 |
||
611 | 255 |
^ true |
1405 | 256 |
|
257 |
"Modified: 16.5.1996 / 14:44:49 / cg" |
|
3031 | 258 |
! |
259 |
||
260 |
size |
|
261 |
"return the current size" |
|
262 |
||
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
263 |
|position1Based| |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
264 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
265 |
position1Based := position - ZeroPosition + 1. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
266 |
^ position1Based - 1. |
3031 | 267 |
|
268 |
"Created: 14.10.1997 / 20:43:49 / cg" |
|
611 | 269 |
! ! |
270 |
||
63 | 271 |
!WriteStream methodsFor:'reading'! |
1 | 272 |
|
273 |
next |
|
10 | 274 |
"catch read access to write stream - report an error" |
1 | 275 |
|
10 | 276 |
self shouldNotImplement |
1 | 277 |
! |
278 |
||
279 |
peek |
|
10 | 280 |
"catch read access to write stream - report an error" |
1 | 281 |
|
10 | 282 |
self shouldNotImplement |
63 | 283 |
! ! |
284 |
||
5556 | 285 |
!WriteStream methodsFor:'testing'! |
286 |
||
287 |
isEmpty |
|
288 |
"return true, if the contents of the stream is empty" |
|
289 |
||
7620
cf2c3d9d6d9c
Fix #isEmpty for external streams.
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
290 |
^ self position0Based == ZeroPosition |
5556 | 291 |
|
292 |
"Created: 14.10.1997 / 20:44:37 / cg" |
|
293 |
! ! |
|
294 |
||
611 | 295 |
!WriteStream methodsFor:'writing'! |
369 | 296 |
|
611 | 297 |
next:count put:anObject |
298 |
"append anObject count times to the receiver. |
|
299 |
Redefined to avoid count grows of the underlying collection - |
|
300 |
instead a single grow on the final size is performed." |
|
301 |
||
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
302 |
|final position1Based| |
611 | 303 |
|
304 |
(collection isNil or:[writeLimit notNil]) ifTrue:[ |
|
7113 | 305 |
^ super next:count put:anObject |
611 | 306 |
]. |
369 | 307 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
308 |
position1Based := position - ZeroPosition + 1. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
309 |
final := position1Based + count - 1. |
611 | 310 |
(final > collection size) ifTrue:[ |
7113 | 311 |
self growCollection:final |
611 | 312 |
]. |
369 | 313 |
|
7113 | 314 |
position1Based to:final do:[:index | |
315 |
collection at:index put:anObject. |
|
611 | 316 |
]. |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
317 |
position1Based := position1Based + count. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
318 |
(position1Based > readLimit) ifTrue:[readLimit := position1Based - 1]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
319 |
position := position1Based - 1 + ZeroPosition. |
611 | 320 |
^ anObject |
321 |
! |
|
1 | 322 |
|
5198
ca2c2f7ec69c
added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
4406
diff
changeset
|
323 |
next:n putAll:aCollection startingAt:pos1 |
ca2c2f7ec69c
added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
4406
diff
changeset
|
324 |
"append some elements of the argument, aCollection to the stream." |
ca2c2f7ec69c
added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
4406
diff
changeset
|
325 |
|
ca2c2f7ec69c
added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
4406
diff
changeset
|
326 |
^ self nextPutAll:aCollection startingAt:pos1 to:pos1+n-1 |
ca2c2f7ec69c
added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
4406
diff
changeset
|
327 |
|
ca2c2f7ec69c
added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
4406
diff
changeset
|
328 |
" |
ca2c2f7ec69c
added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
4406
diff
changeset
|
329 |
|s| |
ca2c2f7ec69c
added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
4406
diff
changeset
|
330 |
|
ca2c2f7ec69c
added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
4406
diff
changeset
|
331 |
s := '' writeStream. |
ca2c2f7ec69c
added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
4406
diff
changeset
|
332 |
s nextPutAll:'hello '. |
ca2c2f7ec69c
added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
4406
diff
changeset
|
333 |
s next:5 putAll:'1234world012345' startingAt:5. |
ca2c2f7ec69c
added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
4406
diff
changeset
|
334 |
s contents |
ca2c2f7ec69c
added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
4406
diff
changeset
|
335 |
" |
ca2c2f7ec69c
added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
4406
diff
changeset
|
336 |
|
ca2c2f7ec69c
added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
4406
diff
changeset
|
337 |
"Modified: 12.7.1996 / 10:31:36 / cg" |
ca2c2f7ec69c
added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
4406
diff
changeset
|
338 |
! |
ca2c2f7ec69c
added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents:
4406
diff
changeset
|
339 |
|
1 | 340 |
nextPut:anObject |
1584 | 341 |
"append the argument, anObject to the stream. |
2863
aec08a0c2c2e
no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents:
2410
diff
changeset
|
342 |
Specially tuned for appending to String, ByteArray and Array streams." |
1 | 343 |
|
63 | 344 |
%{ /* NOCONTEXT */ |
345 |
||
8293
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
346 |
#ifndef NO_PRIM_STREAM |
63 | 347 |
REGISTER int pos; |
348 |
unsigned ch; |
|
349 |
OBJ coll; |
|
2883 | 350 |
OBJ p, wL, rL; |
1584 | 351 |
int __readLimit = -1; |
63 | 352 |
|
1136 | 353 |
coll = __INST(collection); |
354 |
p = __INST(position); |
|
63 | 355 |
|
293 | 356 |
if (__isNonNilObject(coll) && __isSmallInteger(p)) { |
8293
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
357 |
pos = __intVal(p); |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
358 |
/* make 1-based */ |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
359 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
360 |
wL = __INST(writeLimit); |
63 | 361 |
|
8293
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
362 |
if ((wL == nil) |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
363 |
|| (__isSmallInteger(wL) && (pos <= __intVal(wL)))) { |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
364 |
OBJ cls; |
252 | 365 |
|
8293
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
366 |
cls = __qClass(coll); |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
367 |
|
8293
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
368 |
rL = __INST(readLimit); |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
369 |
if (__isSmallInteger(rL)) { |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
370 |
__readLimit = __intVal(rL); |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
371 |
} |
293 | 372 |
|
8293
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
373 |
if (cls == @global(String)) { |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
374 |
if (__isCharacter(anObject) |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
375 |
&& ((ch = __intVal(__characterVal(anObject))) <= 255) /* ch is unsigned */ |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
376 |
&& (pos <= __stringSize(coll))) { |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
377 |
__StringInstPtr(coll)->s_element[pos-1] = ch; |
8615 | 378 |
advancePositionAndReturn: ; |
8293
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
379 |
if ((__readLimit >= 0) && (pos >= __readLimit)) { |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
380 |
__INST(readLimit) = __MKSMALLINT(pos); |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
381 |
} |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
382 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1); |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
383 |
RETURN ( anObject ); |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
384 |
} |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
385 |
} else if (cls == @global(ByteArray)) { |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
386 |
if (__isSmallInteger(anObject) |
8296 | 387 |
&& ((ch = __intVal(anObject)) <= 0xFF) /* ch is unsigned */ |
8293
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
388 |
&& (pos <= __byteArraySize(coll))) { |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
389 |
__ByteArrayInstPtr(coll)->ba_element[pos-1] = ch; |
8615 | 390 |
goto advancePositionAndReturn; |
8293
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
391 |
} |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
392 |
} else if (cls == @global(Array)) { |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
393 |
if (pos <= __arraySize(coll)) { |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
394 |
__ArrayInstPtr(coll)->a_element[pos-1] = anObject; |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
395 |
__STORE(coll, anObject); |
8615 | 396 |
goto advancePositionAndReturn; |
8293
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
397 |
} |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
398 |
} else if (cls == @global(Unicode16String)) { |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
399 |
if (__isCharacter(anObject) |
8296 | 400 |
&& ((ch = __intVal(__characterVal(anObject))) <= 0xFFFF) /* ch is unsigned */ |
8293
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
401 |
&& (pos <= __unicode16StringSize(coll))) { |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
402 |
__Unicode16StringInstPtr(coll)->s_element[pos-1] = ch; |
8615 | 403 |
goto advancePositionAndReturn; |
8293
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
404 |
} |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
405 |
} else if (cls == @global(Unicode32String)) { |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
406 |
if (__isCharacter(anObject) |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
407 |
&& (pos <= __unicode32StringSize(coll))) { |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
408 |
__Unicode32StringInstPtr(coll)->s_element[pos-1] = __intVal(__characterVal(anObject)); |
8615 | 409 |
goto advancePositionAndReturn; |
8293
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
410 |
} |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
411 |
} |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
412 |
} |
63 | 413 |
} |
2894 | 414 |
#endif |
260 | 415 |
%}. |
293 | 416 |
(writeLimit isNil |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
417 |
or:[(position + 1 - ZeroPosition) <= writeLimit]) ifTrue:[ |
8293
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
418 |
((position + 1 - ZeroPosition) > collection size) ifTrue:[self growCollection]. |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
419 |
collection at:(position + 1 - ZeroPosition) put:anObject. |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
420 |
((position + 1 - ZeroPosition) > readLimit) ifTrue:[readLimit := (position + 1 - ZeroPosition)]. |
dcffeb2c11e0
Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents:
7686
diff
changeset
|
421 |
position := position + 1. |
838 | 422 |
] ifFalse:[ |
8320
229adaeaf183
Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents:
8296
diff
changeset
|
423 |
WriteError raiseErrorString:'write beyond writeLimit' |
293 | 424 |
]. |
1 | 425 |
^anObject |
426 |
! |
|
427 |
||
428 |
nextPutAll:aCollection |
|
63 | 429 |
"append all elements of the argument, aCollection to the stream. |
430 |
Redefined to avoid count grows of the underlying collection - |
|
431 |
instead a single grow on the final size is performed." |
|
1 | 432 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
433 |
|nMore final position1Based| |
1 | 434 |
|
77 | 435 |
collection isNil ifTrue:[ |
7686
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7620
diff
changeset
|
436 |
^ super nextPutAll:aCollection |
77 | 437 |
]. |
438 |
||
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
439 |
position1Based := position - ZeroPosition + 1. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
440 |
|
1 | 441 |
nMore := aCollection size. |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
442 |
final := position1Based + nMore - 1. |
293 | 443 |
(writeLimit notNil |
444 |
and:[final > writeLimit]) ifTrue:[ |
|
7686
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7620
diff
changeset
|
445 |
final := writeLimit. |
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7620
diff
changeset
|
446 |
nMore := final - position1Based + 1 |
293 | 447 |
]. |
1 | 448 |
(final > collection size) ifTrue:[ |
7686
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7620
diff
changeset
|
449 |
self growCollection:final |
1 | 450 |
]. |
7686
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7620
diff
changeset
|
451 |
collection |
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7620
diff
changeset
|
452 |
replaceFrom:position1Based |
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7620
diff
changeset
|
453 |
to:final |
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7620
diff
changeset
|
454 |
with:aCollection |
290cda6075ac
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7620
diff
changeset
|
455 |
startingAt:1. |
1 | 456 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
457 |
position1Based := position1Based + nMore. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
458 |
(position1Based > readLimit) ifTrue:[readLimit := position1Based - 1]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
459 |
position := position1Based - 1 + ZeroPosition. |
1 | 460 |
^ aCollection |
1539
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
461 |
! |
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
462 |
|
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
463 |
nextPutAll:aCollection startingAt:pos1 to:pos2 |
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
464 |
"append some elements of the argument, aCollection to the stream. |
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
465 |
Redefined to avoid count grows of the underlying collection - |
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
466 |
instead a single grow on the final size is performed." |
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
467 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
468 |
|nMore final position1Based| |
1539
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
469 |
|
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
470 |
collection isNil ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
471 |
^ super nextPutAll:aCollection startingAt:pos1 to:pos2 |
1539
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
472 |
]. |
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
473 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
474 |
position1Based := position - ZeroPosition + 1. |
1539
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
475 |
nMore := pos2 - pos1 + 1. |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
476 |
final := position1Based + nMore - 1. |
1539
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
477 |
(writeLimit notNil |
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
478 |
and:[final > writeLimit]) ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
479 |
final := writeLimit. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
480 |
nMore := final - position1Based + 1 |
1539
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
481 |
]. |
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
482 |
(final > collection size) ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
483 |
self growCollection:final |
1539
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
484 |
]. |
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
485 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
486 |
collection replaceFrom:position1Based |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
487 |
to:final |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
488 |
with:aCollection |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
489 |
startingAt:pos1. |
1539
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
490 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
491 |
position1Based := position1Based + nMore. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
492 |
(position1Based > readLimit) ifTrue:[readLimit := position1Based - 1]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6871
diff
changeset
|
493 |
position := position1Based - 1 + ZeroPosition. |
1539
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
494 |
^ aCollection |
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
495 |
|
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
496 |
" |
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
497 |
|s| |
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
498 |
|
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
499 |
s := '' writeStream. |
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
500 |
s nextPutAll:'hello '. |
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
501 |
s nextPutAll:'1234world012345' startingAt:5 to:9. |
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
502 |
s contents |
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
503 |
" |
b1ac096a81e3
added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents:
1405
diff
changeset
|
504 |
|
1541 | 505 |
"Modified: 12.7.1996 / 10:31:36 / cg" |
8361 | 506 |
! |
507 |
||
8615 | 508 |
nextPutByte:anObject |
509 |
"append the argument, anObject to the stream. |
|
510 |
Specially tuned for appending to String and ByteArray streams." |
|
511 |
||
512 |
%{ /* NOCONTEXT */ |
|
513 |
||
514 |
#ifndef NO_PRIM_STREAM |
|
515 |
REGISTER int pos; |
|
516 |
OBJ coll; |
|
517 |
OBJ p, wL, rL; |
|
518 |
int __readLimit = -1; |
|
519 |
||
520 |
coll = __INST(collection); |
|
521 |
p = __INST(position); |
|
522 |
||
523 |
if (__isNonNilObject(coll) && __isSmallInteger(p) && __isSmallInteger(anObject)) { |
|
524 |
unsigned ch; |
|
525 |
||
526 |
ch = __intVal(anObject); |
|
527 |
||
528 |
pos = __intVal(p); |
|
529 |
/* make 1-based */ |
|
530 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); |
|
531 |
wL = __INST(writeLimit); |
|
532 |
||
533 |
if ((wL == nil) |
|
534 |
|| (__isSmallInteger(wL) && (pos <= __intVal(wL)))) { |
|
535 |
OBJ cls; |
|
536 |
||
537 |
cls = __qClass(coll); |
|
538 |
||
539 |
rL = __INST(readLimit); |
|
540 |
if (__isSmallInteger(rL)) { |
|
541 |
__readLimit = __intVal(rL); |
|
542 |
} |
|
543 |
||
544 |
if (cls == @global(String)) { |
|
545 |
if ((pos <= __stringSize(coll)) |
|
546 |
&& (ch <= 0xFF)) { /* ch is unsigned */ |
|
547 |
__StringInstPtr(coll)->s_element[pos-1] = ch; |
|
548 |
advancePositionAndReturn: ; |
|
549 |
if ((__readLimit >= 0) && (pos >= __readLimit)) { |
|
550 |
__INST(readLimit) = __MKSMALLINT(pos); |
|
551 |
} |
|
552 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1); |
|
553 |
RETURN ( anObject ); |
|
554 |
} |
|
555 |
} else if (cls == @global(ByteArray)) { |
|
556 |
if ((pos <= __byteArraySize(coll)) |
|
557 |
&& (ch <= 0xFF)) { /* ch is unsigned */ |
|
558 |
__ByteArrayInstPtr(coll)->ba_element[pos-1] = ch; |
|
559 |
goto advancePositionAndReturn; |
|
560 |
} |
|
561 |
} |
|
562 |
} |
|
563 |
} |
|
564 |
#endif |
|
565 |
%}. |
|
566 |
^ super nextPutByte:anObject |
|
567 |
! |
|
568 |
||
8361 | 569 |
nextPutBytes:count from:anObject startingAt:start |
570 |
"write count bytes from an object starting at index start. |
|
571 |
Return the number of bytes written. |
|
572 |
The object must have non-pointer indexed instvars |
|
573 |
(i.e. be a ByteArray, String, Float- or DoubleArray). |
|
574 |
Use with care - non object oriented i/o. |
|
575 |
This is provided for compatibility with externalStream; |
|
576 |
to support binary storage" |
|
577 |
||
578 |
anObject class isBytes ifTrue:[ |
|
579 |
self nextPutAll:anObject startingAt:start to:(start + count - 1). |
|
580 |
^ count. |
|
581 |
]. |
|
582 |
^ super nextPutBytes:count from:anObject startingAt:start |
|
1 | 583 |
! ! |
584 |
||
1965 | 585 |
!WriteStream class methodsFor:'documentation'! |
701 | 586 |
|
587 |
version |
|
8615 | 588 |
^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.61 2004-10-01 07:37:47 cg Exp $' |
701 | 589 |
! ! |