[squeak-dev] The Trunk: Collections-nice.241.mcz

commits at source.squeak.org commits at source.squeak.org
Mon Dec 7 07:54:10 UTC 2009


Nicolas Cellier uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-nice.241.mcz

==================== Summary ====================

Name: Collections-nice.241
Author: nice
Time: 7 December 2009, 8:54:02 am
UUID: 1f4db188-b57c-7e49-b65c-2121cd0e9d46
Ancestors: Collections-ar.240

Provide a universal #nextLine relying on #upToAnyOf:do:
Subclass might want to override #upToAnyOf:do: for speed

=============== Diff against Collections-ar.240 ===============

Item was changed:
  ----- Method: PositionableStream>>nextLine (in category 'accessing') -----
  nextLine
+ 	"Answer next line (may be empty) without line end delimiters, or nil if at end.
+ 	Let the stream positioned after the line delimiter(s).
- 	"Answer next line (may be empty), or nil if at end.
  	Handle a zoo of line delimiters CR, LF, or CR-LF pair"
  
- 	| newStream element crlf |
  	self atEnd ifTrue: [^nil].
+ 	^self upToAnyOf: CharacterSet crlf do: [:char | char = Character cr ifTrue: [self peekFor: Character lf]]!
- 	crlf := CharacterSet crlf.
- 	newStream := WriteStream on: (self collectionSpecies new: 100).
- 	[self atEnd ifTrue: [^newStream contents].
- 	crlf includes: (element := self next)]
- 		whileFalse: [newStream nextPut: element].
- 	element = Character cr ifTrue: [self peekFor: Character lf]. "handle an eventual CR LF pair"
- 	^newStream contents!

Item was added:
+ ----- Method: PositionableStream>>upToAnyOf:do: (in category 'accessing') -----
+ upToAnyOf: subcollection do: aBlock
+ 	"Answer a subcollection from the current access position to the occurrence (if any, but not inclusive) of any object in the collection.
+ 	Evaluate aBlock with this occurence as argument.
+ 	If no matching object is found, don't evaluate aBlock and answer the entire rest of the receiver."
+ 	
+ 	^self collectionSpecies new: 1000 streamContents: [ :stream |
+ 		| ch |
+ 		[ self atEnd or: [ (subcollection includes: (ch := self next)) and: [aBlock value: ch. true] ] ] 
+ 			whileFalse: [ stream nextPut: ch ] ]!

Item was changed:
  ----- Method: PositionableStream>>upToAnyOf: (in category 'accessing') -----
  upToAnyOf: aCollection 
  	"Answer a subcollection from the current access position to the 
  	occurrence (if any, but not inclusive) of any object in the collection. If 
  	no matching object is found, answer the entire rest of the receiver."
+ 	^self upToAnyOf: aCollection do: [:matchingObject | ]!
- 	| newStream element |
- 	newStream := WriteStream on: (self collectionSpecies new: 100).
- 	[self atEnd or: [aCollection includes: (element := self next)]]
- 		whileFalse: [newStream nextPut: element].
- 	^newStream contents!




More information about the Squeak-dev mailing list