--- a/PositionableStream.st Sat Mar 01 23:09:47 2014 +0100
+++ b/PositionableStream.st Sat Mar 01 23:21:38 2014 +0100
@@ -229,6 +229,34 @@
self position:(self position - 1)
!
+match: subCollection
+ "Set the access position of the receiver to be past the next occurrence of the subCollection.
+ Answer whether subCollection is found.
+ No wildcards, and case does matter."
+
+ | pattern startMatch |
+
+ pattern := ReadStream on: subCollection.
+ startMatch := nil.
+ [pattern atEnd] whileFalse: [
+ self atEnd ifTrue: [^ false].
+ (self next) = (pattern next)
+ ifTrue: [pattern position = 1 ifTrue: [startMatch := self position]]
+ ifFalse: [
+ pattern position: 0.
+ startMatch ifNotNil: [
+ self position: startMatch.
+ startMatch := nil
+ ]
+ ]
+ ].
+ ^ true
+
+ "
+ 'abc def ghi' readStream match:'def'; upToEnd
+ "
+!
+
position
"return the read position (0-based)"
@@ -645,11 +673,11 @@
!PositionableStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.162 2014-03-01 22:09:26 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.163 2014-03-01 22:21:38 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.162 2014-03-01 22:09:26 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.163 2014-03-01 22:21:38 cg Exp $'
! !