[squeak-dev] The Trunk: Collections-eem.1023.mcz

commits at source.squeak.org commits at source.squeak.org
Wed Nov 23 03:12:56 UTC 2022


Eliot Miranda uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-eem.1023.mcz

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

Name: Collections-eem.1023
Author: eem
Time: 22 November 2022, 7:12:52.434373 pm
UUID: 9c7f84f0-35b9-476f-9d51-75cc12248c26
Ancestors: Collections-eem.1022

Reimplement subStrings: in SequenceableCollection (this is where it belongs; subStrings: on arbitrary sequeances is useful).  Allow the argument to be a singleton, if not a collection.  Reimplement to use an index and copyFrom:to: instead of consing up a string on each element.

=============== Diff against Collections-eem.1022 ===============

Item was added:
+ ----- Method: SequenceableCollection>>subStrings: (in category 'converting') -----
+ subStrings: separatorsOrElement
+ 	"Answer an array containing the substrings in the receiver separated 
+ 	 by the elements of separatorsOrElement, if it is a Collection, or a
+ 	 singleton separator object, if it is not."
+ 
+ 	| result size thing subsequenceStart |
+ 	result := OrderedCollection new.
+ 	size := self size.
+ 	separatorsOrElement isCollection
+ 		ifTrue:
+ 			[1 to: size do:
+ 				[:i|
+ 				thing := self at: i.
+ 				(separatorsOrElement includes: thing)
+ 					ifTrue:
+ 						[subsequenceStart ifNotNil:
+ 							[result addLast: (self copyFrom: subsequenceStart to: i - 1)].
+ 						 subsequenceStart := nil]
+ 					ifFalse:
+ 						[subsequenceStart ifNil: [subsequenceStart := i]]]]
+ 		ifFalse:
+ 			[1 to: size do:
+ 				[:i|
+ 				thing := self at: i.
+ 				separatorsOrElement = thing
+ 					ifTrue:
+ 						[subsequenceStart ifNotNil:
+ 							[result addLast: (self copyFrom: subsequenceStart to: i - 1)].
+ 						 subsequenceStart := nil]
+ 					ifFalse:
+ 						[subsequenceStart ifNil: [subsequenceStart := i]]]].
+ 	subsequenceStart ifNotNil:
+ 		[result addLast: (self copyFrom: subsequenceStart to: size)].
+ 	^result asArray
+ 
+ 	"'Now is the time for all good people to come to the aid of the cause of world peace.  It is just fine, even desirable, to love your country, if that means wanting it to play a beneficial role in the course of world events and be the best possible example of a good society.  But if it means wanting dominion over the rest of the world, it is not love but defensiveness or self-glorification, and will lead only to oblivion.' subStrings: Character space"
+ 
+ 	"'Now is the time for all good people to come to the aid of the cause of world peace.  It is just fine, even desirable, to love your country, if that means wanting it to play a beneficial role in the course of world events and be the best possible example of a good society.  But if it means wanting dominion over the rest of the world, it is not love but defensiveness or self-glorification, and will lead only to oblivion.' subStrings: ' ,.-'"!

Item was changed:
  ----- Method: String>>subStrings: (in category 'converting') -----
  subStrings: separators 
  	"Answer an array containing the substrings in the receiver separated 
+ 	 by the elements of separators, which should be a collection of Characters,
+ 	 or, for convenience, a single character.."
+ 	(separators isCharacter or: [separators isString or:[separators allSatisfy: [:element | element isCharacter]]]) ifTrue:
+ 		[^super subStrings: separators].
+ 	^self error: 'separators must be Characters.'
+ 
+ 	"'Now is the time for all good people to come to the aid of the cause of world peace.  It is just fine, even desirable, to love your country, if that means wanting it to play a beneficial role in the course of world events and be the best possible example of a good society.  But if it means wanting dominion over the rest of the world, it is not love but defensiveness or self-glorification, and will lead only to oblivion.' subStrings: Character space"
+ 
+ 	"'Now is the time for all good people to come to the aid of the cause of world peace.  It is just fine, even desirable, to love your country, if that means wanting it to play a beneficial role in the course of world events and be the best possible example of a good society.  But if it means wanting dominion over the rest of the world, it is not love but defensiveness or self-glorification, and will lead only to oblivion.' subStrings: ' ,.-'"!
- 	by the elements of separators."
- 	| char result sourceStream subString |
- 	#Collectn.
- 	"Changed 2000/04/08 For ANSI <readableString> protocol."
- 	(separators isString or:[separators allSatisfy: [:element | element isCharacter]]) ifFalse:
- 		[^ self error: 'separators must be Characters.'].
- 	sourceStream := ReadStream on: self.
- 	result := OrderedCollection new.
- 	subString := String new.
- 	[sourceStream atEnd]
- 		whileFalse: 
- 			[char := sourceStream next.
- 			(separators includes: char)
- 				ifTrue: [subString notEmpty
- 						ifTrue: 
- 							[result add: subString copy.
- 							subString := String new]]
- 				ifFalse: [subString := subString , (String with: char)]].
- 	subString notEmpty ifTrue: [result add: subString copy].
- 	^ result asArray!



More information about the Squeak-dev mailing list