'From Squeak3.0 of 4 February 2001 [latest update: #3545] on 21 May 2001 at 1:03:57 pm'! Stream subclass: #BufferStream instanceVariableNames: 'buffer startPos endPos ' classVariableNames: '' poolDictionaries: '' category: 'Kom-kernel'! !BufferStream commentStamp: '' prior: 0! Kom48 (Comanche beta 4.8) bolot 4/2/2001 18:43 BufferStream Comment in Com46: - is-a ReadWriteStream on a String - like a queue removeNext:/nextPutAll: protocol! !BufferStream methodsFor: 'initialize-release' stamp: 'bolot 12/16/2000 01:42'! on: aString buffer _ aString. startPos _ 1. endPos _ buffer size! ! !BufferStream methodsFor: 'initialize-release' stamp: 'rew 5/19/2001 13:08'! reset "hack" self on: (buffer ifNil: [''] ifNotNil: [buffer class new: 0])! ! !BufferStream methodsFor: 'accessing' stamp: 'bolot 12/16/2000 01:36'! contents "return contents, non-destructive" ^buffer copyFrom: startPos to: endPos! ! !BufferStream methodsFor: 'accessing' stamp: 'bolot 12/19/2000 00:21'! match: aString self size < aString size ifTrue: [^false]. (self next: aString size) = aString ifTrue: [^true] ifFalse: [self on: aString, self upToEnd]. ^false! ! !BufferStream methodsFor: 'accessing' stamp: 'bolot 12/16/2000 01:37'! next "return the next character" "consume it" ^buffer at: (startPos _ startPos + 1) - 1! ! !BufferStream methodsFor: 'accessing' stamp: 'bolot 12/16/2000 01:37'! next: anInteger "return next anInteger characters" "consumes them" ^buffer copyFrom: startPos to: (startPos _ startPos + anInteger) - 1! ! !BufferStream methodsFor: 'accessing' stamp: 'bolot 12/16/2000 01:38'! nextPutAll: aString buffer _ (buffer copyFrom: startPos to: endPos), aString. startPos _ 1. endPos _ buffer size! ! !BufferStream methodsFor: 'accessing' stamp: 'bolot 12/16/2000 01:43'! size ^endPos - startPos + 1! ! !BufferStream methodsFor: 'accessing' stamp: 'rew 5/20/2001 13:36'! upTo: aChar "return String up to aChar, but not including" "consumes the returned string" | i | i _ buffer indexOf: aChar startingAt: startPos ifAbsent: [0]. (i <= 0 or: [i > endPos]) ifTrue: [^self upToEnd]. ^self next: (i-startPos)! ! !BufferStream methodsFor: 'accessing' stamp: 'rew 5/20/2001 13:50'! upToAll: aString "return a string before the occurence of aString, if any" "consume it" | i | i _ buffer indexOfSubCollection: aString startingAt: startPos ifAbsent: [0]. (i <= 0 or: [i > endPos]) ifTrue: [^self upToEnd]. ^self next: (i-startPos)! ! !BufferStream methodsFor: 'accessing' stamp: 'bolot 12/16/2000 01:38'! upToEnd "return buffer contents, consume all my buffer" | string | string _ self contents. self reset. ^string! ! !BufferStream methodsFor: 'testing' stamp: 'rew 5/20/2001 13:17'! includes: aChar "answer whether buffer includes aChar within bounds" | tmp | tmp _ buffer indexOf: aChar startingAt: startPos ifAbsent: [0]. ^(tmp >= startPos) and: [tmp <= endPos]! ! !BufferStream methodsFor: 'testing' stamp: 'rew 5/19/2001 13:04'! includesAll: aString "answer whether the buffer contains aString" | tmp | tmp _ buffer indexOfSubCollection: aString startingAt: startPos. ^(tmp >= startPos) and: [tmp <= endPos]! ! !BufferStream methodsFor: 'testing' stamp: 'bolot 12/16/2000 01:37'! isEmpty ^self size <= 0! ! !BufferStream methodsFor: 'printing' stamp: 'bolot 12/16/2000 01:41'! printOn: aStream super printOn: aStream. aStream nextPutAll: '(', self size asString, ')'! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! BufferStream class instanceVariableNames: ''! !BufferStream class methodsFor: 'instance creation' stamp: 'bolot 12/16/2000 01:44'! on: aString ^self basicNew on: aString! !