--- a/ReadStream.st Sun Jun 09 00:49:37 2013 +0100
+++ b/ReadStream.st Mon Jun 10 17:32:35 2013 +0100
@@ -103,19 +103,19 @@
Streams on collections which nothing at all about emphasises,
will report an error."
- ^ collection emphasisAt:(position - ZeroPosition + 1).
+ ^ collection emphasisAt:(position + 1).
"
|t s|
t := 'hello world' asText
- emphasizeFrom:1 to:5 with:#bold;
- emphasizeFrom:7 to:11 with:#italic.
+ emphasizeFrom:1 to:5 with:#bold;
+ emphasizeFrom:7 to:11 with:#italic.
s := t readStream.
[s atEnd] whileFalse:[
- Transcript show:(s emphasis); show:' '.
- Transcript show:''''; show:(s next); showCR:''''.
+ Transcript show:(s emphasis); show:' '.
+ Transcript show:''''; show:(s next); showCR:''''.
].
"
@@ -171,46 +171,46 @@
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) {
- pos = __intVal(p);
- /* make 1-based */
- pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
- if (pos > 0 && pos <= __intVal(l)) {
- OBJ cls, ret;
+ pos = __intVal(p);
+ /* make 1-based */
+ pos = pos + 1;
+ if (pos > 0 && pos <= __intVal(l)) {
+ OBJ cls, ret;
- cls = __qClass(coll);
- if (cls == @global(String)) {
- if (pos <= __stringSize(coll)) {
- ch = __stringVal(coll)[pos-1];
- ret = __MKCHARACTER(ch);
- __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
- RETURN ( ret );
- }
- } else if (cls == @global(ByteArray)) {
- if (pos <= __byteArraySize(coll)) {
- ch = __ByteArrayInstPtr(coll)->ba_element[pos-1];
- ret = __mkSmallInteger(ch);
- __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
- RETURN ( ret );
- }
- } else if (cls == @global(Unicode16String)) {
- if (pos <= __unicode16StringSize(coll)) {
- ch = __Unicode16StringInstPtr(coll)->s_element[pos-1];
- ret = __MKUCHARACTER(ch);
- __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
- RETURN ( ret );
- }
- } else if (cls == @global(Array)) {
- if (pos <= __arraySize(coll)) {
- ret = __ArrayInstPtr(coll)->a_element[pos-1];
- __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
- RETURN ( ret );
- }
- }
- }
+ cls = __qClass(coll);
+ if (cls == @global(String)) {
+ if (pos <= __stringSize(coll)) {
+ ch = __stringVal(coll)[pos-1];
+ ret = __MKCHARACTER(ch);
+ __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
+ RETURN ( ret );
+ }
+ } else if (cls == @global(ByteArray)) {
+ if (pos <= __byteArraySize(coll)) {
+ ch = __ByteArrayInstPtr(coll)->ba_element[pos-1];
+ ret = __mkSmallInteger(ch);
+ __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
+ RETURN ( ret );
+ }
+ } else if (cls == @global(Unicode16String)) {
+ if (pos <= __unicode16StringSize(coll)) {
+ ch = __Unicode16StringInstPtr(coll)->s_element[pos-1];
+ ret = __MKUCHARACTER(ch);
+ __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
+ RETURN ( ret );
+ }
+ } else if (cls == @global(Array)) {
+ if (pos <= __arraySize(coll)) {
+ ret = __ArrayInstPtr(coll)->a_element[pos-1];
+ __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
+ RETURN ( ret );
+ }
+ }
+ }
}
%}.
- ((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEndRead].
- ret := collection at:(position + 1 - ZeroPosition).
+ (position >= readLimit) ifTrue:[^ self pastEndRead].
+ ret := collection at:(position + 1).
position := position + 1.
^ ret
!
@@ -222,19 +222,19 @@
|answer|
self contentsSpecies = collection class ifTrue:[
- ((position + count - ZeroPosition) > readLimit) ifFalse:[
- answer := collection copyFrom:position+1 to:position+count.
- position := position+count.
- ^ answer
- ].
+ ((position + count) > readLimit) ifFalse:[
+ answer := collection copyFrom:position+1 to:position+count.
+ position := position+count.
+ ^ answer
+ ].
].
^ super next:count
"
#[1 2 3 4 5 6 7 8 9] readStream
- next;
- next:5;
- next.
+ next;
+ next:5;
+ next.
"
!
@@ -329,39 +329,39 @@
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) {
- pos = __intVal(p);
- /* make 1-based */
- pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
- if (pos > 0 && pos <= __intVal(l)) {
- OBJ cls, ret;
+ pos = __intVal(p);
+ /* make 1-based */
+ pos = pos + 1;
+ if (pos > 0 && pos <= __intVal(l)) {
+ OBJ cls, ret;
- cls = __qClass(coll);
- if (cls == @global(String)) {
- if (pos <= __stringSize(coll)) {
- ch = __stringVal(coll)[pos-1];
- ret = __mkSmallInteger(ch);
- __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
- RETURN ( ret );
- }
- } else if (cls == @global(ByteArray)) {
- if (pos <= __byteArraySize(coll)) {
- ch = __ByteArrayInstPtr(coll)->ba_element[pos-1];
- ret = __mkSmallInteger(ch);
- __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
- RETURN ( ret );
- }
- } else if (cls == @global(Array)) {
- if (pos <= __arraySize(coll)) {
- ret = __ArrayInstPtr(coll)->a_element[pos-1];
- __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
- RETURN ( ret );
- }
- }
- }
+ cls = __qClass(coll);
+ if (cls == @global(String)) {
+ if (pos <= __stringSize(coll)) {
+ ch = __stringVal(coll)[pos-1];
+ ret = __mkSmallInteger(ch);
+ __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
+ RETURN ( ret );
+ }
+ } else if (cls == @global(ByteArray)) {
+ if (pos <= __byteArraySize(coll)) {
+ ch = __ByteArrayInstPtr(coll)->ba_element[pos-1];
+ ret = __mkSmallInteger(ch);
+ __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
+ RETURN ( ret );
+ }
+ } else if (cls == @global(Array)) {
+ if (pos <= __arraySize(coll)) {
+ ret = __ArrayInstPtr(coll)->a_element[pos-1];
+ __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
+ RETURN ( ret );
+ }
+ }
+ }
}
%}.
- ((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEndRead].
- ret := collection at:(position + 1 -ZeroPosition).
+ (position >= readLimit) ifTrue:[^ self pastEndRead].
+ ret := collection at:(position + 1).
position := position + 1.
^ ret asInteger
!
@@ -480,49 +480,49 @@
l = __INST(readLimit);
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) {
- pos = __intVal(p);
- /* make 1-based */
- pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
- if (pos > 0) {
- OBJ cls, ret;
+ pos = __intVal(p);
+ /* make 1-based */
+ pos = pos + 1;
+ if (pos > 0) {
+ OBJ cls, ret;
- if (pos > __intVal(l)) {
- RETURN(nil);
- }
+ if (pos > __intVal(l)) {
+ RETURN(nil);
+ }
- cls = __qClass(coll);
- if (cls == @global(String)) {
- if (pos <= __stringSize(coll)) {
- ch = __stringVal(coll)[pos-1];
- ret = __MKCHARACTER(ch);
- __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
- RETURN ( ret );
- }
- } else if (cls == @global(ByteArray)) {
- if (pos <= __byteArraySize(coll)) {
- ch = __ByteArrayInstPtr(coll)->ba_element[pos-1];
- ret = __mkSmallInteger(ch);
- __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
- RETURN ( ret );
- }
- } else if (cls == @global(Unicode16String)) {
- if (pos <= __unicode16StringSize(coll)) {
- ch = __Unicode16StringInstPtr(coll)->s_element[pos-1];
- ret = __MKUCHARACTER(ch);
- __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
- RETURN ( ret );
- }
- } else if (cls == @global(Array)) {
- if (pos <= __arraySize(coll)) {
- ret = __ArrayInstPtr(coll)->a_element[pos-1];
- __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
- RETURN ( ret );
- }
- }
- }
+ cls = __qClass(coll);
+ if (cls == @global(String)) {
+ if (pos <= __stringSize(coll)) {
+ ch = __stringVal(coll)[pos-1];
+ ret = __MKCHARACTER(ch);
+ __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
+ RETURN ( ret );
+ }
+ } else if (cls == @global(ByteArray)) {
+ if (pos <= __byteArraySize(coll)) {
+ ch = __ByteArrayInstPtr(coll)->ba_element[pos-1];
+ ret = __mkSmallInteger(ch);
+ __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
+ RETURN ( ret );
+ }
+ } else if (cls == @global(Unicode16String)) {
+ if (pos <= __unicode16StringSize(coll)) {
+ ch = __Unicode16StringInstPtr(coll)->s_element[pos-1];
+ ret = __MKUCHARACTER(ch);
+ __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
+ RETURN ( ret );
+ }
+ } else if (cls == @global(Array)) {
+ if (pos <= __arraySize(coll)) {
+ ret = __ArrayInstPtr(coll)->a_element[pos-1];
+ __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
+ RETURN ( ret );
+ }
+ }
+ }
}
%}.
- ret := collection at:(position + 1 - ZeroPosition).
+ ret := collection at:(position + 1).
position := position + 1.
^ ret
!
@@ -540,26 +540,26 @@
l = __INST(readLimit);
if (__isStringLike(coll) && __bothSmallInteger(p, l)) {
- REGISTER int pos;
- unsigned ch;
+ REGISTER int pos;
+ unsigned ch;
- pos = __intVal(p);
- /* make 1-based */
- pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
- if ((pos > 0) && (pos < __intVal(l)) && (pos < __stringSize(coll))) {
- pos = pos + 1;
- ch = __stringVal(coll)[pos-1];
- /* make ZeroPosition-based */
- pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition));
- __INST(position) = __mkSmallInteger(pos);
- RETURN ( __MKCHARACTER(ch) );
- }
+ pos = __intVal(p);
+ /* make 1-based */
+ pos = pos + 1;
+ if ((pos > 0) && (pos < __intVal(l)) && (pos < __stringSize(coll))) {
+ pos = pos + 1;
+ ch = __stringVal(coll)[pos-1];
+ /* make ZeroPosition-based */
+ pos = pos - 1;
+ __INST(position) = __mkSmallInteger(pos);
+ RETURN ( __MKCHARACTER(ch) );
+ }
}
%}.
- ((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEndRead].
+ (position >= readLimit) ifTrue:[^ self pastEndRead].
position := position + 1.
- ((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEndRead].
- ^ collection at:(position + 1 - ZeroPosition)
+ (position >= readLimit) ifTrue:[^ self pastEndRead].
+ ^ collection at:(position + 1)
!
peek
@@ -580,31 +580,31 @@
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) {
- pos = __intVal(p);
- /* make 1-based */
- pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
- if (pos <= __intVal(l) && pos > 0) {
- cls = __qClass(coll);
- if (cls == @global(String)) {
- if (pos <= __stringSize(coll)) {
- ch = __stringVal(coll)[pos-1];
- RETURN ( __MKCHARACTER(ch) );
- }
- } else if (cls == @global(ByteArray)) {
- if (pos <= __byteArraySize(coll)) {
- ch = __ByteArrayInstPtr(coll)->ba_element[pos-1];
- RETURN ( __mkSmallInteger(ch) );
- }
- } else if (cls == @global(Array)) {
- if (pos <= __arraySize(coll)) {
- RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]);
- }
- }
- }
+ pos = __intVal(p);
+ /* make 1-based */
+ pos = pos + 1;
+ if (pos <= __intVal(l) && pos > 0) {
+ cls = __qClass(coll);
+ if (cls == @global(String)) {
+ if (pos <= __stringSize(coll)) {
+ ch = __stringVal(coll)[pos-1];
+ RETURN ( __MKCHARACTER(ch) );
+ }
+ } else if (cls == @global(ByteArray)) {
+ if (pos <= __byteArraySize(coll)) {
+ ch = __ByteArrayInstPtr(coll)->ba_element[pos-1];
+ RETURN ( __mkSmallInteger(ch) );
+ }
+ } else if (cls == @global(Array)) {
+ if (pos <= __arraySize(coll)) {
+ RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]);
+ }
+ }
+ }
}
%}.
- ((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEndRead].
- ^ collection at:(position + 1 - ZeroPosition)
+ (position >= readLimit) ifTrue:[^ self pastEndRead].
+ ^ collection at:(position + 1)
!
peekOrNil
@@ -627,34 +627,34 @@
if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) {
- pos = __intVal(p);
- /* make 1-based */
- pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
- if (pos <= __intVal(l) && pos > 0) {
- cls = __qClass(coll);
- if (cls == @global(String)) {
- if (pos <= __stringSize(coll)) {
- ch = __stringVal(coll)[pos-1];
- RETURN ( __MKCHARACTER(ch) );
- }
- RETURN ( nil );
- } else if (cls == @global(ByteArray)) {
- if (pos <= __byteArraySize(coll)) {
- ch = __ByteArrayInstPtr(coll)->ba_element[pos-1];
- RETURN ( __mkSmallInteger(ch) );
- }
- RETURN ( nil );
- } else if (cls == @global(Array)) {
- if (pos <= __arraySize(coll)) {
- RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]);
- }
- RETURN ( nil );
- }
- }
+ pos = __intVal(p);
+ /* make 1-based */
+ pos = pos + 1;
+ if (pos <= __intVal(l) && pos > 0) {
+ cls = __qClass(coll);
+ if (cls == @global(String)) {
+ if (pos <= __stringSize(coll)) {
+ ch = __stringVal(coll)[pos-1];
+ RETURN ( __MKCHARACTER(ch) );
+ }
+ RETURN ( nil );
+ } else if (cls == @global(ByteArray)) {
+ if (pos <= __byteArraySize(coll)) {
+ ch = __ByteArrayInstPtr(coll)->ba_element[pos-1];
+ RETURN ( __mkSmallInteger(ch) );
+ }
+ RETURN ( nil );
+ } else if (cls == @global(Array)) {
+ if (pos <= __arraySize(coll)) {
+ RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]);
+ }
+ RETURN ( nil );
+ }
+ }
}
%}.
- ((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ nil].
- ^ collection at:(position + 1 - ZeroPosition)
+ (position >= readLimit) ifTrue:[^ nil].
+ ^ collection at:(position + 1)
!
skipSeparators
@@ -847,10 +847,10 @@
!ReadStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ReadStream.st,v 1.67 2013-05-21 20:44:47 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ReadStream.st,v 1.69 2013-06-03 18:39:38 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/ReadStream.st,v 1.67 2013-05-21 20:44:47 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ReadStream.st,v 1.69 2013-06-03 18:39:38 cg Exp $'
! !