[squeak-dev] The Trunk: Collections-ct.914.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Apr 7 21:02:06 UTC 2022


Christoph Thiede uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ct.914.mcz

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

Name: Collections-ct.914
Author: ct
Time: 29 September 2020, 3:15:58.543807 pm
UUID: 6bb73b4a-58ae-be43-a0f4-fb265b32b30f
Ancestors: Collections-eem.912

Proposal: Supply start and stop of attributes in Text >> #[removeAttributesThat:][replaceAttributesThat:][by:].

For example, this can be useful for retrieving the part of a text that belongs to an attribute before doing filtering the attribute in some way.

=============== Diff against Collections-eem.912 ===============

Item was changed:
  ----- Method: Text>>removeAttributesThat:replaceAttributesThat:by: (in category 'converting') -----
  removeAttributesThat: removalBlock replaceAttributesThat: replaceBlock by: convertBlock
  	"Enumerate all attributes in the receiver. Remove those passing removalBlock and replace those passing replaceBlock after converting it through convertBlock"
  	| added removed |
  	"Deliberately optimized for the no-op default."
  	added := removed := nil.
  	runs withStartStopAndValueDo: [ :start :stop :attribs | 
  		attribs do: [ :attrib | | new |
+ 			(removalBlock cull: attrib cull: start cull: stop) ifTrue:[
- 			(removalBlock value: attrib) ifTrue:[
  				removed ifNil:[removed := WriteStream on: #()].
  				removed nextPut: {start. stop. attrib}.
  			] ifFalse:[
+ 				(replaceBlock cull: attrib cull: start cull: stop) ifTrue:[
- 				(replaceBlock value: attrib) ifTrue:[
  					removed ifNil:[removed := WriteStream on: #()].
  					removed nextPut: {start. stop. attrib}.
+ 					new := convertBlock cull: attrib cull: start cull: stop.
- 					new := convertBlock value: attrib.
  					added ifNil:[added := WriteStream on: #()].
  					added nextPut: {start. stop. new}.
  				].
  			].
  		].
  	].
  	(added == nil and:[removed == nil]) ifTrue:[^self].
  	"otherwise do the real work"
  	removed ifNotNil:[removed contents do:[:spec|
  		self removeAttribute: spec last from: spec first to: spec second]].
  	added ifNotNil:[added contents do:[:spec|
  		self addAttribute: spec last from: spec first to: spec second]].!



More information about the Squeak-dev mailing list