--- a/WriteStream.st Mon Apr 27 16:16:56 2015 +0200
+++ b/WriteStream.st Mon Apr 27 19:04:19 2015 +0200
@@ -47,22 +47,22 @@
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.
+ 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
+ Thus it is slightly incompatible to ST-80 since 'aStream contents' does
not always return the original collection. This may change.
[caveat:]
- Basing capabilities like readability/writability/positionability/peekability on inheritance makes
- the class hierarchy ugly and leads to strange and hard to teach redefinitions (aka. NonPositionableStream
- below PositionableStream or ExternalReadStream under WriteStream)
+ Basing capabilities like readability/writability/positionability/peekability on inheritance makes
+ the class hierarchy ugly and leads to strange and hard to teach redefinitions (aka. NonPositionableStream
+ below PositionableStream or ExternalReadStream under WriteStream)
[author:]
- Claus Gittinger
+ Claus Gittinger
[see also:]
- CharacterWriteStream (if streaming for a unicode string)
+ CharacterWriteStream (if streaming for a unicode string)
"
!
@@ -125,15 +125,15 @@
lastIndex := position.
collection size == lastIndex ifFalse:[
- collection isFixedSize ifTrue:[
- "
- grow is expensive - return a copy.
- (is this what users of writeStream expect ?)
- "
- collection := collection copyFrom:1 to:lastIndex
- ] ifFalse:[
- collection grow:lastIndex
- ]
+ collection isFixedSize ifTrue:[
+ "
+ grow is expensive - return a copy.
+ (is this what users of writeStream expect ?)
+ "
+ collection := collection copyFrom:1 to:lastIndex
+ ] ifFalse:[
+ collection grow:lastIndex
+ ]
].
^ collection
@@ -151,11 +151,11 @@
s := '' writeStream.
s nextPut:$a.
- s last.
+ s last.
s nextPut:$b.
- s last.
+ s last.
s nextPut:$c.
- s last.
+ s last.
"
!
@@ -170,14 +170,14 @@
s := '' writeStream.
s nextPut:$a.
- s last:1.
+ s last:1.
s nextPut:$b.
- s last:1.
- s last:2.
+ s last:1.
+ s last:2.
s nextPut:$c.
- s last:1.
- s last:2.
- s last:3.
+ s last:1.
+ s last:2.
+ s last:3.
"
!
@@ -286,7 +286,7 @@
"Created: 14.10.1997 / 20:44:37 / cg"
!
-isReadable
+isReadable
"return true if the receiver supports reading - thats not true"
^ false
@@ -315,13 +315,13 @@
count == 0 ifTrue:[^ self].
(collection isNil or:[writeLimit notNil]) ifTrue:[
- super next:count put:anObject.
- ^ self.
+ super next:count put:anObject.
+ ^ self.
].
final := position + count.
(final > collection size) ifTrue:[
- self growCollection:final
+ self growCollection:final
].
collection from:position + 1 to:final put:anObject.
@@ -345,7 +345,7 @@
s := '' writeStream.
s nextPutAll:'hello '.
s next:5 putAll:'1234world012345' startingAt:5.
- s contents
+ s contents
"
"Modified: 12.7.1996 / 10:31:36 / cg"
@@ -368,73 +368,73 @@
p = __INST(position);
if (__isNonNilObject(coll) && __isSmallInteger(p)) {
- pos = __intVal(p);
- /* make 1-based */
- pos = pos + 1;
- wL = __INST(writeLimit);
+ pos = __intVal(p);
+ /* make 1-based */
+ pos = pos + 1;
+ wL = __INST(writeLimit);
- if ((wL == nil)
- || (__isSmallInteger(wL) && (pos <= __intVal(wL)))) {
- OBJ cls;
+ if ((wL == nil)
+ || (__isSmallInteger(wL) && (pos <= __intVal(wL)))) {
+ OBJ cls;
- cls = __qClass(coll);
+ cls = __qClass(coll);
- rL = __INST(readLimit);
- if (__isSmallInteger(rL)) {
- __readLimit = __intVal(rL);
- }
+ rL = __INST(readLimit);
+ if (__isSmallInteger(rL)) {
+ __readLimit = __intVal(rL);
+ }
- if (cls == @global(String)) {
- if (__isCharacter(anObject)
- && ((ch = __intVal(__characterVal(anObject))) <= 255) /* ch is unsigned */
- && (pos <= __stringSize(coll))) {
- __StringInstPtr(coll)->s_element[pos-1] = ch;
-advancePositionAndReturn: ;
- if ((__readLimit >= 0) && (pos >= __readLimit)) {
- __INST(readLimit) = __mkSmallInteger(pos);
- }
- __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
- RETURN ( anObject );
- }
- } else if (cls == @global(ByteArray)) {
- if (__isSmallInteger(anObject)
- && ((ch = __intVal(anObject)) <= 0xFF) /* ch is unsigned */
- && (pos <= __byteArraySize(coll))) {
- __ByteArrayInstPtr(coll)->ba_element[pos-1] = ch;
- goto advancePositionAndReturn;
- }
- } else if (cls == @global(Array)) {
- if (pos <= __arraySize(coll)) {
- __ArrayInstPtr(coll)->a_element[pos-1] = anObject;
- __STORE(coll, anObject);
- goto advancePositionAndReturn;
- }
- } else if (cls == @global(Unicode16String)) {
- if (__isCharacter(anObject)
- && ((ch = __intVal(__characterVal(anObject))) <= 0xFFFF) /* ch is unsigned */
- && (pos <= __unicode16StringSize(coll))) {
- __Unicode16StringInstPtr(coll)->s_element[pos-1] = ch;
- goto advancePositionAndReturn;
- }
- } else if (cls == @global(Unicode32String)) {
- if (__isCharacter(anObject)
- && (pos <= __unicode32StringSize(coll))) {
- __Unicode32StringInstPtr(coll)->s_element[pos-1] = __intVal(__characterVal(anObject));
- goto advancePositionAndReturn;
- }
- }
- }
+ if (cls == @global(String)) {
+ if (__isCharacter(anObject)
+ && ((ch = __intVal(__characterVal(anObject))) <= 255) /* ch is unsigned */
+ && (pos <= __stringSize(coll))) {
+ __StringInstPtr(coll)->s_element[pos-1] = ch;
+advancePositionAndReturn: ;
+ if ((__readLimit >= 0) && (pos >= __readLimit)) {
+ __INST(readLimit) = __mkSmallInteger(pos);
+ }
+ __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
+ RETURN ( anObject );
+ }
+ } else if (cls == @global(ByteArray)) {
+ if (__isSmallInteger(anObject)
+ && ((ch = __intVal(anObject)) <= 0xFF) /* ch is unsigned */
+ && (pos <= __byteArraySize(coll))) {
+ __ByteArrayInstPtr(coll)->ba_element[pos-1] = ch;
+ goto advancePositionAndReturn;
+ }
+ } else if (cls == @global(Array)) {
+ if (pos <= __arraySize(coll)) {
+ __ArrayInstPtr(coll)->a_element[pos-1] = anObject;
+ __STORE(coll, anObject);
+ goto advancePositionAndReturn;
+ }
+ } else if (cls == @global(Unicode16String)) {
+ if (__isCharacter(anObject)
+ && ((ch = __intVal(__characterVal(anObject))) <= 0xFFFF) /* ch is unsigned */
+ && (pos <= __unicode16StringSize(coll))) {
+ __Unicode16StringInstPtr(coll)->s_element[pos-1] = ch;
+ goto advancePositionAndReturn;
+ }
+ } else if (cls == @global(Unicode32String)) {
+ if (__isCharacter(anObject)
+ && (pos <= __unicode32StringSize(coll))) {
+ __Unicode32StringInstPtr(coll)->s_element[pos-1] = __intVal(__characterVal(anObject));
+ goto advancePositionAndReturn;
+ }
+ }
+ }
}
#endif
%}.
(writeLimit isNil
or:[(position + 1) <= writeLimit]) ifTrue:[
- (position >= collection size) ifTrue:[self growCollection].
- collection at:(position + 1) put:anObject.
- (position >= readLimit) ifTrue:[readLimit := (position + 1)].
- position := position + 1.
+ (position >= collection size) ifTrue:[self growCollection].
+ collection at:(position + 1) put:anObject.
+ (position >= readLimit) ifTrue:[readLimit := (position + 1)].
+ position := position + 1.
] ifFalse:[
- WriteError raiseErrorString:'write beyond writeLimit'
+ WriteError raiseErrorString:'write beyond writeLimit'
].
^anObject
!
@@ -447,34 +447,34 @@
|nMore "{ Class: SmallInteger }"
final "{ Class: SmallInteger }" |
- (collection isNil or:[aCollection isSequenceable not]) ifTrue:[
- "/ fallback
- super nextPutAll:aCollection.
- ^ self.
+ (collection notNil and:[aCollection isSequenceable]) ifFalse:[
+ "/ fallback
+ super nextPutAll:aCollection.
+ ^ self.
].
nMore := aCollection size.
nMore == 0 ifTrue:[
- "/ for the programmer..
- aCollection isCollection ifFalse:[
- self error:'invalid argument (not a collection)' mayProceed:true
- ].
+ "/ for the programmer..
+ aCollection isCollection ifFalse:[
+ self error:'invalid argument (not a collection)' mayProceed:true
+ ].
].
final := position + nMore.
(writeLimit notNil
and:[final > writeLimit]) ifTrue:[
- final := writeLimit.
- nMore := final - position
+ final := writeLimit.
+ nMore := final - position
].
(final > collection size) ifTrue:[
- self growCollection:final
+ self growCollection:final
].
- collection
- replaceFrom:(position + 1)
- to:final
- with:aCollection
- startingAt:1.
+ collection
+ replaceFrom:(position + 1)
+ to:final
+ with:aCollection
+ startingAt:1.
(position >= readLimit) ifTrue:[readLimit := position].
position := position + nMore.
@@ -491,24 +491,24 @@
|nMore final|
collection isNil ifTrue:[
- ^ super nextPutAll:aCollection startingAt:pos1 to:pos2
+ ^ super nextPutAll:aCollection startingAt:pos1 to:pos2
].
nMore := pos2 - pos1 + 1.
final := position + nMore.
(writeLimit notNil
and:[final > writeLimit]) ifTrue:[
- final := writeLimit.
- nMore := final - position
+ final := writeLimit.
+ nMore := final - position
].
(final > collection size) ifTrue:[
- self growCollection:final
+ self growCollection:final
].
collection replaceFrom:position + 1
- to:final
- with:aCollection
- startingAt:pos1.
+ to:final
+ with:aCollection
+ startingAt:pos1.
position := position + nMore.
(position >= readLimit) ifTrue:[readLimit := position].
@@ -530,17 +530,17 @@
"normal streams can not handle multi-byte characters, so convert them to utf8"
"this code is not perfect if you use both #nextPutAll: and #nextPutAllUnicode:
- with the same stream, since 8-bit characters (with the highest bits set)
+ with the same stream, since 8-bit characters (with the highest bits set)
are not stored as UTF, so we get some inconsistent string"
collection isString ifTrue:[
- collection bitsPerCharacter == 16 ifTrue:[
- self nextPutAllUtf16:aString.
- ] ifFalse:[
- self nextPutAllUtf8:aString.
- ].
+ collection bitsPerCharacter == 16 ifTrue:[
+ self nextPutAllUtf16:aString.
+ ] ifFalse:[
+ self nextPutAllUtf8:aString.
+ ].
] ifFalse:[
- self nextPutAll:aString
+ self nextPutAll:aString
].
"Modified: / 28-09-2011 / 16:15:52 / cg"
@@ -562,45 +562,45 @@
p = __INST(position);
if (__isNonNilObject(coll) && __isSmallInteger(p) && __isSmallInteger(anObject)) {
- unsigned ch;
+ unsigned ch;
- ch = __intVal(anObject);
+ ch = __intVal(anObject);
- pos = __intVal(p);
- /* make 1-based */
- pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
- wL = __INST(writeLimit);
+ pos = __intVal(p);
+ /* make 1-based */
+ pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
+ wL = __INST(writeLimit);
- if ((wL == nil)
- || (__isSmallInteger(wL) && (pos <= __intVal(wL)))) {
- OBJ cls;
+ if ((wL == nil)
+ || (__isSmallInteger(wL) && (pos <= __intVal(wL)))) {
+ OBJ cls;
- cls = __qClass(coll);
+ cls = __qClass(coll);
- rL = __INST(readLimit);
- if (__isSmallInteger(rL)) {
- __readLimit = __intVal(rL);
- }
+ rL = __INST(readLimit);
+ if (__isSmallInteger(rL)) {
+ __readLimit = __intVal(rL);
+ }
- if (cls == @global(String)) {
- if ((pos <= __stringSize(coll))
- && (ch <= 0xFF)) { /* ch is unsigned */
- __StringInstPtr(coll)->s_element[pos-1] = ch;
- advancePositionAndReturn: ;
- if ((__readLimit >= 0) && (pos >= __readLimit)) {
- __INST(readLimit) = __mkSmallInteger(pos);
- }
- __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
- RETURN ( anObject );
- }
- } else if (cls == @global(ByteArray)) {
- if ((pos <= __byteArraySize(coll))
- && (ch <= 0xFF)) { /* ch is unsigned */
- __ByteArrayInstPtr(coll)->ba_element[pos-1] = ch;
- goto advancePositionAndReturn;
- }
- }
- }
+ if (cls == @global(String)) {
+ if ((pos <= __stringSize(coll))
+ && (ch <= 0xFF)) { /* ch is unsigned */
+ __StringInstPtr(coll)->s_element[pos-1] = ch;
+ advancePositionAndReturn: ;
+ if ((__readLimit >= 0) && (pos >= __readLimit)) {
+ __INST(readLimit) = __mkSmallInteger(pos);
+ }
+ __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
+ RETURN ( anObject );
+ }
+ } else if (cls == @global(ByteArray)) {
+ if ((pos <= __byteArraySize(coll))
+ && (ch <= 0xFF)) { /* ch is unsigned */
+ __ByteArrayInstPtr(coll)->ba_element[pos-1] = ch;
+ goto advancePositionAndReturn;
+ }
+ }
+ }
}
#endif
%}.
@@ -610,15 +610,15 @@
nextPutBytes:count from:anObject startingAt:start
"write count bytes from an object starting at index start.
Return the number of bytes written.
- The object must have non-pointer indexed instvars
- (i.e. be a ByteArray, String, Float- or DoubleArray).
+ The object must have non-pointer indexed instvars
+ (i.e. be a ByteArray, String, Float- or DoubleArray).
Use with care - non object oriented i/o.
This is provided for compatibility with externalStream;
to support binary storage"
anObject isByteCollection ifTrue:[
- self nextPutAll:anObject startingAt:start to:(start + count - 1).
- ^ count.
+ self nextPutAll:anObject startingAt:start to:(start + count - 1).
+ ^ count.
].
^ super nextPutBytes:count from:anObject startingAt:start
!
@@ -627,27 +627,26 @@
"normal streams can not handle multi-byte characters, so convert them to utf8"
"this code is not perfect if you use both #nextPut: and #nextPutUnicode:
- with the same stream, since 8-bit characters (with the highest bits set)
+ with the same stream, since 8-bit characters (with the highest bits set)
are not stored as UTF, so we get some inconsistent string"
collection isString ifTrue:[
- collection bitsPerCharacter == 16 ifTrue:[
- self nextPutUtf16:aCharacter.
- ] ifFalse:[
- self nextPutUtf8:aCharacter.
- ].
+ collection bitsPerCharacter == 16 ifTrue:[
+ self nextPutUtf16:aCharacter.
+ ] ifFalse:[
+ self nextPutUtf8:aCharacter.
+ ].
] ifFalse:[
- self nextPut:aCharacter.
+ self nextPut:aCharacter.
].
! !
!WriteStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.96 2015-03-26 23:32:34 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.97 2015-04-27 17:04:19 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.96 2015-03-26 23:32:34 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.97 2015-04-27 17:04:19 cg Exp $'
! !
-