PosStream.st
changeset 2 6526dde5f3ac
parent 1 a27a279701f8
child 3 24d81bf47225
equal deleted inserted replaced
1:a27a279701f8 2:6526dde5f3ac
   127     ].
   127     ].
   128     ^ newColl
   128     ^ newColl
   129 
   129 
   130     "(ReadStream on:'1234567890') upTo:$5"
   130     "(ReadStream on:'1234567890') upTo:$5"
   131     "(ReadStream on:'123456') upTo:$7"
   131     "(ReadStream on:'123456') upTo:$7"
       
   132 !
       
   133 
       
   134 upToEnd
       
   135     "return a collection of the elements up-to the end
       
   136      Return nil if the stream-end is reached before."
       
   137 
       
   138     |newColl e|
       
   139 
       
   140     newColl := collection species new.
       
   141     [self atEnd] whileFalse:[
       
   142         newColl := newColl copyWith:(self next).
       
   143     ].
       
   144     ^ newColl
       
   145 
       
   146     "(ReadStream on:'1234567890') upToEnd"
       
   147     "((ReadStream on:'123456') next; next) upToEnd"
       
   148 !
       
   149 
       
   150 upToSeparator
       
   151     "Return the next elements up to but not including the next separator."
       
   152 
       
   153     |stream ch|
       
   154 
       
   155     stream := WriteStream on: (collection species new).
       
   156     [(ch := self peek) == nil] whileFalse:[
       
   157         ch isSeparator ifTrue: [
       
   158             ^ stream contents
       
   159         ] ifFalse: [
       
   160             self skip: 1.
       
   161             stream nextPut: ch
       
   162         ]
       
   163     ].
       
   164     ^ stream contents
   132 ! !
   165 ! !
   133 
   166 
   134 !PositionableStream methodsFor:'testing'!
   167 !PositionableStream methodsFor:'testing'!
   135 
   168 
   136 atEnd
   169 atEnd