--- a/ReadStream.st Fri Jul 16 11:39:45 1993 +0200
+++ b/ReadStream.st Mon Oct 04 11:32:33 1993 +0100
@@ -32,14 +32,19 @@
peek
"return the next element; do NOT advance read pointer.
- - reimplemented for speed on String-Streams"
+ return nil, if there is no next element.
+ - reimplemented for speed on String/ByteArray-Streams"
%{ /* NOCONTEXT */
REGISTER int pos;
unsigned ch;
+ OBJ coll;
+ extern OBJ ByteArray;
- if (_isString(_INST(collection))
+ coll = _INST(collection);
+ if (_isNonNilObject(coll)
+ && ((_qClass(coll) == String) || (_qClass(coll) == ByteArray))
&& _isSmallInteger(_INST(position))
&& _isSmallInteger(_INST(readLimit))) {
@@ -47,10 +52,18 @@
if (pos > _intVal(_INST(readLimit))) {
RETURN ( nil );
}
- if ((pos > 0)
- && (pos < _qSize(_INST(collection)) - OHDR_SIZE)) {
- ch = _stringVal(_INST(collection))[pos-1];
- RETURN ( _MKCHARACTER(ch) );
+ if (pos > 0) {
+ if (_qClass(coll) == String) {
+ if (pos < (_qSize(coll) - OHDR_SIZE)) {
+ ch = _stringVal(coll)[pos-1];
+ RETURN ( _MKCHARACTER(ch) );
+ }
+ } else {
+ if (pos <= (_qSize(coll) - OHDR_SIZE)) {
+ ch = _ByteArrayInstPtr(coll)->ba_element[pos-1];
+ RETURN ( _MKSMALLINT(ch) );
+ }
+ }
}
}
%}
@@ -61,7 +74,8 @@
next
"return the next element; advance read pointer.
- - reimplemented for speed on String-Streams"
+ return nil, if there is no next element.
+ - reimplemented for speed on String/ByteArray-Streams"
|ret|
@@ -69,8 +83,12 @@
REGISTER int pos;
unsigned ch;
+ OBJ coll;
+ extern OBJ ByteArray;
- if (_isString(_INST(collection))
+ coll = _INST(collection);
+ if (_isNonNilObject(coll)
+ && ((_qClass(coll) == String) || (_qClass(coll) == ByteArray))
&& _isSmallInteger(_INST(position))
&& _isSmallInteger(_INST(readLimit))) {
@@ -78,11 +96,20 @@
if (pos > _intVal(_INST(readLimit))) {
RETURN ( nil );
}
- if ((pos > 0)
- && (pos < _qSize(_INST(collection)) - OHDR_SIZE)) {
- ch = _stringVal(_INST(collection))[pos-1];
- _INST(position) = _MKSMALLINT(pos + 1);
- RETURN ( _MKCHARACTER(ch) );
+ if (pos > 0) {
+ if (_qClass(coll) == String) {
+ if (pos < (_qSize(coll) - OHDR_SIZE)) {
+ _INST(position) = _MKSMALLINT(pos + 1);
+ ch = _stringVal(coll)[pos-1];
+ RETURN ( _MKCHARACTER(ch) );
+ }
+ } else {
+ if (pos <= (_qSize(coll) - OHDR_SIZE)) {
+ _INST(position) = _MKSMALLINT(pos + 1);
+ ch = _ByteArrayInstPtr(coll)->ba_element[pos-1];
+ RETURN ( _MKSMALLINT(ch) );
+ }
+ }
}
}
%}
@@ -93,10 +120,24 @@
^ ret
!
+next:count
+ "return the next count elements of the stream as a collection.
+ Redefined, to return a collection of the streamed-upon collections
+ species."
+
+ |coll|
+
+ coll := (collection species) new:count.
+ 1 to:count do: [:index |
+ coll at:index put:(self next)
+ ].
+ ^ coll
+!
+
nextPeek
"advance read pointer return the peek element.
this is equivalent to (self next; peek).
- - reimplemented for speed on String-Streams"
+ - reimplemented for speed on String-Streams for faster scanning"
%{ /* NOCONTEXT */
@@ -131,7 +172,7 @@
nextDecimalInteger
"read the next integer in radix 10. dont skip whitespace.
- - reimplemented for speed on String-Streams"
+ - reimplemented for speed on String-Streams for faster scanning"
|value|
%{
@@ -177,7 +218,7 @@
nextWord
"read the next word (i.e. up to non letter-or-digit).
return a string containing those characters.
- - reimplemented for speed on String-Streams"
+ - reimplemented for speed on String-Streams for faster scanning"
%{
/* speedup, if collection is a string */
@@ -238,7 +279,7 @@
nextSymbol
"read the next selector-symbol (i.e. up to non letter-or-digit).
return a string containing those characters.
- - reimplemented for speed on String-Streams"
+ - reimplemented for speed on String-Streams for faster scanning"
%{
int pos, limit, sz;
int len;
@@ -284,10 +325,11 @@
^ super nextSymbol
!
-skipFor:anObject
- "skip all objects up-to and including anObject;
- return the element after anObject.
- - reimplemented for speed on String-Streams"
+nextMatchFor:anObject
+ "skip all objects up-to and including anObject, return anObject on success,
+ nil if end-of-file is reached before. The next read operation will return
+ the element after anObject.
+ - reimplemented for speed on String-Streams for faster scanning"
%{ /* NOCONTEXT */
@@ -297,7 +339,7 @@
&& _isSmallInteger(_INST(readLimit))) {
REGISTER unsigned char *chars;
REGISTER int pos, limit;
- unsigned ch;
+ unsigned ch;
pos = _intVal(_INST(position));
if (pos <= 0) {
@@ -315,23 +357,22 @@
ch = *++chars;
pos++;
_INST(position) = _MKSMALLINT(pos);
- RETURN ( _MKCHARACTER(ch) );
+ RETURN ( anObject );
}
chars++;
pos++;
}
- _INST(position) = _MKSMALLINT(pos);
RETURN ( nil );
}
%}
.
- ^ super skipFor:anObject
+ ^ super nextMatchFor:anObject
!
skipSeparators
"skip all whitespace; next will return next non-white-space element.
- - reimplemented for speed on String-Streams"
+ - reimplemented for speed on String-Streams for faster scanning"
%{ /* NOCONTEXT */