PeekableStream.st
changeset 2419 13804903a785
parent 2060 4f93a792ba9d
child 2421 0b8966d99a87
--- a/PeekableStream.st	Wed Feb 26 00:10:03 1997 +0100
+++ b/PeekableStream.st	Wed Feb 26 12:10:04 1997 +0100
@@ -187,6 +187,30 @@
     "
 !
 
+upToMatching:aBlock
+    "Return the next elements up to but not including the next element
+     for which aBlock returns true.
+     The next read will return that matching element."
+
+    |answerStream element|
+
+    answerStream := WriteStream on:(self contentsSpecies new).
+    [self atEnd] whileFalse: [
+        element := self peek.
+        (aBlock value:element) ifTrue: [^ answerStream contents].
+        answerStream nextPut:element.
+        self next.
+    ].
+    ^ answerStream contents
+
+    "
+     'hello world' readStream upToMatching:[:c | c isSeparator].
+    "
+
+    "Modified: 4.1.1997 / 23:38:05 / cg"
+    "Created: 26.2.1997 / 12:09:38 / cg"
+!
+
 upToSeparator
     "Return the next elements up to but not including the next separator.
      The elements are supposed to understand #isSeparator."
@@ -212,5 +236,5 @@
 !PeekableStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/PeekableStream.st,v 1.16 1997-01-04 22:38:16 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/PeekableStream.st,v 1.17 1997-02-26 11:10:04 cg Exp $'
 ! !