Mantis - Squeak
Viewing Issue Advanced Details
4874 Collections feature N/A 09-11-06 15:23 10-03-09 19:33
assigned 3.9  
none 3.11  
0004874: Need split and join for text manipulation tasks
Perl, Python and Ruby all support split and join for strings. Split will split a string on each match of a regex into a list of substrings, and join will join a list of strings into a single string given a separator.
As far as I can tell there is no easy way to simulate either split or join with existing Squeak methods.
I propose to add String>>split: aRegexString (which should call RxMatcher>>split: aString). I also propose adding SequenceableCollection>>join: anOrderedCollection (which is the obvious generalization of String>>join: aString). I also propose to include the VB-Regex categories in the standard image (which is why I propose this here rather than in Squeak Packages). To see a version with tests, look at: [^]
 Join-kph.1.mcz [^] (1,245 bytes) 10-10-06 19:15
 Join-kph.2.mcz [^] (2,822 bytes) 10-19-06 14:55
 Join.1.cs [^] (13,289 bytes) 10-19-06 15:25
 Join.2.cs [^] (7,920 bytes) 10-19-06 18:31
 Join.3.cs [^] (8,168 bytes) 10-19-06 18:43
 Join.4.cs [^] (5,493 bytes) 12-18-06 06:23
 JoinTest.1.cs [^] (2,776 bytes) 12-18-06 06:24
 SplitJoin-onierstrasz.25.mcz [^] (11,077 bytes) 04-12-09 18:50
 SplitJoin-onierstrasz.26.mcz [^] (11,024 bytes) 04-12-09 19:00

10-19-06 15:01   
Join-kph-2.mcz Has a separate package 'Join'.
Join.3.cs is merged into SequenceableCollection and CollectionsTests
it has some method comments

Implements #joinUsing: and #splitOn: both using a double dispatch

$/ useToJoin: aSequencableCollection
aSequenceableCollection joinUsing: $/
aSequenceableCollection joinUsing: ', ' last: ' and'

aSequencableCollection splitOn: splitter
where splitter can be any sequenceable collection, or a Block

aSequencableCollection splitUp: aSequenceableCollection
aBlock splitUp: aSequenceableCollection
aSequencableCollection split: aBlock

12-18-06 06:20   
"fix begin"
Installer mantis bug: 4874 fix: 'Join.4.cs' date: '12-18-06'.
"fix test"
Installer mantis bug: 4874 fix: 'JoinTest.1.cs' date: '12-18-06'.
"fix end"

04-12-09 18:52 [^] is an attempt to merge and generalize two version sof the split join functionality. The end result is largely consistent with Keith's implementation. Additionally, objects and regexes can be splitters, and OrderedCollections and SortedCollections may be joiners.