PositionableStream.st
changeset 2153 244e36cbbd9b
parent 2130 b9e7e1cf98bd
child 2154 89e96599e1e2
equal deleted inserted replaced
2152:6a42beaf7cc5 2153:244e36cbbd9b
   550 
   550 
   551 skipThroughAll:aCollection
   551 skipThroughAll:aCollection
   552     "skip for and through the sequence given by the argument, aCollection;
   552     "skip for and through the sequence given by the argument, aCollection;
   553      return nil if not found, self otherwise. 
   553      return nil if not found, self otherwise. 
   554      On a successful match, the next read will return elements after aCollection;
   554      On a successful match, the next read will return elements after aCollection;
   555      if no match was found, the receiver will be positioned at the end."
   555      if no match was found, the receiver will be positioned at the end.
       
   556      This is redefined here, to make use of positioning."
   556 
   557 
   557     |oldPos buffer l first idx|
   558     |oldPos buffer l first idx|
   558 
   559 
   559     oldPos := self position.
   560     oldPos := self position.
   560 
   561 
   561     l := aCollection size.
   562     l := aCollection size.
   562     first := aCollection at:1.
   563     first := aCollection at:1.
   563     [self atEnd] whileFalse:[
   564     [self atEnd] whileFalse:[
   564 	buffer := self next:l.
   565         buffer := self nextAvailable:l.
   565 	buffer = aCollection ifTrue:[
   566         buffer = aCollection ifTrue:[
   566 	    ^ self
   567             ^ self
   567 	].
   568         ].
   568 	idx := buffer indexOf:first startingAt:2.
   569         idx := buffer indexOf:first startingAt:2.
   569 	idx == 0 ifFalse:[
   570         idx == 0 ifFalse:[
   570 	    self position:(self position - l + idx - 1)
   571             self position:(self position - l + idx - 1)
   571 	]
   572         ]
   572     ].
   573     ].
   573     ^ nil
   574     ^ nil
   574 
   575 
   575     "
   576     "
   576      |s|
   577      |s|
   577      s := ReadStream on:'12345678901234567890'.
   578      s := ReadStream on:'12345678901234567890'.
   578      s skipThroughAll:'901'.
   579      s skipThroughAll:'901'.
   579      s upToEnd  
   580      s upToEnd  
   580     "
   581     "
   581 
   582     "
   582     "Modified: 26.6.1996 / 09:27:25 / cg"
   583      |s|
       
   584      s := ReadStream on:'12345678901234567890'.
       
   585      s skipThroughAll:'1234'.
       
   586      s upToEnd  
       
   587     "
       
   588     "
       
   589      |s|
       
   590      s := ReadStream on:'12345678901234567890'.
       
   591      s skipThroughAll:'999'.
       
   592      s atEnd  
       
   593     "
       
   594 
   583     "Created: 26.6.1996 / 09:35:35 / cg"
   595     "Created: 26.6.1996 / 09:35:35 / cg"
       
   596     "Modified: 11.1.1997 / 19:10:26 / cg"
   584 !
   597 !
   585 
   598 
   586 skipToAll:aCollection
   599 skipToAll:aCollection
   587     "skip for the sequence given by the argument, aCollection;
   600     "skip for the sequence given by the argument, aCollection;
   588      return nil if not found, self otherwise. 
   601      return nil if not found, self otherwise. 
   682 ! !
   695 ! !
   683 
   696 
   684 !PositionableStream class methodsFor:'documentation'!
   697 !PositionableStream class methodsFor:'documentation'!
   685 
   698 
   686 version
   699 version
   687     ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.51 1997-01-10 17:50:55 cg Exp $'
   700     ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.52 1997-01-11 18:16:19 cg Exp $'
   688 ! !
   701 ! !
   689 PositionableStream initialize!
   702 PositionableStream initialize!