Andreas Raab uploaded a new version of Collections to project The Trunk: http://source.squeak.org/trunk/Collections-ar.323.mcz
==================== Summary ====================
Name: Collections-ar.323 Author: ar Time: 27 February 2010, 10:32:57.735 pm UUID: 66aa4c95-8687-8d49-a5cc-3eebe5ad7d2e Ancestors: Collections-ar.322
Add SequenceableCollection>>splitBy:[do:] to implement common split operation, i.e.,
'Hello<p>World' splitBy: '<p>' => #('Hello' 'World'). 'Hello<p>World' splitBy: '<p>' do:[:token| ... ].
=============== Diff against Collections-ar.322 ===============
Item was added: + ----- Method: SequenceableCollection>>splitBy:do: (in category 'enumerating') ----- + splitBy: aCollection do: aBlock + "Split the receiver by aCollection. Evaluate aBlock with the parts. + + This method works similarly to findTokens: but + a) takes a collection argument (i.e., 'hello<p>world<p>' splitBy: '<p>') + b) is 'strict' in its splitting, for example: + 'a///b' findTokens: '/' ==> #('a' 'b') + 'a///b' splitBy: '/' ==> #('a' '' '' 'b') + " + + | lastIndex nextIndex | + lastIndex := 1. + [nextIndex := self indexOfSubCollection: aCollection startingAt: lastIndex. + nextIndex = 0] whileFalse:[ + aBlock value: (self copyFrom: lastIndex to: nextIndex-1). + lastIndex := nextIndex+ aCollection size. + ]. + aBlock value: (self copyFrom: lastIndex to: self size). + !
Item was added: + ----- Method: SequenceableCollection>>splitBy: (in category 'enumerating') ----- + splitBy: aCollection + "Answer the receiver, split by aCollection. + + This method works similarly to findTokens: but + a) takes a collection argument (i.e., 'hello<p>world<p>' splitBy: '<p>') + b) is 'strict' in its splitting, for example: + 'a///b' findTokens: '/' ==> #('a' 'b') + 'a///b' splitBy: '/' ==> #('a' '' '' 'b') + " + + ^Array streamContents:[:stream| + self splitBy: aCollection do:[:each| stream nextPut: each]. + ]. + !
squeak-dev@lists.squeakfoundation.org