fixed: skipThrough dod not position atEnd if the element was not found.
also: return value is receiver if ok - not the element.
--- a/ReadStream.st Fri Sep 07 21:26:52 2001 +0200
+++ b/ReadStream.st Fri Sep 07 21:27:52 2001 +0200
@@ -622,8 +622,9 @@
!
skipThrough:anObject
- "skip all objects up-to and including anObject, return anObject on success,
- nil if end-of-stream is reached before.
+ "skip all objects up-to and including anObject.
+ Return the receiver if skip was successful,
+ otherwise (i.e. if not found) return nil and leave the stream positioned at the end.
On success, the next read operation will return the element after anObject.
- reimplemented for speed on String-Streams for faster scanning"
@@ -637,36 +638,36 @@
if (__isString(coll)
&& __isCharacter(anObject)
&& __bothSmallInteger(p, l)) {
- REGISTER unsigned char *chars;
- REGISTER int pos, limit;
- unsigned ch;
- int sz;
+ REGISTER unsigned char *chars;
+ REGISTER int pos, limit;
+ unsigned ch;
+ int sz;
- pos = __intVal(p);
- if (pos <= 0) {
- RETURN ( nil );
- }
+ pos = __intVal(p);
+ if (pos <= 0) {
+ RETURN ( nil );
+ }
- limit = __intVal(l);
- sz = __stringSize(coll);
- if (limit > sz) limit = sz;
+ limit = __intVal(l);
+ sz = __stringSize(coll);
+ if (limit > sz) limit = sz;
- chars = (unsigned char *)(__stringVal(coll) + pos - 1);
- ch = __intVal(_characterVal(anObject)) & 0xFF;
- while (pos < limit) {
- if (*chars == ch) {
- ch = *++chars;
- pos++;
- __INST(position) = __MKSMALLINT(pos);
- RETURN ( anObject );
- }
- chars++;
- pos++;
- }
- RETURN ( nil );
+ chars = (unsigned char *)(__stringVal(coll) + pos - 1);
+ ch = __intVal(_characterVal(anObject)) & 0xFF;
+ while (pos < limit) {
+ if (*chars == ch) {
+ ch = *++chars;
+ pos++;
+ __INST(position) = __MKSMALLINT(pos);
+ RETURN ( self );
+ }
+ chars++;
+ pos++;
+ }
+ __INST(position) = __MKSMALLINT(pos+1);
+ RETURN ( nil );
}
-%}
-.
+%}.
^ super skipThrough:anObject
! !
@@ -681,5 +682,5 @@
!ReadStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ReadStream.st,v 1.42 2001-02-14 09:24:40 frank Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ReadStream.st,v 1.43 2001-09-07 19:27:52 cg Exp $'
! !