[ENH] Minor Stream refactoring

Stephan Rudlof sr at evolgo.de
Wed May 9 17:35:32 UTC 2001


Richard,

please read
	http://minnow.cc.gatech.edu/squeak/398
(link has worked for me just now) for a description of how to post an
enhancement or other code here.

Greetings,

Stephan

"Richard A. O'Keefe" wrote:
> 
> I had occasion to define a new Stream class recently.  I found that several
> of the operations I wanted, that made perfect sense for my class and did
> not depend on anything that wasn't already part of the Stream protocol,
> were in the "wrong" classes.  This change set promotes some of the methods
> from PositionableStream and WriteStream to Stream.  It was written in
> Squeak 2.7, but has also been checked in Squeak 3.0.1.
> 
> 'From Squeak2.7 of 5 January 2000 [latest update: #1782] on 9 May 2001 at 12:23:26 pm'!
> 
> !Stream methodsFor: 'accessing' stamp: 'raok 5/3/2001 18:13'!
> next: anInteger putAll: aCollection startingAt: startIndex
>         "Store the next anInteger elements from the given collection."
>         0 to: anInteger-1 do: [:i|
>                 self nextPut: (aCollection at: startIndex + i).
>         ].
>         ^aCollection! !
> 
> !Stream methodsFor: 'character writing' stamp: 'raok 5/3/2001 18:35'!
> cr
>         "Append a return character to the receiver."
> 
>         self nextPut: Character cr! !
> 
> !Stream methodsFor: 'character writing' stamp: 'raok 5/3/2001 18:35'!
> crtab
>         "Append a return character, followed by a single tab character, to the
>         receiver."
> 
>         self nextPut: Character cr.
>         self nextPut: Character tab! !
> 
> !Stream methodsFor: 'character writing' stamp: 'raok 5/3/2001 18:36'!
> crtab: anInteger
>         "Append a return character, followed by anInteger tab characters, to the
>         receiver."
> 
>         self nextPut: Character cr.
>         anInteger timesRepeat: [self nextPut: Character tab]! !
> 
> !Stream methodsFor: 'character writing' stamp: 'raok 5/3/2001 18:36'!
> space
>         "Append a space character to the receiver."
> 
>         self nextPut: Character space! !
> 
> !Stream methodsFor: 'character writing' stamp: 'raok 5/3/2001 18:37'!
> space: anInteger
>         "Append anInteger space characters to the receiver."
> 
>         anInteger timesRepeat: [self nextPut: Character space]! !
> 
> !Stream methodsFor: 'character writing' stamp: 'raok 5/3/2001 18:37'!
> tab
>         "Append a tab character to the receiver."
> 
>         self nextPut: Character tab! !
> 
> !Stream methodsFor: 'positioning' stamp: 'raok 5/8/2001 18:04'!
> skip: anInteger
>         "Skip over the next anInteger elements, not trying to read past end of stream.
>          Subclasses that can implement this more efficiently should do so."
>         anInteger timesRepeat: [self atEnd ifTrue: [^self]. self next]
> ! !
> 
> !Stream methodsFor: 'positioning' stamp: 'raok 5/8/2001 18:07'!
> skipLine
>         "Skip the rest of the line, if there is any."
>         ^self skipTo: Character cr
> ! !
> 
> !Stream methodsFor: 'positioning' stamp: 'raok 5/8/2001 18:06'!
> skipTo: anObject
>         "Skip elements until either the next occurrence of anObject has just been reached
>          or the end of the stream is found.  Answer whether anObject was found.
>          This method is misnamed because it doesn't skip TO anObject but PAST it."
> 
>         [self atEnd] whileFalse: [self next = anObject ifTrue: [^true]].
>         ^false
> ! !
> 
> PositionableStream removeSelector: #skipTo:!
> PositionableStream removeSelector: #next:putAll:startingAt:!
> WriteStream removeSelector: #cr!
> WriteStream removeSelector: #crtab!
> WriteStream removeSelector: #tab!
> WriteStream removeSelector: #crtab:!
> WriteStream removeSelector: #space!

-- 
Stephan Rudlof (sr at evolgo.de)
   "Genius doesn't work on an assembly line basis.
    You can't simply say, 'Today I will be brilliant.'"
    -- Kirk, "The Ultimate Computer", stardate 4731.3





More information about the Squeak-dev mailing list