split:

stephane ducasse stephane.ducasse at gmail.com
Sat Sep 16 07:41:18 UTC 2006


keep trying to find a fix point with a nice solution and tests ;)

Stef

On 16 sept. 06, at 03:20, Keith Hodges wrote:

> The question as to whether split: should work with Strings or  
> Regex's is something that should be handled with a double dispatch.  
> If you feed it a String it should use a string if you feed it a  
> Regex then it will use a Regex.
>
> eg := 'Now is the time for all good men to come to the aid of the   
> party'.
>
> eg splitOnEvery: 'the'
> eg splitOnEvery: ( '+[\s]' asRegex ).
> eg splitOnEvery: $e.
> #(1 2 3 4 5 6 7 8 9) splitOnEvery: #(4).
> #(1 2 3 4 5 6 7 8 9) splitOnEvery: #(4 5 6).
> #(1 2 3 4 5 6 7 8 9) splitOnEvery: [ :n | n isPrimeNumber ]
>
> SequencableCollection>>splitOnEvery: aSpliter
> ^aSpliter  splitUp:  self
> aRegex>>splitUp: aString.
> ...regex implementation
> aString>>splitUp: aString.
> ...string implementation
> aCharacter>>splitUp: aString.
> ...character implementation
> aSequencableCollection>>splitUp: aSequencableCollection
> ... generic collection implementation.
> aMonadicBlock>>splitOnEvery: thing
> ^ thing splitUsing: aBlock.
>
> more ideas
>
> Keith
>
>
>
>
> >In my viewer I saw two spaces at "the  party".
> >So what should happen for #split: on a single space.
> >Should there be an extra item with value nil or an
> >empty string? Or should there be no extra item?
>
> I think that the convention is to return an empty string. -> # 
> ('the' '' 'party')
>
>
> 	
> 	
> 		
> ___________________________________________________________ Yahoo!  
> Messenger - NEW crystal clear PC to PC calling worldwide with  
> voicemail http://uk.messenger.yahoo.com
>




More information about the Squeak-dev mailing list