PositionableStream.st
changeset 16188 4df8b9b15db4
parent 16186 dae8e43ccc46
child 16189 d7b9978c07bb
equal deleted inserted replaced
16187:e0147ce76df5 16188:4df8b9b15db4
   225 
   225 
   226 backStep
   226 backStep
   227     "move backward read position by one"
   227     "move backward read position by one"
   228 
   228 
   229     self position:(self position - 1)
   229     self position:(self position - 1)
       
   230 !
       
   231 
       
   232 match: subCollection
       
   233     "Set the access position of the receiver to be past the next occurrence of the subCollection. 
       
   234      Answer whether subCollection is found.  
       
   235      No wildcards, and case does matter."
       
   236 
       
   237     | pattern startMatch |
       
   238 
       
   239     pattern := ReadStream on: subCollection.
       
   240     startMatch := nil.
       
   241     [pattern atEnd] whileFalse: [
       
   242         self atEnd ifTrue: [^ false].
       
   243         (self next) = (pattern next) 
       
   244             ifTrue: [pattern position = 1 ifTrue: [startMatch := self position]]
       
   245             ifFalse: [
       
   246                 pattern position: 0.
       
   247                 startMatch ifNotNil: [
       
   248                     self position: startMatch.
       
   249                     startMatch := nil
       
   250                 ]
       
   251             ]
       
   252     ].
       
   253     ^ true
       
   254 
       
   255     "
       
   256      'abc def ghi' readStream match:'def'; upToEnd
       
   257     "
   230 !
   258 !
   231 
   259 
   232 position
   260 position
   233     "return the read position (0-based)"
   261     "return the read position (0-based)"
   234 
   262 
   643 ! !
   671 ! !
   644 
   672 
   645 !PositionableStream class methodsFor:'documentation'!
   673 !PositionableStream class methodsFor:'documentation'!
   646 
   674 
   647 version
   675 version
   648     ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.162 2014-03-01 22:09:26 cg Exp $'
   676     ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.163 2014-03-01 22:21:38 cg Exp $'
   649 !
   677 !
   650 
   678 
   651 version_CVS
   679 version_CVS
   652     ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.162 2014-03-01 22:09:26 cg Exp $'
   680     ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.163 2014-03-01 22:21:38 cg Exp $'
   653 ! !
   681 ! !
   654 
   682 
   655 
   683 
   656 PositionableStream initialize!
   684 PositionableStream initialize!