WriteStream.st
changeset 21132 48e561eba578
parent 20432 e7056f247cd9
child 21242 19fabe339f8b
child 21814 3694bdb6c97b
equal deleted inserted replaced
21131:d1acc3e2e4a1 21132:48e561eba578
     1 "{ Encoding: utf8 }"
       
     2 
       
     3 "
     1 "
     4  COPYRIGHT (c) 1989 by Claus Gittinger
     2  COPYRIGHT (c) 1989 by Claus Gittinger
     5 	      All Rights Reserved
     3 	      All Rights Reserved
     6 
     4 
     7  This software is furnished under a license and may be used
     5  This software is furnished under a license and may be used
   253     super on:aCollection from:start to:last.
   251     super on:aCollection from:start to:last.
   254     writeLimit := last.
   252     writeLimit := last.
   255 ! !
   253 ! !
   256 
   254 
   257 !WriteStream methodsFor:'queries'!
   255 !WriteStream methodsFor:'queries'!
       
   256 
       
   257 endsWith:aCollection
       
   258     "Answer true, if the contents of the stream ends with aCollection.
       
   259      Speedup for upToAll:, throughAll etc."
       
   260 
       
   261     |sz start "{ Class: SmallInteger }"|
       
   262 
       
   263     collection isNil ifTrue:[
       
   264         "only supported for internal streams"
       
   265         self shouldNotImplement.
       
   266     ].
       
   267 
       
   268     sz := aCollection size.
       
   269     start := position + 1 - sz.
       
   270     ^ start > 0 and:[(collection copyFrom:position+1-sz to:position) endsWith:aCollection].
       
   271 
       
   272     "
       
   273         (WriteStream with:'abcdef') endsWith:'def'
       
   274         (WriteStream with:'def') endsWith:'def'
       
   275         (WriteStream with:'abc') endsWith:'def'
       
   276         (WriteStream with:'ef') endsWith:'def'
       
   277 false    "
       
   278 !
   258 
   279 
   259 size
   280 size
   260     "return the current size"
   281     "return the current size"
   261 
   282 
   262     ^ position
   283     ^ position