diff -r eab134bd8b94 -r f2d1d7b2d649 PositionableStream.st --- a/PositionableStream.st Wed Mar 05 11:01:20 2014 +0100 +++ b/PositionableStream.st Wed Mar 05 11:02:58 2014 +0100 @@ -116,7 +116,6 @@ "Modified: / 13-07-2006 / 20:36:54 / cg" ! ! - !PositionableStream methodsFor:'Compatibility-Dolphin'! endChunk @@ -391,14 +390,14 @@ first := aCollection at:1. [self atEnd] whileFalse:[ buffer := self nextAvailable:len. - buffer = aCollection ifTrue:[ - ^ self - ]. buffer size == len ifTrue:[ + buffer = aCollection ifTrue:[ + ^ self + ]. "expect more input" idx := buffer indexOf:first startingAt:2. - idx == 0 ifFalse:[ - self position:(self position - len + idx - 1) + idx ~~ 0 ifTrue:[ + self skip:(idx - len - 1) ]. ]. ]. @@ -560,28 +559,30 @@ !PositionableStream methodsFor:'queries'! -endsWith:aSequenceableCollection +endsBeforePositionWith:aSequenceableCollection "answer true, if the elements in aSequenceableCollection - form the end of the stream." + are at the current end of the stream up to position." - self contentsSpecies == collection class ifTrue:[ - |sz| + |sz pos| - sz := aSequenceableCollection size. - position < sz ifTrue:[ - ^ false. - ]. - ^ collection sameContentsFrom:position+1-sz to:position as:aSequenceableCollection startingAt:1. + sz := aSequenceableCollection size. + pos := self position. + pos < sz ifTrue:[ + ^ false. ]. - ^ self contents endsWith:aSequenceableCollection + self contentsSpecies == collection class ifTrue:[ + ^ collection sameContentsFrom:pos+1-sz to:pos as:aSequenceableCollection startingAt:1. + ]. + self position:pos-sz. + ^ (self next:sz) = aSequenceableCollection. " - ('' writeStream nextPutAll:'Hello World') endsWith:'World' - ('' writeStream nextPutAll:'Hello World') endsWith:'Hello World' - ('' writeStream nextPutAll:'Hello World') endsWith:'xHello World' - ('' writeStream nextPutAll:'Hello World') endsWith:'Bla' - ('' writeStream) endsWith:'Bla' - ('' writeStream) endsWith:'' + ('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'World' + ('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'Hello World' + ('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'Hello Worldx' + ('' writeStream nextPutAll:'Hello World') endsBeforePositionWith:'Bla' + ('' writeStream) endsBeforePositionWith:'Bla' + ('' writeStream) endsBeforePositionWith:'' '' endsWith:'' " ! ! @@ -675,18 +676,18 @@ which position after the found item. We implement the method this way for the sake of ST80-compatibility." - |answerStream element last rslt| + |answerStream element last| last := aCollection last. - answerStream := WriteStream on:(self contentsSpecies new). - [self atEnd] whileFalse:[ - element := self next. + answerStream := WriteStream on:(self contentsSpecies new:100). + [(element := self nextOrNil) notNil] whileTrue:[ answerStream nextPut:element. - element == last ifTrue:[ - ((rslt := answerStream contents) endsWith:aCollection) ifTrue:[ - self position:(self position - aCollection size). - ^ rslt copyButLast:aCollection size - ] + (element = last and:[answerStream endsBeforePositionWith:aCollection]) ifTrue:[ + |backStep| + backStep := aCollection size negated. + self skip:backStep. + answerStream skip:backStep. + ^ answerStream contents ]. ]. ^ answerStream contents @@ -694,21 +695,21 @@ " |s| s := ReadStream on:'hello world'. - Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. + Transcript show:'<'; show:(s upToAll_positionBefore:'wo'); showCR:'>'. Transcript showCR:s atEnd. Transcript show:'<'; show:(s upToEnd); showCR:'>'. " " |s| s := ReadStream on:'hello world'. - Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. + Transcript show:'<'; show:(s upToAll_positionBefore:'wo'); showCR:'>'. Transcript showCR:s atEnd. - Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. + Transcript show:'<'; show:(s upToAll_positionBefore:'wo'); showCR:'>'. " " |s| s := ReadStream on:'hello world'. - Transcript show:'<'; show:(s upToAll:'xx'); showCR:'>'. + Transcript show:'<'; show:(s upToAll_positionBefore:'xx'); showCR:'>'. Transcript showCR:s atEnd. Transcript show:'<'; show:(s upToEnd); showCR:'>'. " @@ -748,11 +749,11 @@ !PositionableStream class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.165 2014-03-04 12:36:39 stefan Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.166 2014-03-05 10:02:58 stefan Exp $' ! version_CVS - ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.165 2014-03-04 12:36:39 stefan Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.166 2014-03-05 10:02:58 stefan Exp $' ! !