--- a/Stream.st Wed Mar 25 11:32:56 2009 +0100
+++ b/Stream.st Wed Mar 25 12:54:56 2009 +0100
@@ -194,6 +194,7 @@
^ ChunkSeparator
! !
+
!Stream methodsFor:'accessing'!
contents
@@ -2286,19 +2287,10 @@
and also positions behind it, but DOES include it in the returned
value."
- |answerStream element|
+ |answerStream|
answerStream := WriteStream on:(self contentsSpecies new).
- [
- element := self nextOrNil.
- ((element isNil and:[self atEnd]) or:[element = anObject]) ifTrue:[
- true
- ] ifFalse:[
- answerStream nextPut:element.
- false
- ].
- ] whileFalse.
-
+ self upTo:anObject into:answerStream.
^ answerStream contents
"
@@ -2339,6 +2331,29 @@
"Modified: / 15.1.1998 / 23:28:47 / stefan"
!
+upTo:anObject into:aStream
+ "read a collection of all objects up-to anObject and append these
+ elements to aStream, but excluding anObject.
+ The next read operation will return the element after anObject.
+ (i.e. anObject is considered a separator, which is skipped)
+ Similar to #through:, but the matching object is not included in the returned collection.
+ If anObject is not encountered, all elements up to the end are read and returned.
+ Compare this with #through: which also reads up to some object
+ and also positions behind it, but DOES include it in the returned value."
+
+ |element|
+
+ [
+ element := self nextOrNil.
+ ((element isNil and:[self atEnd]) or:[element = anObject]) ifTrue:[
+ true
+ ] ifFalse:[
+ aStream nextPut:element.
+ false
+ ].
+ ] whileFalse.
+!
+
upToAllExcluding:aCollection
"read a collection of all objects up-to a element which is contained in
aCollection and return these elements, but excluding the matching one.
@@ -2911,7 +2926,7 @@
!Stream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.163 2009-03-18 13:46:52 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.164 2009-03-25 11:54:56 cg Exp $'
! !
Stream initialize!