--- a/WriteStream.st Fri Apr 22 21:13:32 2016 +0100
+++ b/WriteStream.st Sat Apr 23 09:05:39 2016 +0100
@@ -313,18 +313,18 @@
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.
position := position + count.
- (position >= readLimit) ifTrue:[readLimit := position].
+ (position > readLimit) ifTrue:[readLimit := position].
"/ ^ anObject -- return self
"
@@ -366,73 +366,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;
+ 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 ((__readLimit >= 0) && (pos > __readLimit)) {
+ __INST(readLimit) = __mkSmallInteger(pos);
+ }
+ __INST(position) = __mkSmallInteger(pos);
+ 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 := position + 1.
+ (position > readLimit) ifTrue:[readLimit := position].
] ifFalse:[
- WriteError raiseErrorString:'write beyond writeLimit'
+ WriteError raiseErrorString:'write beyond writeLimit'
].
^anObject
!
@@ -446,36 +446,36 @@
final "{ Class: SmallInteger }" |
(collection notNil and:[aCollection isSequenceable]) ifFalse:[
- "/ fallback
- super nextPutAll:aCollection.
- ^ self.
+ "/ 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.
+ replaceFrom:(position + 1)
+ to:final
+ with:aCollection
+ startingAt:1.
- (position >= readLimit) ifTrue:[readLimit := position].
position := position + nMore.
+ (position > readLimit) ifTrue:[readLimit := position].
"/ ^ aCollection -- self
"Modified: / 04-09-2011 / 20:03:32 / cg"
@@ -489,27 +489,27 @@
|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].
+ (position > readLimit) ifTrue:[readLimit := position].
"/ ^ aCollection -- return self
"
@@ -560,45 +560,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 and usable for update below */
+ 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 ((pos <= __stringSize(coll))
- && (ch <= 0xFF)) { /* ch is unsigned */
- __StringInstPtr(coll)->s_element[pos-1] = ch;
+ 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 ((__readLimit >= 0) && (pos > __readLimit)) {
+ __INST(readLimit) = __mkSmallInteger(pos);
+ }
+ __INST(position) = __mkSmallInteger(pos);
+ 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
%}.