--- a/Stream.st Thu Nov 12 17:56:46 2009 +0100
+++ b/Stream.st Sun Nov 15 10:55:42 2009 +0100
@@ -194,6 +194,7 @@
^ ChunkSeparator
! !
+
!Stream methodsFor:'accessing'!
contents
@@ -2442,17 +2443,13 @@
and also positions behind it, but DOES include it in the returned
value."
- |answerStream element|
-
- answerStream := WriteStream on:(self contentsSpecies new).
- [self atEnd] whileFalse:[
- element := self next.
- (aCollectionOfObjects includes:element) ifTrue: [
- ^ answerStream contents
- ].
- answerStream nextPut:element.
+ |result|
+
+ result := self upToBeforeAny:aCollectionOfObjects.
+ self atEnd ifFalse:[
+ self next.
].
- ^ answerStream contents
+ ^ result
"
|s|
@@ -2467,6 +2464,43 @@
"Modified: / 11.1.1998 / 15:19:18 / cg"
!
+upToBeforeAny:aCollectionOfObjects
+ "read a collection of all objects up-to a element which is contained in
+ aCollectionOfObjects and return these elements, but excluding the matching one.
+ The next read operation will return the matching element.
+ If no such element is encountered, all elements up to the end are read
+ and returned.
+ This returns the exact same as upToAny: would, but leaves the streams position so that
+ the next read returns the matching delimiter instead of skipping it.
+ Caveat: this is the one which should have been called upTo: in the first place;
+ however, it seems now too late for a change."
+
+ |answerStream element|
+
+ answerStream := WriteStream on:(self contentsSpecies new).
+ [self atEnd] whileFalse:[
+ element := self peek.
+ (aCollectionOfObjects includes:element) ifTrue: [
+ ^ answerStream contents
+ ].
+ answerStream nextPut:element.
+ self next.
+ ].
+ ^ answerStream contents
+
+ "
+ |s|
+ s := ReadStream on:'hello world'.
+ Transcript showCR:(s upToBeforeAny:(Array with:Character space)).
+ Transcript showCR:(s upToEnd)
+
+ 'Make.proto' asFilename readStream upToBeforeAny:($A to:$Z)
+ "
+
+ "Created: / 30.8.1997 / 03:02:05 / cg"
+ "Modified: / 11.1.1998 / 15:19:18 / cg"
+!
+
upToEnd
"return a collection of the elements up-to the end.
Return an empty collection, if the stream-end is already at the end."
@@ -3093,11 +3127,11 @@
!Stream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.183 2009-11-03 14:01:35 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.184 2009-11-15 09:55:42 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.183 2009-11-03 14:01:35 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.184 2009-11-15 09:55:42 cg Exp $'
! !
Stream initialize!