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