8298
|
1 |
'From Smalltalk/X, Version:5.2.2 on 06-04-2004 at 17:40:13' !
|
|
2 |
|
8299
|
3 |
"{ Package: 'stx:libbasic' }"
|
8298
|
4 |
|
|
5 |
WriteStream subclass:#CharacterWriteStream
|
|
6 |
instanceVariableNames:'currentCharacterSize'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'Streams'
|
|
10 |
!
|
|
11 |
|
|
12 |
!CharacterWriteStream methodsFor:'writing'!
|
|
13 |
|
|
14 |
nextPut:anObject
|
|
15 |
"append the argument, anObject to the stream.
|
|
16 |
Specially tuned for appending to String, ByteArray and Array streams."
|
|
17 |
|
|
18 |
%{ /* NOCONTEXT */
|
|
19 |
|
|
20 |
#ifndef NO_PRIM_STREAM
|
|
21 |
REGISTER int pos;
|
|
22 |
unsigned ch;
|
|
23 |
OBJ coll;
|
|
24 |
OBJ p, wL, rL;
|
|
25 |
int __readLimit = -1;
|
|
26 |
|
|
27 |
coll = __INST(collection);
|
|
28 |
p = __INST(position);
|
|
29 |
|
|
30 |
if (__isNonNilObject(coll) && __isSmallInteger(p) && __isCharacter(anObject)) {
|
|
31 |
pos = __intVal(p);
|
|
32 |
/* make 1-based */
|
|
33 |
pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
|
|
34 |
wL = __INST(writeLimit);
|
|
35 |
|
|
36 |
if ((wL == nil)
|
|
37 |
|| (__isSmallInteger(wL) && (pos <= __intVal(wL)))) {
|
|
38 |
OBJ cls;
|
|
39 |
|
|
40 |
cls = __qClass(coll);
|
|
41 |
ch = __intVal(__characterVal(anObject));
|
|
42 |
|
|
43 |
rL = __INST(readLimit);
|
|
44 |
if (__isSmallInteger(rL)) {
|
|
45 |
__readLimit = __intVal(rL);
|
|
46 |
}
|
|
47 |
|
|
48 |
if (cls == @global(String)) {
|
|
49 |
if (ch > 0xFF) {
|
|
50 |
goto resize;
|
|
51 |
}
|
|
52 |
if (pos <= __stringSize(coll)) {
|
|
53 |
__StringInstPtr(coll)->s_element[pos-1] = ch;
|
|
54 |
if ((__readLimit >= 0) && (pos >= __readLimit)) {
|
|
55 |
__INST(readLimit) = __MKSMALLINT(pos);
|
|
56 |
}
|
|
57 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1);
|
|
58 |
RETURN ( anObject );
|
|
59 |
}
|
|
60 |
} else if (cls == @global(Unicode16String)) {
|
|
61 |
if (ch > 0xFFFF) {
|
|
62 |
goto resize;
|
|
63 |
}
|
|
64 |
if (pos <= __unicode16StringSize(coll)) {
|
|
65 |
__Unicode16StringInstPtr(coll)->s_element[pos-1] = ch;
|
|
66 |
if ((__readLimit >= 0) && (pos >= __readLimit)) {
|
|
67 |
__INST(readLimit) = __MKSMALLINT(pos);
|
|
68 |
}
|
|
69 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1);
|
|
70 |
RETURN ( anObject );
|
|
71 |
}
|
|
72 |
} else if (cls == @global(Unicode32String)) {
|
|
73 |
if ((pos <= __unicode32StringSize(coll))) {
|
|
74 |
__Unicode32StringInstPtr(coll)->s_element[pos-1] = ch;
|
|
75 |
if ((__readLimit >= 0) && (pos >= __readLimit)) {
|
|
76 |
__INST(readLimit) = __MKSMALLINT(pos);
|
|
77 |
}
|
|
78 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1);
|
|
79 |
RETURN ( anObject );
|
|
80 |
}
|
|
81 |
}
|
|
82 |
}
|
|
83 |
}
|
|
84 |
resize:;
|
|
85 |
#endif
|
|
86 |
%}.
|
|
87 |
|
|
88 |
(writeLimit isNil
|
|
89 |
or:[(position + 1 - ZeroPosition) <= writeLimit]) ifTrue:[
|
|
90 |
((position + 1 - ZeroPosition) > collection size) ifTrue:[self growCollection].
|
|
91 |
collection at:(position + 1 - ZeroPosition) put:anObject.
|
|
92 |
((position + 1 - ZeroPosition) > readLimit) ifTrue:[readLimit := (position + 1 - ZeroPosition)].
|
|
93 |
position := position + 1.
|
|
94 |
] ifFalse:[
|
|
95 |
WriteErrorSignal raiseErrorString:'write beyond writeLimit'
|
|
96 |
].
|
|
97 |
^anObject
|
|
98 |
! !
|
|
99 |
|