--- a/WriteStr.st Fri Aug 22 15:10:11 1997 +0200
+++ b/WriteStr.st Fri Aug 22 15:18:10 1997 +0200
@@ -35,7 +35,14 @@
documentation
"
- Streams for writing into - this implementation currently DOES change the
+ Streams for writing into.
+ WriteStreams are especially useful, if big strings are to be constructed
+ from pieces - create a writeStream, add the pieces (with #nextPut or
+ #nextPutAll) and finally fetch the concatenated string via #contents.
+ This is much better than constructing the big string by concatenating via
+ the comma (,) operator, since less intermediate garbage objects are created.
+
+ This implementation currently DOES change the
identity if the streamed-upon collection IF it cannot grow easily.
Collections which cannot grow easily are for example: Array, ByteArray and String.
Thus it is slightly incompatible to ST-80 since 'aStream contents' does
@@ -44,6 +51,44 @@
[author:]
Claus Gittinger
"
+!
+
+examples
+"
+ [exBegin]
+ |s|
+
+ s := WriteStream on:''.
+ s nextPutAll:'hello';
+ space;
+ nextPutAll:'world'.
+
+ s contents inspect
+ [exEnd]
+
+ [exBegin]
+ |s|
+
+ s := WriteStream on:''.
+ s nextPutAll:'hello';
+ space;
+ nextPutAll:'world'.
+
+ Transcript nextPutLine:(s contents)
+ [exEnd]
+
+ [exBegin]
+ |s|
+
+ s := '' writeStream.
+ s nextPutAll:'hello';
+ space;
+ nextPutAll:'world'.
+
+ Transcript nextPutLine:(s contents)
+ [exEnd]
+"
+
! !
!WriteStream methodsFor:'accessing'!
@@ -198,7 +243,7 @@
REGISTER int pos;
unsigned ch;
OBJ coll;
- OBJ p, l, rL;
+ OBJ p, wL, rL;
int __readLimit = -1;
coll = __INST(collection);
@@ -206,10 +251,10 @@
if (__isNonNilObject(coll) && __isSmallInteger(p)) {
pos = __intVal(p);
- l = __INST(writeLimit);
+ wL = __INST(writeLimit);
- if ((l == nil)
- || (__isSmallInteger(l) && (pos <= __intVal(l)))) {
+ if ((wL == nil)
+ || (__isSmallInteger(wL) && (pos <= __intVal(wL)))) {
OBJ cls;
cls = __qClass(coll);
@@ -221,21 +266,19 @@
if (cls == @global(String)) {
if (__isCharacter(anObject)
+ && ((ch = __intVal(__characterVal(anObject))) <= 255) /* ch is unsigned */
&& (pos <= __stringSize(coll))) {
- ch = __intVal(_characterVal(anObject));
- if (ch <= 255) { /* ch is unsigned */
- __StringInstPtr(coll)->s_element[pos-1] = ch;
- __INST(position) = __MKSMALLINT(pos + 1);
- if ((__readLimit >= 0) && (pos >= __readLimit)) {
- __INST(readLimit) = __MKSMALLINT(pos);
- }
- RETURN ( anObject );
+ __StringInstPtr(coll)->s_element[pos-1] = ch;
+ __INST(position) = __MKSMALLINT(pos + 1);
+ if ((__readLimit >= 0) && (pos >= __readLimit)) {
+ __INST(readLimit) = __MKSMALLINT(pos);
}
+ RETURN ( anObject );
}
} else if (cls == @global(ByteArray)) {
if (__isSmallInteger(anObject)
&& ((ch = __intVal(anObject)) <= 255) /* ch is unsigned */
- && (pos <= _byteArraySize(coll))) {
+ && (pos <= __byteArraySize(coll))) {
__ByteArrayInstPtr(coll)->ba_element[pos-1] = ch;
__INST(position) = __MKSMALLINT(pos + 1);
if ((__readLimit >= 0) && (pos >= __readLimit)) {
@@ -244,7 +287,7 @@
RETURN ( anObject );
}
} else if (cls == @global(Array)) {
- if (pos <= _arraySize(coll)) {
+ if (pos <= __arraySize(coll)) {
__ArrayInstPtr(coll)->a_element[pos-1] = anObject;
__STORE(coll, anObject);
__INST(position) = __MKSMALLINT(pos + 1);
@@ -346,5 +389,5 @@
!WriteStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Attic/WriteStr.st,v 1.35 1997-08-19 16:10:02 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Attic/WriteStr.st,v 1.36 1997-08-22 13:18:10 cg Exp $'
! !
--- a/WriteStream.st Fri Aug 22 15:10:11 1997 +0200
+++ b/WriteStream.st Fri Aug 22 15:18:10 1997 +0200
@@ -35,7 +35,14 @@
documentation
"
- Streams for writing into - this implementation currently DOES change the
+ Streams for writing into.
+ WriteStreams are especially useful, if big strings are to be constructed
+ from pieces - create a writeStream, add the pieces (with #nextPut or
+ #nextPutAll) and finally fetch the concatenated string via #contents.
+ This is much better than constructing the big string by concatenating via
+ the comma (,) operator, since less intermediate garbage objects are created.
+
+ This implementation currently DOES change the
identity if the streamed-upon collection IF it cannot grow easily.
Collections which cannot grow easily are for example: Array, ByteArray and String.
Thus it is slightly incompatible to ST-80 since 'aStream contents' does
@@ -44,6 +51,44 @@
[author:]
Claus Gittinger
"
+!
+
+examples
+"
+ [exBegin]
+ |s|
+
+ s := WriteStream on:''.
+ s nextPutAll:'hello';
+ space;
+ nextPutAll:'world'.
+
+ s contents inspect
+ [exEnd]
+
+ [exBegin]
+ |s|
+
+ s := WriteStream on:''.
+ s nextPutAll:'hello';
+ space;
+ nextPutAll:'world'.
+
+ Transcript nextPutLine:(s contents)
+ [exEnd]
+
+ [exBegin]
+ |s|
+
+ s := '' writeStream.
+ s nextPutAll:'hello';
+ space;
+ nextPutAll:'world'.
+
+ Transcript nextPutLine:(s contents)
+ [exEnd]
+"
+
! !
!WriteStream methodsFor:'accessing'!
@@ -198,7 +243,7 @@
REGISTER int pos;
unsigned ch;
OBJ coll;
- OBJ p, l, rL;
+ OBJ p, wL, rL;
int __readLimit = -1;
coll = __INST(collection);
@@ -206,10 +251,10 @@
if (__isNonNilObject(coll) && __isSmallInteger(p)) {
pos = __intVal(p);
- l = __INST(writeLimit);
+ wL = __INST(writeLimit);
- if ((l == nil)
- || (__isSmallInteger(l) && (pos <= __intVal(l)))) {
+ if ((wL == nil)
+ || (__isSmallInteger(wL) && (pos <= __intVal(wL)))) {
OBJ cls;
cls = __qClass(coll);
@@ -221,21 +266,19 @@
if (cls == @global(String)) {
if (__isCharacter(anObject)
+ && ((ch = __intVal(__characterVal(anObject))) <= 255) /* ch is unsigned */
&& (pos <= __stringSize(coll))) {
- ch = __intVal(_characterVal(anObject));
- if (ch <= 255) { /* ch is unsigned */
- __StringInstPtr(coll)->s_element[pos-1] = ch;
- __INST(position) = __MKSMALLINT(pos + 1);
- if ((__readLimit >= 0) && (pos >= __readLimit)) {
- __INST(readLimit) = __MKSMALLINT(pos);
- }
- RETURN ( anObject );
+ __StringInstPtr(coll)->s_element[pos-1] = ch;
+ __INST(position) = __MKSMALLINT(pos + 1);
+ if ((__readLimit >= 0) && (pos >= __readLimit)) {
+ __INST(readLimit) = __MKSMALLINT(pos);
}
+ RETURN ( anObject );
}
} else if (cls == @global(ByteArray)) {
if (__isSmallInteger(anObject)
&& ((ch = __intVal(anObject)) <= 255) /* ch is unsigned */
- && (pos <= _byteArraySize(coll))) {
+ && (pos <= __byteArraySize(coll))) {
__ByteArrayInstPtr(coll)->ba_element[pos-1] = ch;
__INST(position) = __MKSMALLINT(pos + 1);
if ((__readLimit >= 0) && (pos >= __readLimit)) {
@@ -244,7 +287,7 @@
RETURN ( anObject );
}
} else if (cls == @global(Array)) {
- if (pos <= _arraySize(coll)) {
+ if (pos <= __arraySize(coll)) {
__ArrayInstPtr(coll)->a_element[pos-1] = anObject;
__STORE(coll, anObject);
__INST(position) = __MKSMALLINT(pos + 1);
@@ -346,5 +389,5 @@
!WriteStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.35 1997-08-19 16:10:02 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.36 1997-08-22 13:18:10 cg Exp $'
! !